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

Side by Side Diff: remoting/protocol/simple_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, 1 month 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
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 // Unittests in this file test both SimpleClientAuthenticator and
Wez 2011/11/22 22:58:05 nit: Unit tests in this file...
Sergey Ulanov 2011/11/23 02:02:25 Done.
6 // SimpleHostAuthenticator.
Wez 2011/11/22 22:58:05 Do you really need this comment?
Sergey Ulanov 2011/11/23 02:02:25 Done.
7
8 #include "base/file_path.h"
9 #include "base/file_util.h"
10 #include "base/path_service.h"
11 #include "crypto/rsa_private_key.h"
12 #include "remoting/protocol/simple_client_authenticator.h"
13 #include "remoting/protocol/simple_host_authenticator.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 namespace remoting {
19 namespace protocol {
20
21 namespace {
22 const char kHostJid[] = "host1@gmail.com/123";
23 const char kClientJid[] = "host2@gmail.com/321";
24
25 const char kTestSharedSecret[] = "1234-1234-5678";
26 const char kTestSharedSecretBad[] = "0000-0000-0001";
27 } // namespace
28
29 class SimpleAuthenticatorTest : public testing::Test {
30 public:
31 SimpleAuthenticatorTest() {
32 }
33 virtual ~SimpleAuthenticatorTest() {
34 }
35
36 protected:
37 void InitAuthenticators(const std::string& client_secret,
38 const std::string& host_secret) {
39 FilePath certs_dir;
40 PathService::Get(base::DIR_SOURCE_ROOT, &certs_dir);
41 certs_dir = certs_dir.AppendASCII("net");
42 certs_dir = certs_dir.AppendASCII("data");
43 certs_dir = certs_dir.AppendASCII("ssl");
44 certs_dir = certs_dir.AppendASCII("certificates");
45
46 FilePath cert_path = certs_dir.AppendASCII("unittest.selfsigned.der");
47 std::string cert_der;
48 ASSERT_TRUE(file_util::ReadFileToString(cert_path, &cert_der));
49
50 FilePath key_path = certs_dir.AppendASCII("unittest.key.bin");
51 std::string key_string;
52 ASSERT_TRUE(file_util::ReadFileToString(key_path, &key_string));
53 std::vector<uint8> key_vector(
54 reinterpret_cast<const uint8*>(key_string.data()),
55 reinterpret_cast<const uint8*>(key_string.data() +
56 key_string.length()));
57 private_key_.reset(
58 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_vector));
59
60 host_.reset(new SimpleHostAuthenticator(
61 cert_der, private_key_.get(), host_secret, kClientJid));
62 client_.reset(new SimpleClientAuthenticator(kClientJid, client_secret));
63 }
64
65 void RunAuthExchange() {
66 do {
67 scoped_ptr<buzz::XmlElement> message;
68
69 // Pass message from client to host.
70 ASSERT_EQ(Authenticator::MESSAGE_READY, client_->state());
71 message.reset(client_->GetNextMessage());
72 ASSERT_TRUE(message.get());
73 ASSERT_NE(Authenticator::MESSAGE_READY, client_->state());
74
75 ASSERT_EQ(Authenticator::WAITING_MESSAGE, host_->state());
76 host_->ProcessMessage(message.get());
77 ASSERT_NE(Authenticator::WAITING_MESSAGE, host_->state());
78
79 // Are we done yet?
80 if (host_->state() == Authenticator::ACCEPTED ||
81 host_->state() == Authenticator::REJECTED) {
82 break;
83 }
84
85 // Pass message from host to client.
86 ASSERT_EQ(Authenticator::MESSAGE_READY, host_->state());
87 message.reset(host_->GetNextMessage());
88 ASSERT_TRUE(message.get());
89 ASSERT_NE(Authenticator::MESSAGE_READY, host_->state());
90
91 ASSERT_EQ(Authenticator::WAITING_MESSAGE, client_->state());
92 client_->ProcessMessage(message.get());
93 ASSERT_NE(Authenticator::WAITING_MESSAGE, client_->state());
94 } while (host_->state() != Authenticator::ACCEPTED &&
95 host_->state() != Authenticator::REJECTED);
96 }
97
98 scoped_ptr<crypto::RSAPrivateKey> private_key_;
99 scoped_ptr<SimpleHostAuthenticator> host_;
100 scoped_ptr<SimpleClientAuthenticator> client_;
101
102 DISALLOW_COPY_AND_ASSIGN(SimpleAuthenticatorTest);
103 };
104
105 TEST_F(SimpleAuthenticatorTest, SuccessfulAuth) {
106 {
107 SCOPED_TRACE("RunAuthExchange");
108 InitAuthenticators(kTestSharedSecret, kTestSharedSecret);
109 RunAuthExchange();
110 }
111 ASSERT_EQ(Authenticator::ACCEPTED, host_->state());
112 ASSERT_EQ(Authenticator::ACCEPTED, client_->state());
113 }
114
115 TEST_F(SimpleAuthenticatorTest, InvalidSecret) {
116 {
117 SCOPED_TRACE("RunAuthExchange");
118 InitAuthenticators(kTestSharedSecretBad, kTestSharedSecret);
119 RunAuthExchange();
120 }
121 ASSERT_EQ(Authenticator::REJECTED, host_->state());
122 }
123
124 } // namespace protocol
125 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698