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/ssl_hmac_channel_authenticator.h" | 5 #include "remoting/protocol/ssl_hmac_channel_authenticator.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
14 #include "crypto/rsa_private_key.h" | 14 #include "crypto/rsa_private_key.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 #include "net/base/test_data_directory.h" | 16 #include "net/base/test_data_directory.h" |
17 #include "net/test/cert_test_util.h" | 17 #include "net/test/cert_test_util.h" |
18 #include "remoting/base/rsa_key_pair.h" | 18 #include "remoting/base/rsa_key_pair.h" |
19 #include "remoting/protocol/connection_tester.h" | 19 #include "remoting/protocol/connection_tester.h" |
20 #include "remoting/protocol/fake_session.h" | 20 #include "remoting/protocol/fake_session.h" |
| 21 #include "remoting/protocol/p2p_stream_socket.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 24 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
24 | 25 |
25 using testing::_; | 26 using testing::_; |
26 using testing::NotNull; | 27 using testing::NotNull; |
27 using testing::SaveArg; | 28 using testing::SaveArg; |
28 | 29 |
29 namespace remoting { | 30 namespace remoting { |
30 namespace protocol { | 31 namespace protocol { |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 const char kTestSharedSecret[] = "1234-1234-5678"; | 35 const char kTestSharedSecret[] = "1234-1234-5678"; |
35 const char kTestSharedSecretBad[] = "0000-0000-0001"; | 36 const char kTestSharedSecretBad[] = "0000-0000-0001"; |
36 | 37 |
37 class MockChannelDoneCallback { | 38 class MockChannelDoneCallback { |
38 public: | 39 public: |
39 MOCK_METHOD2(OnDone, void(int error, net::StreamSocket* socket)); | 40 MOCK_METHOD2(OnDone, void(int error, P2PStreamSocket* socket)); |
40 }; | 41 }; |
41 | 42 |
42 ACTION_P(QuitThreadOnCounter, counter) { | 43 ACTION_P(QuitThreadOnCounter, counter) { |
43 --(*counter); | 44 --(*counter); |
44 EXPECT_GE(*counter, 0); | 45 EXPECT_GE(*counter, 0); |
45 if (*counter == 0) | 46 if (*counter == 0) |
46 base::MessageLoop::current()->Quit(); | 47 base::MessageLoop::current()->Quit(); |
47 } | 48 } |
48 | 49 |
49 } // namespace | 50 } // namespace |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // called. | 109 // called. |
109 base::Timer shutdown_timer(false, false); | 110 base::Timer shutdown_timer(false, false); |
110 shutdown_timer.Start(FROM_HERE, | 111 shutdown_timer.Start(FROM_HERE, |
111 TestTimeouts::action_timeout(), | 112 TestTimeouts::action_timeout(), |
112 base::MessageLoop::QuitClosure()); | 113 base::MessageLoop::QuitClosure()); |
113 message_loop_.Run(); | 114 message_loop_.Run(); |
114 } | 115 } |
115 | 116 |
116 void OnHostConnected(const std::string& ref_argument, | 117 void OnHostConnected(const std::string& ref_argument, |
117 int error, | 118 int error, |
118 scoped_ptr<net::StreamSocket> socket) { | 119 scoped_ptr<P2PStreamSocket> socket) { |
119 // Try deleting the authenticator and verify that this doesn't destroy | 120 // Try deleting the authenticator and verify that this doesn't destroy |
120 // reference parameters. | 121 // reference parameters. |
121 host_auth_.reset(); | 122 host_auth_.reset(); |
122 DCHECK_EQ(ref_argument, "ref argument value"); | 123 DCHECK_EQ(ref_argument, "ref argument value"); |
123 | 124 |
124 host_callback_.OnDone(error, socket.get()); | 125 host_callback_.OnDone(error, socket.get()); |
125 host_socket_ = socket.Pass(); | 126 host_socket_ = socket.Pass(); |
126 } | 127 } |
127 | 128 |
128 void OnClientConnected(int error, scoped_ptr<net::StreamSocket> socket) { | 129 void OnClientConnected(int error, scoped_ptr<P2PStreamSocket> socket) { |
129 client_auth_.reset(); | 130 client_auth_.reset(); |
130 client_callback_.OnDone(error, socket.get()); | 131 client_callback_.OnDone(error, socket.get()); |
131 client_socket_ = socket.Pass(); | 132 client_socket_ = socket.Pass(); |
132 } | 133 } |
133 | 134 |
134 base::MessageLoop message_loop_; | 135 base::MessageLoop message_loop_; |
135 | 136 |
136 scoped_refptr<RsaKeyPair> key_pair_; | 137 scoped_refptr<RsaKeyPair> key_pair_; |
137 std::string host_cert_; | 138 std::string host_cert_; |
138 scoped_ptr<FakeStreamSocket> client_fake_socket_; | 139 scoped_ptr<FakeStreamSocket> client_fake_socket_; |
139 scoped_ptr<FakeStreamSocket> host_fake_socket_; | 140 scoped_ptr<FakeStreamSocket> host_fake_socket_; |
140 scoped_ptr<ChannelAuthenticator> client_auth_; | 141 scoped_ptr<ChannelAuthenticator> client_auth_; |
141 scoped_ptr<ChannelAuthenticator> host_auth_; | 142 scoped_ptr<ChannelAuthenticator> host_auth_; |
142 MockChannelDoneCallback client_callback_; | 143 MockChannelDoneCallback client_callback_; |
143 MockChannelDoneCallback host_callback_; | 144 MockChannelDoneCallback host_callback_; |
144 scoped_ptr<net::StreamSocket> client_socket_; | 145 scoped_ptr<P2PStreamSocket> client_socket_; |
145 scoped_ptr<net::StreamSocket> host_socket_; | 146 scoped_ptr<P2PStreamSocket> host_socket_; |
146 | 147 |
147 DISALLOW_COPY_AND_ASSIGN(SslHmacChannelAuthenticatorTest); | 148 DISALLOW_COPY_AND_ASSIGN(SslHmacChannelAuthenticatorTest); |
148 }; | 149 }; |
149 | 150 |
150 // Verify that a channel can be connected using a valid shared secret. | 151 // Verify that a channel can be connected using a valid shared secret. |
151 TEST_F(SslHmacChannelAuthenticatorTest, SuccessfulAuth) { | 152 TEST_F(SslHmacChannelAuthenticatorTest, SuccessfulAuth) { |
152 client_auth_ = SslHmacChannelAuthenticator::CreateForClient( | 153 client_auth_ = SslHmacChannelAuthenticator::CreateForClient( |
153 host_cert_, kTestSharedSecret); | 154 host_cert_, kTestSharedSecret); |
154 host_auth_ = SslHmacChannelAuthenticator::CreateForHost( | 155 host_auth_ = SslHmacChannelAuthenticator::CreateForHost( |
155 host_cert_, key_pair_, kTestSharedSecret); | 156 host_cert_, key_pair_, kTestSharedSecret); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 host_auth_ = SslHmacChannelAuthenticator::CreateForHost( | 194 host_auth_ = SslHmacChannelAuthenticator::CreateForHost( |
194 host_cert_, key_pair_, kTestSharedSecret); | 195 host_cert_, key_pair_, kTestSharedSecret); |
195 | 196 |
196 RunChannelAuth(net::ERR_CERT_INVALID, net::ERR_CONNECTION_CLOSED); | 197 RunChannelAuth(net::ERR_CERT_INVALID, net::ERR_CONNECTION_CLOSED); |
197 | 198 |
198 ASSERT_TRUE(host_socket_.get() == nullptr); | 199 ASSERT_TRUE(host_socket_.get() == nullptr); |
199 } | 200 } |
200 | 201 |
201 } // namespace protocol | 202 } // namespace protocol |
202 } // namespace remoting | 203 } // namespace remoting |
OLD | NEW |