#include "remoting/protocol/session_authz_authenticator.h"
#include <memory>
#include <tuple>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/gmock_move_support.h"
#include "base/test/mock_callback.h"
#include "base/time/time.h"
#include "net/http/http_status_code.h"
#include "remoting/base/mock_session_authz_service_client.h"
#include "remoting/base/protobuf_http_status.h"
#include "remoting/base/rsa_key_pair.h"
#include "remoting/base/session_authz_service_client.h"
#include "remoting/proto/session_authz_service.h"
#include "remoting/protocol/authenticator.h"
#include "remoting/protocol/authenticator_test_base.h"
#include "remoting/protocol/connection_tester.h"
#include "remoting/protocol/credentials_type.h"
#include "remoting/protocol/spake2_authenticator.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace remoting::protocol {
namespace {
_;
ByMove;
Return;
constexpr char kFakeHostToken[] = …;
constexpr char kFakeSessionId[] = …;
constexpr char kFakeSessionToken[] = …;
constexpr char kFakeSharedSecret[] = …;
constexpr char kFakeSessionReauthToken[] = …;
constexpr base::TimeDelta kFakeSessionReauthTokenLifetime = …;
constexpr int kMessageSize = …;
constexpr int kMessages = …;
auto RespondGenerateHostToken() { … }
auto RespondVerifySessionToken(
const std::string& session_id = kFakeSessionId,
const std::string& shared_secret = kFakeSharedSecret) { … }
class FakeClientAuthenticator : public Authenticator { … };
CredentialsType FakeClientAuthenticator::credentials_type() const { … }
const Authenticator& FakeClientAuthenticator::implementing_authenticator()
const { … }
Authenticator::State FakeClientAuthenticator::state() const { … }
bool FakeClientAuthenticator::started() const { … }
FakeClientAuthenticator::FakeClientAuthenticator(
const CreateBaseAuthenticatorCallback& create_base_authenticator_callback)
: … { … }
FakeClientAuthenticator::~FakeClientAuthenticator() = default;
Authenticator::RejectionReason FakeClientAuthenticator::rejection_reason()
const { … }
void FakeClientAuthenticator::ProcessMessage(
const jingle_xmpp::XmlElement* message,
base::OnceClosure resume_callback) { … }
std::unique_ptr<jingle_xmpp::XmlElement>
FakeClientAuthenticator::GetNextMessage() { … }
const std::string& FakeClientAuthenticator::GetAuthKey() const { … }
std::unique_ptr<ChannelAuthenticator>
FakeClientAuthenticator::CreateChannelAuthenticator() const { … }
}
class SessionAuthzAuthenticatorTest : public AuthenticatorTestBase { … };
SessionAuthzAuthenticatorTest::SessionAuthzAuthenticatorTest() = default;
SessionAuthzAuthenticatorTest::~SessionAuthzAuthenticatorTest() = default;
void SessionAuthzAuthenticatorTest::SetUp() { … }
void SessionAuthzAuthenticatorTest::StartAuthExchange() { … }
TEST_F(SessionAuthzAuthenticatorTest, SuccessfulAuth) { … }
TEST_F(SessionAuthzAuthenticatorTest, GenerateHostToken_RpcError_Rejected) { … }
TEST_F(SessionAuthzAuthenticatorTest, VerifySessionToken_RpcError_Rejected) { … }
TEST_F(SessionAuthzAuthenticatorTest,
VerifySessionToken_SessionIdMismatch_Rejected) { … }
TEST_F(SessionAuthzAuthenticatorTest,
UnderlyingAuthenticator_InvalidIncomingMessage_Rejected) { … }
TEST_F(SessionAuthzAuthenticatorTest,
UnderlyingAuthenticator_MismatchedSharedSecret_NotAccepted) { … }
TEST_F(SessionAuthzAuthenticatorTest, ReauthorizationFailed_Rejected) { … }
}