OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/v2_authenticator.h" | 5 #include "remoting/protocol/v2_authenticator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
9 #include "remoting/base/rsa_key_pair.h" | 9 #include "remoting/base/rsa_key_pair.h" |
10 #include "remoting/protocol/authenticator_test_base.h" | 10 #include "remoting/protocol/authenticator_test_base.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 host_ = V2Authenticator::CreateForHost( | 44 host_ = V2Authenticator::CreateForHost( |
45 host_cert_, key_pair_, host_secret, | 45 host_cert_, key_pair_, host_secret, |
46 Authenticator::WAITING_MESSAGE); | 46 Authenticator::WAITING_MESSAGE); |
47 client_ = V2Authenticator::CreateForClient( | 47 client_ = V2Authenticator::CreateForClient( |
48 client_secret, Authenticator::MESSAGE_READY); | 48 client_secret, Authenticator::MESSAGE_READY); |
49 } | 49 } |
50 | 50 |
51 DISALLOW_COPY_AND_ASSIGN(V2AuthenticatorTest); | 51 DISALLOW_COPY_AND_ASSIGN(V2AuthenticatorTest); |
52 }; | 52 }; |
53 | 53 |
54 // These tests use net::SSLServerSocket which is not implemented for OpenSSL. | 54 TEST_F(V2AuthenticatorTest, SuccessfulAuth) { |
55 #if defined(USE_OPENSSL) | |
56 #define MAYBE(x) DISABLED_##x | |
57 #else | |
58 #define MAYBE(x) x | |
59 #endif | |
60 | |
61 TEST_F(V2AuthenticatorTest, MAYBE(SuccessfulAuth)) { | |
62 ASSERT_NO_FATAL_FAILURE( | 55 ASSERT_NO_FATAL_FAILURE( |
63 InitAuthenticators(kTestSharedSecret, kTestSharedSecret)); | 56 InitAuthenticators(kTestSharedSecret, kTestSharedSecret)); |
64 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 57 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
65 | 58 |
66 ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); | 59 ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); |
67 ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); | 60 ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); |
68 | 61 |
69 client_auth_ = client_->CreateChannelAuthenticator(); | 62 client_auth_ = client_->CreateChannelAuthenticator(); |
70 host_auth_ = host_->CreateChannelAuthenticator(); | 63 host_auth_ = host_->CreateChannelAuthenticator(); |
71 RunChannelAuth(false); | 64 RunChannelAuth(false); |
72 | 65 |
73 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | 66 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), |
74 kMessageSize, kMessages); | 67 kMessageSize, kMessages); |
75 | 68 |
76 tester.Start(); | 69 tester.Start(); |
77 message_loop_.Run(); | 70 message_loop_.Run(); |
78 tester.CheckResults(); | 71 tester.CheckResults(); |
79 } | 72 } |
80 | 73 |
81 // Verify that connection is rejected when secrets don't match. | 74 // Verify that connection is rejected when secrets don't match. |
82 TEST_F(V2AuthenticatorTest, MAYBE(InvalidSecret)) { | 75 TEST_F(V2AuthenticatorTest, InvalidSecret) { |
83 ASSERT_NO_FATAL_FAILURE( | 76 ASSERT_NO_FATAL_FAILURE( |
84 InitAuthenticators(kTestSharedSecretBad, kTestSharedSecret)); | 77 InitAuthenticators(kTestSharedSecretBad, kTestSharedSecret)); |
85 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); | 78 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); |
86 | 79 |
87 ASSERT_EQ(Authenticator::REJECTED, client_->state()); | 80 ASSERT_EQ(Authenticator::REJECTED, client_->state()); |
88 | 81 |
89 // Change |client_| so that we can get the last message. | 82 // Change |client_| so that we can get the last message. |
90 reinterpret_cast<V2Authenticator*>(client_.get())->state_ = | 83 reinterpret_cast<V2Authenticator*>(client_.get())->state_ = |
91 Authenticator::MESSAGE_READY; | 84 Authenticator::MESSAGE_READY; |
92 | 85 |
93 scoped_ptr<buzz::XmlElement> message(client_->GetNextMessage()); | 86 scoped_ptr<buzz::XmlElement> message(client_->GetNextMessage()); |
94 ASSERT_TRUE(message.get()); | 87 ASSERT_TRUE(message.get()); |
95 | 88 |
96 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state()); | 89 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state()); |
97 host_->ProcessMessage(message.get(), base::Bind(&base::DoNothing)); | 90 host_->ProcessMessage(message.get(), base::Bind(&base::DoNothing)); |
98 // This assumes that V2Authenticator::ProcessMessage runs synchronously. | 91 // This assumes that V2Authenticator::ProcessMessage runs synchronously. |
99 ASSERT_EQ(Authenticator::REJECTED, host_->state()); | 92 ASSERT_EQ(Authenticator::REJECTED, host_->state()); |
100 } | 93 } |
101 | 94 |
102 } // namespace protocol | 95 } // namespace protocol |
103 } // namespace remoting | 96 } // namespace remoting |
OLD | NEW |