Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: remoting/protocol/v1_authenticator_unittest.cc

Issue 8647001: Add implementation for current IT2Me auth. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/v1_authenticator.cc ('k') | remoting/remoting.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "base/file_path.h"
6 #include "base/file_util.h"
7 #include "base/path_service.h"
8 #include "crypto/rsa_private_key.h"
9 #include "remoting/protocol/v1_authenticator.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
13
14 namespace remoting {
15 namespace protocol {
16
17 namespace {
18 const char kHostJid[] = "host1@gmail.com/123";
19 const char kClientJid[] = "host2@gmail.com/321";
20
21 const char kTestSharedSecret[] = "1234-1234-5678";
22 const char kTestSharedSecretBad[] = "0000-0000-0001";
23 } // namespace
24
25 class V1AuthenticatorTest : public testing::Test {
26 public:
27 V1AuthenticatorTest() {
28 }
29 virtual ~V1AuthenticatorTest() {
30 }
31
32 protected:
33 void InitAuthenticators(const std::string& client_secret,
34 const std::string& host_secret) {
35 FilePath certs_dir;
36 PathService::Get(base::DIR_SOURCE_ROOT, &certs_dir);
37 certs_dir = certs_dir.AppendASCII("net");
38 certs_dir = certs_dir.AppendASCII("data");
39 certs_dir = certs_dir.AppendASCII("ssl");
40 certs_dir = certs_dir.AppendASCII("certificates");
41
42 FilePath cert_path = certs_dir.AppendASCII("unittest.selfsigned.der");
43 std::string cert_der;
44 ASSERT_TRUE(file_util::ReadFileToString(cert_path, &cert_der));
45
46 FilePath key_path = certs_dir.AppendASCII("unittest.key.bin");
47 std::string key_string;
48 ASSERT_TRUE(file_util::ReadFileToString(key_path, &key_string));
49 std::vector<uint8> key_vector(
50 reinterpret_cast<const uint8*>(key_string.data()),
51 reinterpret_cast<const uint8*>(key_string.data() +
52 key_string.length()));
53 private_key_.reset(
54 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_vector));
55
56 host_.reset(new V1HostAuthenticator(
57 cert_der, private_key_.get(), host_secret, kClientJid));
58 client_.reset(new V1ClientAuthenticator(kClientJid, client_secret));
59 }
60
61 void RunAuthExchange() {
62 do {
63 scoped_ptr<buzz::XmlElement> message;
64
65 // Pass message from client to host.
66 ASSERT_EQ(Authenticator::MESSAGE_READY, client_->state());
67 message.reset(client_->GetNextMessage());
68 ASSERT_TRUE(message.get());
69 ASSERT_NE(Authenticator::MESSAGE_READY, client_->state());
70
71 ASSERT_EQ(Authenticator::WAITING_MESSAGE, host_->state());
72 host_->ProcessMessage(message.get());
73 ASSERT_NE(Authenticator::WAITING_MESSAGE, host_->state());
74
75 // Are we done yet?
76 if (host_->state() == Authenticator::ACCEPTED ||
77 host_->state() == Authenticator::REJECTED) {
78 break;
79 }
80
81 // Pass message from host to client.
82 ASSERT_EQ(Authenticator::MESSAGE_READY, host_->state());
83 message.reset(host_->GetNextMessage());
84 ASSERT_TRUE(message.get());
85 ASSERT_NE(Authenticator::MESSAGE_READY, host_->state());
86
87 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state());
88 client_->ProcessMessage(message.get());
89 ASSERT_NE(Authenticator::WAITING_MESSAGE, client_->state());
90 } while (host_->state() != Authenticator::ACCEPTED &&
91 host_->state() != Authenticator::REJECTED);
92 }
93
94 scoped_ptr<crypto::RSAPrivateKey> private_key_;
95 scoped_ptr<V1HostAuthenticator> host_;
96 scoped_ptr<V1ClientAuthenticator> client_;
97
98 DISALLOW_COPY_AND_ASSIGN(V1AuthenticatorTest);
99 };
100
101 TEST_F(V1AuthenticatorTest, SuccessfulAuth) {
102 {
103 SCOPED_TRACE("RunAuthExchange");
104 InitAuthenticators(kTestSharedSecret, kTestSharedSecret);
105 RunAuthExchange();
106 }
107 ASSERT_EQ(Authenticator::ACCEPTED, host_->state());
108 ASSERT_EQ(Authenticator::ACCEPTED, client_->state());
109 }
110
111 TEST_F(V1AuthenticatorTest, InvalidSecret) {
112 {
113 SCOPED_TRACE("RunAuthExchange");
114 InitAuthenticators(kTestSharedSecretBad, kTestSharedSecret);
115 RunAuthExchange();
116 }
117 ASSERT_EQ(Authenticator::REJECTED, host_->state());
118 }
119
120 } // namespace protocol
121 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/v1_authenticator.cc ('k') | remoting/remoting.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698