| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/protocol/v1_authenticator.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "net/base/net_errors.h" | |
| 9 #include "remoting/protocol/authenticator.h" | |
| 10 #include "remoting/protocol/authenticator_test_base.h" | |
| 11 #include "remoting/protocol/channel_authenticator.h" | |
| 12 #include "remoting/protocol/connection_tester.h" | |
| 13 #include "remoting/protocol/fake_session.h" | |
| 14 #include "testing/gmock/include/gmock/gmock.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | |
| 17 | |
| 18 using testing::_; | |
| 19 using testing::DeleteArg; | |
| 20 using testing::Mock; | |
| 21 using testing::SaveArg; | |
| 22 | |
| 23 namespace remoting { | |
| 24 namespace protocol { | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 const int kMessageSize = 100; | |
| 29 const int kMessages = 1; | |
| 30 | |
| 31 const char kClientJid[] = "host2@gmail.com/321"; | |
| 32 | |
| 33 const char kTestSharedSecret[] = "1234-1234-5678"; | |
| 34 const char kTestSharedSecretBad[] = "0000-0000-0001"; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 class V1AuthenticatorTest : public AuthenticatorTestBase { | |
| 39 public: | |
| 40 V1AuthenticatorTest() { | |
| 41 } | |
| 42 virtual ~V1AuthenticatorTest() { | |
| 43 } | |
| 44 | |
| 45 protected: | |
| 46 void InitAuthenticators(const std::string& client_secret, | |
| 47 const std::string& host_secret) { | |
| 48 host_.reset(new V1HostAuthenticator( | |
| 49 host_cert_, *private_key_, host_secret, kClientJid)); | |
| 50 client_.reset(new V1ClientAuthenticator(kClientJid, client_secret)); | |
| 51 } | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(V1AuthenticatorTest); | |
| 54 }; | |
| 55 | |
| 56 TEST_F(V1AuthenticatorTest, SuccessfulAuth) { | |
| 57 { | |
| 58 SCOPED_TRACE("RunAuthExchange"); | |
| 59 InitAuthenticators(kTestSharedSecret, kTestSharedSecret); | |
| 60 RunAuthExchange(); | |
| 61 } | |
| 62 ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); | |
| 63 ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); | |
| 64 | |
| 65 client_auth_ = client_->CreateChannelAuthenticator(); | |
| 66 host_auth_ = host_->CreateChannelAuthenticator(); | |
| 67 RunChannelAuth(false); | |
| 68 | |
| 69 EXPECT_TRUE(client_socket_.get() != NULL); | |
| 70 EXPECT_TRUE(host_socket_.get() != NULL); | |
| 71 | |
| 72 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), | |
| 73 kMessageSize, kMessages); | |
| 74 | |
| 75 tester.Start(); | |
| 76 message_loop_.Run(); | |
| 77 tester.CheckResults(); | |
| 78 } | |
| 79 | |
| 80 // Verify that connection is rejected when secrets don't match. | |
| 81 TEST_F(V1AuthenticatorTest, InvalidSecret) { | |
| 82 { | |
| 83 SCOPED_TRACE("RunAuthExchange"); | |
| 84 InitAuthenticators(kTestSharedSecretBad, kTestSharedSecret); | |
| 85 RunAuthExchange(); | |
| 86 } | |
| 87 ASSERT_EQ(Authenticator::REJECTED, host_->state()); | |
| 88 } | |
| 89 | |
| 90 } // namespace protocol | |
| 91 } // namespace remoting | |
| OLD | NEW |