| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/protocol/spake2_authenticator.h" | 5 #include "remoting/protocol/spake2_authenticator.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/run_loop.h" |
| 9 #include "remoting/base/rsa_key_pair.h" | 10 #include "remoting/base/rsa_key_pair.h" |
| 10 #include "remoting/protocol/authenticator_test_base.h" | 11 #include "remoting/protocol/authenticator_test_base.h" |
| 11 #include "remoting/protocol/channel_authenticator.h" | 12 #include "remoting/protocol/channel_authenticator.h" |
| 12 #include "remoting/protocol/connection_tester.h" | 13 #include "remoting/protocol/connection_tester.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 16 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
| 16 | 17 |
| 17 using testing::_; | 18 using testing::_; |
| 18 using testing::DeleteArg; | 19 using testing::DeleteArg; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); | 62 ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); |
| 62 | 63 |
| 63 client_auth_ = client_->CreateChannelAuthenticator(); | 64 client_auth_ = client_->CreateChannelAuthenticator(); |
| 64 host_auth_ = host_->CreateChannelAuthenticator(); | 65 host_auth_ = host_->CreateChannelAuthenticator(); |
| 65 RunChannelAuth(false); | 66 RunChannelAuth(false); |
| 66 | 67 |
| 67 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | 68 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
| 68 kMessageSize, kMessages); | 69 kMessageSize, kMessages); |
| 69 | 70 |
| 70 tester.Start(); | 71 tester.Start(); |
| 71 message_loop_.Run(); | 72 base::RunLoop().Run(); |
| 72 tester.CheckResults(); | 73 tester.CheckResults(); |
| 73 } | 74 } |
| 74 | 75 |
| 75 // Verify that connection is rejected when secrets don't match. | 76 // Verify that connection is rejected when secrets don't match. |
| 76 TEST_F(Spake2AuthenticatorTest, InvalidSecret) { | 77 TEST_F(Spake2AuthenticatorTest, InvalidSecret) { |
| 77 ASSERT_NO_FATAL_FAILURE( | 78 ASSERT_NO_FATAL_FAILURE( |
| 78 InitAuthenticators(kTestSharedSecretBad, kTestSharedSecret)); | 79 InitAuthenticators(kTestSharedSecretBad, kTestSharedSecret)); |
| 79 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 80 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
| 80 | 81 |
| 81 ASSERT_EQ(Authenticator::REJECTED, client_->state()); | 82 ASSERT_EQ(Authenticator::REJECTED, client_->state()); |
| 82 ASSERT_EQ(Authenticator::INVALID_CREDENTIALS, client_->rejection_reason()); | 83 ASSERT_EQ(Authenticator::INVALID_CREDENTIALS, client_->rejection_reason()); |
| 83 | 84 |
| 84 // Change |client_| so that we can get the last message. | 85 // Change |client_| so that we can get the last message. |
| 85 reinterpret_cast<Spake2Authenticator*>(client_.get())->state_ = | 86 reinterpret_cast<Spake2Authenticator*>(client_.get())->state_ = |
| 86 Authenticator::MESSAGE_READY; | 87 Authenticator::MESSAGE_READY; |
| 87 | 88 |
| 88 std::unique_ptr<buzz::XmlElement> message(client_->GetNextMessage()); | 89 std::unique_ptr<buzz::XmlElement> message(client_->GetNextMessage()); |
| 89 ASSERT_TRUE(message.get()); | 90 ASSERT_TRUE(message.get()); |
| 90 | 91 |
| 91 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state()); | 92 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state()); |
| 92 host_->ProcessMessage(message.get(), base::Bind(&base::DoNothing)); | 93 host_->ProcessMessage(message.get(), base::Bind(&base::DoNothing)); |
| 93 // This assumes that Spake2Authenticator::ProcessMessage runs synchronously. | 94 // This assumes that Spake2Authenticator::ProcessMessage runs synchronously. |
| 94 ASSERT_EQ(Authenticator::REJECTED, host_->state()); | 95 ASSERT_EQ(Authenticator::REJECTED, host_->state()); |
| 95 } | 96 } |
| 96 | 97 |
| 97 } // namespace protocol | 98 } // namespace protocol |
| 98 } // namespace remoting | 99 } // namespace remoting |
| OLD | NEW |