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

Side by Side Diff: remoting/host/gnubby_auth_handler_posix_unittest.cc

Issue 138753005: Add gnubby authentication to remoting host (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Another Windows warning Created 6 years, 10 months 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
« no previous file with comments | « remoting/host/gnubby_auth_handler_posix.cc ('k') | remoting/host/gnubby_auth_handler_win.cc » ('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 2014 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/strings/stringprintf.h"
6 #include "net/socket/stream_listen_socket.h"
7 #include "remoting/host/gnubby_auth_handler_posix.h"
8 #include "remoting/protocol/protocol_mock_objects.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace remoting {
12
13 using protocol::MockClientStub;
14
15 using testing::_;
16 using testing::Return;
17
18 namespace {
19
20 // Test gnubby request data.
21 const char request_data[] = {
22 0x00, 0x00, 0x00, 0x9a, 0x65, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
23 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x60, 0x90,
24 0x24, 0x71, 0xf8, 0xf2, 0xe5, 0xdf, 0x7f, 0x81, 0xc7, 0x49, 0xc4, 0xa3,
25 0x58, 0x5c, 0xf6, 0xcc, 0x40, 0x14, 0x28, 0x0c, 0xa0, 0xfa, 0x03, 0x18,
26 0x38, 0xd8, 0x7d, 0x77, 0x2b, 0x3a, 0x00, 0x00, 0x00, 0x20, 0x64, 0x46,
27 0x47, 0x2f, 0xdf, 0x6e, 0xed, 0x7b, 0xf3, 0xc3, 0x37, 0x20, 0xf2, 0x36,
28 0x67, 0x6c, 0x36, 0xe1, 0xb4, 0x5e, 0xbe, 0x04, 0x85, 0xdb, 0x89, 0xa3,
29 0xcd, 0xfd, 0xd2, 0x4b, 0xd6, 0x9f, 0x00, 0x00, 0x00, 0x40, 0x38, 0x35,
30 0x05, 0x75, 0x1d, 0x13, 0x6e, 0xb3, 0x6b, 0x1d, 0x29, 0xae, 0xd3, 0x43,
31 0xe6, 0x84, 0x8f, 0xa3, 0x9d, 0x65, 0x4e, 0x2f, 0x57, 0xe3, 0xf6, 0xe6,
32 0x20, 0x3c, 0x00, 0xc6, 0xe1, 0x73, 0x34, 0xe2, 0x23, 0x99, 0xc4, 0xfa,
33 0x91, 0xc2, 0xd5, 0x97, 0xc1, 0x8b, 0xd0, 0x3c, 0x13, 0xba, 0xf0, 0xd7,
34 0x5e, 0xa3, 0xbc, 0x02, 0x5b, 0xec, 0xe4, 0x4b, 0xae, 0x0e, 0xf2, 0xbd,
35 0xc8, 0xaa};
36
37 class MockStreamListenSocket : public net::StreamListenSocket {
38 public:
39 explicit MockStreamListenSocket(net::StreamListenSocket::Delegate* delegate)
40 : StreamListenSocket(net::kInvalidSocket, delegate) {}
41
42 virtual void Accept() OVERRIDE { NOTREACHED(); }
43
44 private:
45 virtual ~MockStreamListenSocket() {}
46 };
47
48 } // namespace
49
50 class GnubbyAuthHandlerPosixTest : public testing::Test {
51 public:
52 GnubbyAuthHandlerPosixTest() {}
53
54 virtual void SetUp() OVERRIDE;
55
56 protected:
57 // Object under test.
58 scoped_ptr<GnubbyAuthHandlerPosix> auth_handler_posix_;
59
60 // GnubbyAuthHandler interface for |auth_handler_posix_|.
61 GnubbyAuthHandler* auth_handler_;
62
63 // Stream delegate interface for |auth_handler_posix_|.
64 net::StreamListenSocket::Delegate* delegate_;
65
66 // Mock client stub.
67 MockClientStub client_stub_;
68
69 private:
70 void OnConnect(int result);
71 };
72
73 void GnubbyAuthHandlerPosixTest::SetUp() {
74 auth_handler_posix_.reset(new GnubbyAuthHandlerPosix(&client_stub_));
75 auth_handler_ = auth_handler_posix_.get();
76 delegate_ = auth_handler_posix_.get();
77 }
78
79 MATCHER_P2(EqualsDataMessage, id, data, "") {
80 std::string connection_id = base::StringPrintf("\"connectionId\":%d", id);
81 std::string json_message = base::StringPrintf("\"jsonMessage\":\"%s\"", data);
82
83 return (arg.type() == "gnubby-auth" &&
84 arg.data().find("\"type\":\"data\"") != std::string::npos &&
85 arg.data().find(connection_id) != std::string::npos &&
86 arg.data().find(json_message) != std::string::npos);
87 }
88
89 TEST_F(GnubbyAuthHandlerPosixTest, HostDataMessageDelivered) {
90 EXPECT_CALL(client_stub_,
91 DeliverHostMessage(EqualsDataMessage(42, "test_msg")));
92
93 auth_handler_->DeliverHostDataMessage(42, "test_msg");
94 }
95
96 TEST_F(GnubbyAuthHandlerPosixTest, DidClose) {
97 net::StreamListenSocket* socket = new MockStreamListenSocket(delegate_);
98
99 delegate_->DidAccept(NULL, make_scoped_ptr(socket));
100 ASSERT_TRUE(auth_handler_posix_->HasActiveSocketForTesting(socket));
101
102 delegate_->DidClose(socket);
103 ASSERT_FALSE(auth_handler_posix_->HasActiveSocketForTesting(socket));
104 }
105
106 TEST_F(GnubbyAuthHandlerPosixTest, DidRead) {
107 EXPECT_CALL(client_stub_, DeliverHostMessage(_));
108
109 net::StreamListenSocket* socket = new MockStreamListenSocket(delegate_);
110
111 delegate_->DidAccept(NULL, make_scoped_ptr(socket));
112 delegate_->DidRead(socket, request_data, sizeof(request_data));
113 }
114
115 TEST_F(GnubbyAuthHandlerPosixTest, DidReadByteByByte) {
116 EXPECT_CALL(client_stub_, DeliverHostMessage(_));
117
118 net::StreamListenSocket* socket = new MockStreamListenSocket(delegate_);
119
120 delegate_->DidAccept(NULL, make_scoped_ptr(socket));
121 for (unsigned int i = 0; i < sizeof(request_data); ++i) {
122 delegate_->DidRead(socket, request_data + i, 1);
123 }
124 }
125
126 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/gnubby_auth_handler_posix.cc ('k') | remoting/host/gnubby_auth_handler_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698