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

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

Issue 138753005: Add gnubby authentication to remoting host (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change authorization socket flag name 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
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.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 GnubbyAuthHandlerTest : public testing::Test {
51 public:
52 GnubbyAuthHandlerTest() {}
53
54 virtual void SetUp() OVERRIDE;
55
56 protected:
57 // Object under test.
58 scoped_ptr<GnubbyAuthHandler> auth_handler_;
59
60 // Mock client stub.
61 MockClientStub client_stub_;
62
63 private:
64 void OnConnect(int result);
65 };
66
67 void GnubbyAuthHandlerTest::SetUp() {
68 auth_handler_.reset(new GnubbyAuthHandler(&client_stub_));
69 }
70
71 MATCHER_P(EqualsCloseMessage, id, "") {
72 std::string message = base::StringPrintf("control close %d", id);
73 return (arg.type() == "gnubby-auth" && arg.data() == message);
74 }
75
76 MATCHER_P2(EqualsDataMessage, id, data, "") {
77 std::string message = base::StringPrintf("data %d %s", id, data);
78 return (arg.type() == "gnubby-auth" && arg.data() == message);
79 }
80
81 TEST_F(GnubbyAuthHandlerTest, DeliverHostControlMessage) {
82 EXPECT_CALL(client_stub_, DeliverHostMessage(EqualsCloseMessage(42)));
83
84 auth_handler_->DeliverHostControlMessage("close", "42");
85 }
86
87 TEST_F(GnubbyAuthHandlerTest, DeliverHostDataMessage) {
88 EXPECT_CALL(client_stub_,
89 DeliverHostMessage(EqualsDataMessage(42, "test_msg")));
90
91 auth_handler_->DeliverHostDataMessage(42, "test_msg");
92 }
93
94 TEST_F(GnubbyAuthHandlerTest, DidClose) {
95 net::StreamListenSocket* socket =
96 new MockStreamListenSocket(auth_handler_.get());
97
98 auth_handler_->DidAccept(NULL, make_scoped_ptr(socket));
99 ASSERT_TRUE(auth_handler_->HasActiveSocketForTesting(socket));
100
101 auth_handler_->DidClose(socket);
102 ASSERT_FALSE(auth_handler_->HasActiveSocketForTesting(socket));
103 }
104
105 TEST_F(GnubbyAuthHandlerTest, DidRead) {
106 EXPECT_CALL(client_stub_, DeliverHostMessage(_));
107
108 net::StreamListenSocket* socket =
109 new MockStreamListenSocket(auth_handler_.get());
110
111 auth_handler_->DidAccept(NULL, make_scoped_ptr(socket));
112
113 auth_handler_->DidRead(socket, request_data, sizeof(request_data));
114 }
115
116 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698