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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 namespace remoting { | 29 namespace remoting { |
30 namespace protocol { | 30 namespace protocol { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const char kTestSharedSecret[] = "1234-1234-5678"; | 34 const char kTestSharedSecret[] = "1234-1234-5678"; |
35 const char kTestSharedSecretBad[] = "0000-0000-0001"; | 35 const char kTestSharedSecretBad[] = "0000-0000-0001"; |
36 | 36 |
37 class MockChannelDoneCallback { | 37 class MockChannelDoneCallback { |
38 public: | 38 public: |
39 MOCK_METHOD2(OnDone, void(int error, net::StreamSocket* socket)); | 39 MOCK_METHOD2(OnDone, void(net::Error error, net::StreamSocket* socket)); |
40 }; | 40 }; |
41 | 41 |
42 ACTION_P(QuitThreadOnCounter, counter) { | 42 ACTION_P(QuitThreadOnCounter, counter) { |
43 --(*counter); | 43 --(*counter); |
44 EXPECT_GE(*counter, 0); | 44 EXPECT_GE(*counter, 0); |
45 if (*counter == 0) | 45 if (*counter == 0) |
46 base::MessageLoop::current()->Quit(); | 46 base::MessageLoop::current()->Quit(); |
47 } | 47 } |
48 | 48 |
49 } // namespace | 49 } // namespace |
(...skipping 25 matching lines...) Expand all Loading... |
75 client_fake_socket_->PairWith(host_fake_socket_.get()); | 75 client_fake_socket_->PairWith(host_fake_socket_.get()); |
76 | 76 |
77 client_auth_->SecureAndAuthenticate( | 77 client_auth_->SecureAndAuthenticate( |
78 client_fake_socket_.PassAs<net::StreamSocket>(), | 78 client_fake_socket_.PassAs<net::StreamSocket>(), |
79 base::Bind(&SslHmacChannelAuthenticatorTest::OnClientConnected, | 79 base::Bind(&SslHmacChannelAuthenticatorTest::OnClientConnected, |
80 base::Unretained(this))); | 80 base::Unretained(this))); |
81 | 81 |
82 host_auth_->SecureAndAuthenticate( | 82 host_auth_->SecureAndAuthenticate( |
83 host_fake_socket_.PassAs<net::StreamSocket>(), | 83 host_fake_socket_.PassAs<net::StreamSocket>(), |
84 base::Bind(&SslHmacChannelAuthenticatorTest::OnHostConnected, | 84 base::Bind(&SslHmacChannelAuthenticatorTest::OnHostConnected, |
85 base::Unretained(this), std::string("ref argument value"))); | 85 base::Unretained(this))); |
86 | 86 |
87 // Expect two callbacks to be called - the client callback and the host | 87 // Expect two callbacks to be called - the client callback and the host |
88 // callback. | 88 // callback. |
89 int callback_counter = 2; | 89 int callback_counter = 2; |
90 | 90 |
91 if (expected_fail) { | 91 if (expected_fail) { |
92 EXPECT_CALL(client_callback_, OnDone(net::ERR_FAILED, NULL)) | 92 EXPECT_CALL(client_callback_, OnDone(net::ERR_FAILED, NULL)) |
93 .WillOnce(QuitThreadOnCounter(&callback_counter)); | 93 .WillOnce(QuitThreadOnCounter(&callback_counter)); |
94 EXPECT_CALL(host_callback_, OnDone(net::ERR_FAILED, NULL)) | 94 EXPECT_CALL(host_callback_, OnDone(net::ERR_FAILED, NULL)) |
95 .WillOnce(QuitThreadOnCounter(&callback_counter)); | 95 .WillOnce(QuitThreadOnCounter(&callback_counter)); |
96 } else { | 96 } else { |
97 EXPECT_CALL(client_callback_, OnDone(net::OK, NotNull())) | 97 EXPECT_CALL(client_callback_, OnDone(net::OK, NotNull())) |
98 .WillOnce(QuitThreadOnCounter(&callback_counter)); | 98 .WillOnce(QuitThreadOnCounter(&callback_counter)); |
99 EXPECT_CALL(host_callback_, OnDone(net::OK, NotNull())) | 99 EXPECT_CALL(host_callback_, OnDone(net::OK, NotNull())) |
100 .WillOnce(QuitThreadOnCounter(&callback_counter)); | 100 .WillOnce(QuitThreadOnCounter(&callback_counter)); |
101 } | 101 } |
102 | 102 |
103 // Ensure that .Run() does not run unbounded if the callbacks are never | 103 // Ensure that .Run() does not run unbounded if the callbacks are never |
104 // called. | 104 // called. |
105 base::Timer shutdown_timer(false, false); | 105 base::Timer shutdown_timer(false, false); |
106 shutdown_timer.Start(FROM_HERE, | 106 shutdown_timer.Start(FROM_HERE, |
107 TestTimeouts::action_timeout(), | 107 TestTimeouts::action_timeout(), |
108 base::MessageLoop::QuitClosure()); | 108 base::MessageLoop::QuitClosure()); |
109 message_loop_.Run(); | 109 message_loop_.Run(); |
110 } | 110 } |
111 | 111 |
112 void OnHostConnected(const std::string& ref_argument, | 112 void OnHostConnected(net::Error error, |
113 int error, | |
114 scoped_ptr<net::StreamSocket> socket) { | 113 scoped_ptr<net::StreamSocket> socket) { |
115 // Try deleting the authenticator and verify that this doesn't destroy | |
116 // reference parameters. | |
117 host_auth_.reset(); | |
118 DCHECK_EQ(ref_argument, "ref argument value"); | |
119 | |
120 host_callback_.OnDone(error, socket.get()); | 114 host_callback_.OnDone(error, socket.get()); |
121 host_socket_ = socket.Pass(); | 115 host_socket_ = socket.Pass(); |
122 } | 116 } |
123 | 117 |
124 void OnClientConnected(int error, scoped_ptr<net::StreamSocket> socket) { | 118 void OnClientConnected(net::Error error, |
125 client_auth_.reset(); | 119 scoped_ptr<net::StreamSocket> socket) { |
126 client_callback_.OnDone(error, socket.get()); | 120 client_callback_.OnDone(error, socket.get()); |
127 client_socket_ = socket.Pass(); | 121 client_socket_ = socket.Pass(); |
128 } | 122 } |
129 | 123 |
130 base::MessageLoop message_loop_; | 124 base::MessageLoop message_loop_; |
131 | 125 |
132 scoped_refptr<RsaKeyPair> key_pair_; | 126 scoped_refptr<RsaKeyPair> key_pair_; |
133 std::string host_cert_; | 127 std::string host_cert_; |
134 scoped_ptr<FakeSocket> client_fake_socket_; | 128 scoped_ptr<FakeSocket> client_fake_socket_; |
135 scoped_ptr<FakeSocket> host_fake_socket_; | 129 scoped_ptr<FakeSocket> host_fake_socket_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 host_auth_ = SslHmacChannelAuthenticator::CreateForHost( | 164 host_auth_ = SslHmacChannelAuthenticator::CreateForHost( |
171 host_cert_, key_pair_, kTestSharedSecret); | 165 host_cert_, key_pair_, kTestSharedSecret); |
172 | 166 |
173 RunChannelAuth(true); | 167 RunChannelAuth(true); |
174 | 168 |
175 ASSERT_TRUE(host_socket_.get() == NULL); | 169 ASSERT_TRUE(host_socket_.get() == NULL); |
176 } | 170 } |
177 | 171 |
178 } // namespace protocol | 172 } // namespace protocol |
179 } // namespace remoting | 173 } // namespace remoting |
OLD | NEW |