Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: remoting/protocol/validating_authenticator_unittest.cc

Issue 2724223003: Disconnect all users if too many connection requests are received for It2Me (Closed)
Patch Set: Fixing another non-Windows build error Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/protocol/validating_authenticator_unittest.cc
diff --git a/remoting/protocol/validating_authenticator_unittest.cc b/remoting/protocol/validating_authenticator_unittest.cc
index dd23b726c975cfe97862c8389afb733295aaacf7..2cb957dc8ec1b51397641c9cbbd55aecb60d3ad5 100644
--- a/remoting/protocol/validating_authenticator_unittest.cc
+++ b/remoting/protocol/validating_authenticator_unittest.cc
@@ -29,7 +29,7 @@ using testing::Return;
typedef ValidatingAuthenticator::Result ValidationResult;
-const char kRemoteTestJid[] = "ficticious_jid_for_testing";
+constexpr char kRemoteTestJid[] = "ficticious_jid_for_testing";
// testing::InvokeArgument<N> does not work with base::Callback, fortunately
// gmock makes it simple to create action templates that do for the various
@@ -48,6 +48,8 @@ class ValidatingAuthenticatorTest : public testing::Test {
~ValidatingAuthenticatorTest() override;
void ValidateCallback(
+ ValidationResult* validation_result,
+ bool* callback_called,
const std::string& remote_jid,
const ValidatingAuthenticator::ResultCallback& callback);
@@ -63,14 +65,21 @@ class ValidatingAuthenticatorTest : public testing::Test {
// to |validating_authenticator_|. Lifetime of the object is controlled by
// |validating_authenticator_| so this pointer is no longer valid once
// the owner is destroyed.
- MockAuthenticator* mock_authenticator_ = nullptr;
+ testing::NiceMock<MockAuthenticator>* mock_authenticator_ = nullptr;
// This member is used to drive behavior in |validating_authenticator_| when
- // it's validation complete callback is run.
- ValidationResult validation_result_ = ValidationResult::SUCCESS;
+ // its incoming validation complete callback is run.
+ ValidationResult incoming_validation_result_ = ValidationResult::SUCCESS;
- // Tracks whether our ValidateCallback has been called or not.
- bool validate_complete_called_ = false;
+ // Tracks whether our 'incoming' callback has been called or not.
+ bool incoming_complete_called_ = false;
+
+ // This member is used to drive behavior in |validating_authenticator_| when
+ // its accepted validation complete callback is run.
+ ValidationResult accepted_validation_result_ = ValidationResult::SUCCESS;
+
+ // Tracks whether our 'accepted' callback has been called or not.
+ bool accepted_complete_called_ = false;
// The object under test.
std::unique_ptr<ValidatingAuthenticator> validating_authenticator_;
@@ -86,19 +95,26 @@ ValidatingAuthenticatorTest::ValidatingAuthenticatorTest() {}
ValidatingAuthenticatorTest::~ValidatingAuthenticatorTest() {}
void ValidatingAuthenticatorTest::ValidateCallback(
+ ValidationResult* validation_result,
+ bool* callback_called,
const std::string& remote_jid,
const ValidatingAuthenticator::ResultCallback& callback) {
- validate_complete_called_ = true;
- callback.Run(validation_result_);
+ *callback_called = true;
+ callback.Run(*validation_result);
}
void ValidatingAuthenticatorTest::SetUp() {
- mock_authenticator_ = new MockAuthenticator();
+ mock_authenticator_ = new testing::NiceMock<MockAuthenticator>();
std::unique_ptr<Authenticator> authenticator(mock_authenticator_);
validating_authenticator_.reset(new ValidatingAuthenticator(
- kRemoteTestJid, base::Bind(&ValidatingAuthenticatorTest::ValidateCallback,
- base::Unretained(this)),
+ kRemoteTestJid,
+ base::Bind(&ValidatingAuthenticatorTest::ValidateCallback,
+ base::Unretained(this), &incoming_validation_result_,
+ &incoming_complete_called_),
+ base::Bind(&ValidatingAuthenticatorTest::ValidateCallback,
+ base::Unretained(this), &accepted_validation_result_,
+ &accepted_complete_called_),
std::move(authenticator)));
}
@@ -120,7 +136,8 @@ TEST_F(ValidatingAuthenticatorTest, ValidConnection_SingleMessage) {
.WillByDefault(Return(Authenticator::ACCEPTED));
SendMessageAndWaitForCallback();
- ASSERT_TRUE(validate_complete_called_);
+ ASSERT_TRUE(incoming_complete_called_);
+ ASSERT_TRUE(accepted_complete_called_);
ASSERT_EQ(validating_authenticator_->state(), Authenticator::ACCEPTED);
}
@@ -135,7 +152,8 @@ TEST_F(ValidatingAuthenticatorTest, ValidConnection_TwoMessages) {
.WillRepeatedly(Return(Authenticator::MESSAGE_READY));
SendMessageAndWaitForCallback();
- ASSERT_TRUE(validate_complete_called_);
+ ASSERT_TRUE(incoming_complete_called_);
+ ASSERT_FALSE(accepted_complete_called_);
ASSERT_EQ(validating_authenticator_->state(), Authenticator::MESSAGE_READY);
// Now 'retrieve' the message for the client which resets the state.
@@ -159,10 +177,11 @@ TEST_F(ValidatingAuthenticatorTest, ValidConnection_TwoMessages) {
.WillRepeatedly(Return(Authenticator::ACCEPTED));
// Reset the callback state, we don't expect the validate function to be
- // called for the second message.
- validate_complete_called_ = false;
+ // called for the second message, but the accepted callback should.
+ incoming_complete_called_ = false;
SendMessageAndWaitForCallback();
- ASSERT_FALSE(validate_complete_called_);
+ ASSERT_FALSE(incoming_complete_called_);
+ ASSERT_TRUE(accepted_complete_called_);
ASSERT_EQ(validating_authenticator_->state(), Authenticator::ACCEPTED);
}
@@ -171,10 +190,11 @@ TEST_F(ValidatingAuthenticatorTest, InvalidConnection_RejectedByUser) {
EXPECT_CALL(*mock_authenticator_, state()).Times(0);
EXPECT_CALL(*mock_authenticator_, rejection_reason()).Times(0);
- validation_result_ = ValidationResult::ERROR_REJECTED_BY_USER;
+ incoming_validation_result_ = ValidationResult::ERROR_REJECTED_BY_USER;
SendMessageAndWaitForCallback();
- ASSERT_TRUE(validate_complete_called_);
+ ASSERT_TRUE(incoming_complete_called_);
+ ASSERT_FALSE(accepted_complete_called_);
ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED);
ASSERT_EQ(validating_authenticator_->rejection_reason(),
Authenticator::REJECTED_BY_USER);
@@ -185,10 +205,11 @@ TEST_F(ValidatingAuthenticatorTest, InvalidConnection_InvalidCredentials) {
EXPECT_CALL(*mock_authenticator_, state()).Times(0);
EXPECT_CALL(*mock_authenticator_, rejection_reason()).Times(0);
- validation_result_ = ValidationResult::ERROR_INVALID_CREDENTIALS;
+ incoming_validation_result_ = ValidationResult::ERROR_INVALID_CREDENTIALS;
SendMessageAndWaitForCallback();
- ASSERT_TRUE(validate_complete_called_);
+ ASSERT_TRUE(incoming_complete_called_);
+ ASSERT_FALSE(accepted_complete_called_);
ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED);
ASSERT_EQ(validating_authenticator_->rejection_reason(),
Authenticator::INVALID_CREDENTIALS);
@@ -199,15 +220,49 @@ TEST_F(ValidatingAuthenticatorTest, InvalidConnection_InvalidAccount) {
EXPECT_CALL(*mock_authenticator_, state()).Times(0);
EXPECT_CALL(*mock_authenticator_, rejection_reason()).Times(0);
- validation_result_ = ValidationResult::ERROR_INVALID_ACCOUNT;
+ incoming_validation_result_ = ValidationResult::ERROR_INVALID_ACCOUNT;
SendMessageAndWaitForCallback();
- ASSERT_TRUE(validate_complete_called_);
+ ASSERT_TRUE(incoming_complete_called_);
+ ASSERT_FALSE(accepted_complete_called_);
ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED);
ASSERT_EQ(validating_authenticator_->rejection_reason(),
Authenticator::INVALID_ACCOUNT);
}
+TEST_F(ValidatingAuthenticatorTest, InvalidConnection_TooManyConnections) {
+ EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _)).Times(0);
+ EXPECT_CALL(*mock_authenticator_, state()).Times(0);
+ EXPECT_CALL(*mock_authenticator_, rejection_reason()).Times(0);
+
+ incoming_validation_result_ = ValidationResult::ERROR_TOO_MANY_CONNECTIONS;
+
+ SendMessageAndWaitForCallback();
+ ASSERT_TRUE(incoming_complete_called_);
+ ASSERT_FALSE(accepted_complete_called_);
+ ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED);
+ ASSERT_EQ(validating_authenticator_->rejection_reason(),
+ Authenticator::TOO_MANY_CONNECTIONS);
+}
+
+TEST_F(ValidatingAuthenticatorTest, AcceptedConnection_RejectedByUser) {
+ EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _))
+ .Times(1)
+ .WillOnce(InvokeCallbackArgument<1>());
+
+ ON_CALL(*mock_authenticator_, state())
+ .WillByDefault(Return(Authenticator::ACCEPTED));
+
+ accepted_validation_result_ = ValidationResult::ERROR_REJECTED_BY_USER;
+
+ SendMessageAndWaitForCallback();
+ ASSERT_TRUE(incoming_complete_called_);
+ ASSERT_TRUE(accepted_complete_called_);
+ ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED);
+ ASSERT_EQ(validating_authenticator_->rejection_reason(),
+ Authenticator::REJECTED_BY_USER);
+}
+
TEST_F(ValidatingAuthenticatorTest,
WrappedAuthenticatorRejectsConnection_InvalidCredentials) {
EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _))
@@ -221,7 +276,8 @@ TEST_F(ValidatingAuthenticatorTest,
.WillByDefault(Return(Authenticator::REJECTED_BY_USER));
SendMessageAndWaitForCallback();
- ASSERT_TRUE(validate_complete_called_);
+ ASSERT_TRUE(incoming_complete_called_);
+ ASSERT_FALSE(accepted_complete_called_);
ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED);
ASSERT_EQ(validating_authenticator_->rejection_reason(),
Authenticator::REJECTED_BY_USER);
@@ -240,14 +296,15 @@ TEST_F(ValidatingAuthenticatorTest,
.WillByDefault(Return(Authenticator::INVALID_CREDENTIALS));
SendMessageAndWaitForCallback();
- ASSERT_TRUE(validate_complete_called_);
+ ASSERT_TRUE(incoming_complete_called_);
+ ASSERT_FALSE(accepted_complete_called_);
ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED);
ASSERT_EQ(validating_authenticator_->rejection_reason(),
Authenticator::INVALID_CREDENTIALS);
}
TEST_F(ValidatingAuthenticatorTest,
- WrappedAuthenticatorRejectsConnection_PROTOCOL_ERROR) {
+ WrappedAuthenticatorRejectsConnection_ProtocolError) {
EXPECT_CALL(*mock_authenticator_, ProcessMessage(_, _))
.Times(1)
.WillOnce(InvokeCallbackArgument<1>());
@@ -259,7 +316,8 @@ TEST_F(ValidatingAuthenticatorTest,
.WillByDefault(Return(Authenticator::PROTOCOL_ERROR));
SendMessageAndWaitForCallback();
- ASSERT_TRUE(validate_complete_called_);
+ ASSERT_TRUE(incoming_complete_called_);
+ ASSERT_FALSE(accepted_complete_called_);
ASSERT_EQ(validating_authenticator_->state(), Authenticator::REJECTED);
ASSERT_EQ(validating_authenticator_->rejection_reason(),
Authenticator::PROTOCOL_ERROR);
« remoting/protocol/authenticator.h ('K') | « remoting/protocol/validating_authenticator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698