Chromium Code Reviews| 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" |
|
Wez
2015/06/22 15:49:07
Need the p2p_socket.h include here?
Sergey Ulanov
2015/07/10 00:49:54
Done.
| |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 23 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
| 24 | 24 |
| 25 using testing::_; | 25 using testing::_; |
| 26 using testing::NotNull; | 26 using testing::NotNull; |
| 27 using testing::SaveArg; | 27 using testing::SaveArg; |
| 28 | 28 |
| 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(int error, P2PStreamSocket* 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 // called. | 108 // called. |
| 109 base::Timer shutdown_timer(false, false); | 109 base::Timer shutdown_timer(false, false); |
| 110 shutdown_timer.Start(FROM_HERE, | 110 shutdown_timer.Start(FROM_HERE, |
| 111 TestTimeouts::action_timeout(), | 111 TestTimeouts::action_timeout(), |
| 112 base::MessageLoop::QuitClosure()); | 112 base::MessageLoop::QuitClosure()); |
| 113 message_loop_.Run(); | 113 message_loop_.Run(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void OnHostConnected(const std::string& ref_argument, | 116 void OnHostConnected(const std::string& ref_argument, |
| 117 int error, | 117 int error, |
| 118 scoped_ptr<net::StreamSocket> socket) { | 118 scoped_ptr<P2PStreamSocket> socket) { |
| 119 // Try deleting the authenticator and verify that this doesn't destroy | 119 // Try deleting the authenticator and verify that this doesn't destroy |
| 120 // reference parameters. | 120 // reference parameters. |
| 121 host_auth_.reset(); | 121 host_auth_.reset(); |
| 122 DCHECK_EQ(ref_argument, "ref argument value"); | 122 DCHECK_EQ(ref_argument, "ref argument value"); |
| 123 | 123 |
| 124 host_callback_.OnDone(error, socket.get()); | 124 host_callback_.OnDone(error, socket.get()); |
| 125 host_socket_ = socket.Pass(); | 125 host_socket_ = socket.Pass(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void OnClientConnected(int error, scoped_ptr<net::StreamSocket> socket) { | 128 void OnClientConnected(int error, scoped_ptr<P2PStreamSocket> socket) { |
| 129 client_auth_.reset(); | 129 client_auth_.reset(); |
| 130 client_callback_.OnDone(error, socket.get()); | 130 client_callback_.OnDone(error, socket.get()); |
| 131 client_socket_ = socket.Pass(); | 131 client_socket_ = socket.Pass(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 base::MessageLoop message_loop_; | 134 base::MessageLoop message_loop_; |
| 135 | 135 |
| 136 scoped_refptr<RsaKeyPair> key_pair_; | 136 scoped_refptr<RsaKeyPair> key_pair_; |
| 137 std::string host_cert_; | 137 std::string host_cert_; |
| 138 scoped_ptr<FakeStreamSocket> client_fake_socket_; | 138 scoped_ptr<FakeStreamSocket> client_fake_socket_; |
| 139 scoped_ptr<FakeStreamSocket> host_fake_socket_; | 139 scoped_ptr<FakeStreamSocket> host_fake_socket_; |
| 140 scoped_ptr<ChannelAuthenticator> client_auth_; | 140 scoped_ptr<ChannelAuthenticator> client_auth_; |
| 141 scoped_ptr<ChannelAuthenticator> host_auth_; | 141 scoped_ptr<ChannelAuthenticator> host_auth_; |
| 142 MockChannelDoneCallback client_callback_; | 142 MockChannelDoneCallback client_callback_; |
| 143 MockChannelDoneCallback host_callback_; | 143 MockChannelDoneCallback host_callback_; |
| 144 scoped_ptr<net::StreamSocket> client_socket_; | 144 scoped_ptr<P2PStreamSocket> client_socket_; |
| 145 scoped_ptr<net::StreamSocket> host_socket_; | 145 scoped_ptr<P2PStreamSocket> host_socket_; |
| 146 | 146 |
| 147 DISALLOW_COPY_AND_ASSIGN(SslHmacChannelAuthenticatorTest); | 147 DISALLOW_COPY_AND_ASSIGN(SslHmacChannelAuthenticatorTest); |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 // Verify that a channel can be connected using a valid shared secret. | 150 // Verify that a channel can be connected using a valid shared secret. |
| 151 TEST_F(SslHmacChannelAuthenticatorTest, SuccessfulAuth) { | 151 TEST_F(SslHmacChannelAuthenticatorTest, SuccessfulAuth) { |
| 152 client_auth_ = SslHmacChannelAuthenticator::CreateForClient( | 152 client_auth_ = SslHmacChannelAuthenticator::CreateForClient( |
| 153 host_cert_, kTestSharedSecret); | 153 host_cert_, kTestSharedSecret); |
| 154 host_auth_ = SslHmacChannelAuthenticator::CreateForHost( | 154 host_auth_ = SslHmacChannelAuthenticator::CreateForHost( |
| 155 host_cert_, key_pair_, kTestSharedSecret); | 155 host_cert_, key_pair_, kTestSharedSecret); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 host_auth_ = SslHmacChannelAuthenticator::CreateForHost( | 193 host_auth_ = SslHmacChannelAuthenticator::CreateForHost( |
| 194 host_cert_, key_pair_, kTestSharedSecret); | 194 host_cert_, key_pair_, kTestSharedSecret); |
| 195 | 195 |
| 196 RunChannelAuth(net::ERR_CERT_INVALID, net::ERR_CONNECTION_CLOSED); | 196 RunChannelAuth(net::ERR_CERT_INVALID, net::ERR_CONNECTION_CLOSED); |
| 197 | 197 |
| 198 ASSERT_TRUE(host_socket_.get() == nullptr); | 198 ASSERT_TRUE(host_socket_.get() == nullptr); |
| 199 } | 199 } |
| 200 | 200 |
| 201 } // namespace protocol | 201 } // namespace protocol |
| 202 } // namespace remoting | 202 } // namespace remoting |
| OLD | NEW |