Add Download.ShowDangerousDownloadConfirmationPrompt for Windows/CrOS
[chromium-blink-merge.git] / remoting / protocol / v2_authenticator_unittest.cc
blobf57b6c31a2e5013bc7522c0a1b8628b01b36e3f7
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.
5 #include "remoting/protocol/v2_authenticator.h"
7 #include "base/bind.h"
8 #include "net/base/net_errors.h"
9 #include "remoting/base/rsa_key_pair.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 "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
17 using testing::_;
18 using testing::DeleteArg;
19 using testing::SaveArg;
21 namespace remoting {
22 namespace protocol {
24 namespace {
26 const int kMessageSize = 100;
27 const int kMessages = 1;
29 const char kTestSharedSecret[] = "1234-1234-5678";
30 const char kTestSharedSecretBad[] = "0000-0000-0001";
32 } // namespace
34 class V2AuthenticatorTest : public AuthenticatorTestBase {
35 public:
36 V2AuthenticatorTest() {
38 virtual ~V2AuthenticatorTest() {
41 protected:
42 void InitAuthenticators(const std::string& client_secret,
43 const std::string& host_secret) {
44 host_ = V2Authenticator::CreateForHost(
45 host_cert_, key_pair_, host_secret,
46 Authenticator::WAITING_MESSAGE);
47 client_ = V2Authenticator::CreateForClient(
48 client_secret, Authenticator::MESSAGE_READY);
51 DISALLOW_COPY_AND_ASSIGN(V2AuthenticatorTest);
54 // These tests use net::SSLServerSocket which is not implemented for OpenSSL.
55 #if defined(USE_OPENSSL)
56 #define MAYBE(x) DISABLED_##x
57 #else
58 #define MAYBE(x) x
59 #endif
61 TEST_F(V2AuthenticatorTest, MAYBE(SuccessfulAuth)) {
62 ASSERT_NO_FATAL_FAILURE(
63 InitAuthenticators(kTestSharedSecret, kTestSharedSecret));
64 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
66 ASSERT_EQ(Authenticator::ACCEPTED, host_->state());
67 ASSERT_EQ(Authenticator::ACCEPTED, client_->state());
69 client_auth_ = client_->CreateChannelAuthenticator();
70 host_auth_ = host_->CreateChannelAuthenticator();
71 RunChannelAuth(false);
73 StreamConnectionTester tester(host_socket_.get(), client_socket_.get(),
74 kMessageSize, kMessages);
76 tester.Start();
77 message_loop_.Run();
78 tester.CheckResults();
81 // Verify that connection is rejected when secrets don't match.
82 TEST_F(V2AuthenticatorTest, MAYBE(InvalidSecret)) {
83 ASSERT_NO_FATAL_FAILURE(
84 InitAuthenticators(kTestSharedSecretBad, kTestSharedSecret));
85 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
87 ASSERT_EQ(Authenticator::REJECTED, client_->state());
89 // Change |client_| so that we can get the last message.
90 reinterpret_cast<V2Authenticator*>(client_.get())->state_ =
91 Authenticator::MESSAGE_READY;
93 scoped_ptr<buzz::XmlElement> message(client_->GetNextMessage());
94 ASSERT_TRUE(message.get());
96 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state());
97 host_->ProcessMessage(message.get(), base::Bind(&base::DoNothing));
98 // This assumes that V2Authenticator::ProcessMessage runs synchronously.
99 ASSERT_EQ(Authenticator::REJECTED, host_->state());
102 } // namespace protocol
103 } // namespace remoting