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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/gnubby_auth_handler_unittest.cc
diff --git a/remoting/host/gnubby_auth_handler_unittest.cc b/remoting/host/gnubby_auth_handler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..94458c8250687131adbdc73b8c7dad84411fc727
--- /dev/null
+++ b/remoting/host/gnubby_auth_handler_unittest.cc
@@ -0,0 +1,116 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/strings/stringprintf.h"
+#include "net/socket/stream_listen_socket.h"
+#include "remoting/host/gnubby_auth_handler.h"
+#include "remoting/protocol/protocol_mock_objects.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace remoting {
+
+using protocol::MockClientStub;
+
+using testing::_;
+using testing::Return;
+
+namespace {
+
+// Test gnubby request data.
+const char request_data[] = {
+ 0x00, 0x00, 0x00, 0x9a, 0x65, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
+ 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x60, 0x90,
+ 0x24, 0x71, 0xf8, 0xf2, 0xe5, 0xdf, 0x7f, 0x81, 0xc7, 0x49, 0xc4, 0xa3,
+ 0x58, 0x5c, 0xf6, 0xcc, 0x40, 0x14, 0x28, 0x0c, 0xa0, 0xfa, 0x03, 0x18,
+ 0x38, 0xd8, 0x7d, 0x77, 0x2b, 0x3a, 0x00, 0x00, 0x00, 0x20, 0x64, 0x46,
+ 0x47, 0x2f, 0xdf, 0x6e, 0xed, 0x7b, 0xf3, 0xc3, 0x37, 0x20, 0xf2, 0x36,
+ 0x67, 0x6c, 0x36, 0xe1, 0xb4, 0x5e, 0xbe, 0x04, 0x85, 0xdb, 0x89, 0xa3,
+ 0xcd, 0xfd, 0xd2, 0x4b, 0xd6, 0x9f, 0x00, 0x00, 0x00, 0x40, 0x38, 0x35,
+ 0x05, 0x75, 0x1d, 0x13, 0x6e, 0xb3, 0x6b, 0x1d, 0x29, 0xae, 0xd3, 0x43,
+ 0xe6, 0x84, 0x8f, 0xa3, 0x9d, 0x65, 0x4e, 0x2f, 0x57, 0xe3, 0xf6, 0xe6,
+ 0x20, 0x3c, 0x00, 0xc6, 0xe1, 0x73, 0x34, 0xe2, 0x23, 0x99, 0xc4, 0xfa,
+ 0x91, 0xc2, 0xd5, 0x97, 0xc1, 0x8b, 0xd0, 0x3c, 0x13, 0xba, 0xf0, 0xd7,
+ 0x5e, 0xa3, 0xbc, 0x02, 0x5b, 0xec, 0xe4, 0x4b, 0xae, 0x0e, 0xf2, 0xbd,
+ 0xc8, 0xaa};
+
+class MockStreamListenSocket : public net::StreamListenSocket {
+ public:
+ explicit MockStreamListenSocket(net::StreamListenSocket::Delegate* delegate)
+ : StreamListenSocket(net::kInvalidSocket, delegate) {}
+
+ virtual void Accept() OVERRIDE { NOTREACHED(); }
+
+ private:
+ virtual ~MockStreamListenSocket() {}
+};
+
+} // namespace
+
+class GnubbyAuthHandlerTest : public testing::Test {
+ public:
+ GnubbyAuthHandlerTest() {}
+
+ virtual void SetUp() OVERRIDE;
+
+ protected:
+ // Object under test.
+ scoped_ptr<GnubbyAuthHandler> auth_handler_;
+
+ // Mock client stub.
+ MockClientStub client_stub_;
+
+ private:
+ void OnConnect(int result);
+};
+
+void GnubbyAuthHandlerTest::SetUp() {
+ auth_handler_.reset(new GnubbyAuthHandler(&client_stub_));
+}
+
+MATCHER_P(EqualsCloseMessage, id, "") {
+ std::string message = base::StringPrintf("control close %d", id);
+ return (arg.type() == "gnubby-auth" && arg.data() == message);
+}
+
+MATCHER_P2(EqualsDataMessage, id, data, "") {
+ std::string message = base::StringPrintf("data %d %s", id, data);
+ return (arg.type() == "gnubby-auth" && arg.data() == message);
+}
+
+TEST_F(GnubbyAuthHandlerTest, DeliverHostControlMessage) {
+ EXPECT_CALL(client_stub_, DeliverHostMessage(EqualsCloseMessage(42)));
+
+ auth_handler_->DeliverHostControlMessage("close", "42");
+}
+
+TEST_F(GnubbyAuthHandlerTest, DeliverHostDataMessage) {
+ EXPECT_CALL(client_stub_,
+ DeliverHostMessage(EqualsDataMessage(42, "test_msg")));
+
+ auth_handler_->DeliverHostDataMessage(42, "test_msg");
+}
+
+TEST_F(GnubbyAuthHandlerTest, DidClose) {
+ net::StreamListenSocket* socket =
+ new MockStreamListenSocket(auth_handler_.get());
+
+ auth_handler_->DidAccept(NULL, make_scoped_ptr(socket));
+ ASSERT_TRUE(auth_handler_->HasActiveSocketForTesting(socket));
+
+ auth_handler_->DidClose(socket);
+ ASSERT_FALSE(auth_handler_->HasActiveSocketForTesting(socket));
+}
+
+TEST_F(GnubbyAuthHandlerTest, DidRead) {
+ EXPECT_CALL(client_stub_, DeliverHostMessage(_));
+
+ net::StreamListenSocket* socket =
+ new MockStreamListenSocket(auth_handler_.get());
+
+ auth_handler_->DidAccept(NULL, make_scoped_ptr(socket));
+
+ auth_handler_->DidRead(socket, request_data, sizeof(request_data));
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698