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

Side by Side Diff: blimp/net/engine_authentication_handler_unittest.cc

Issue 1876983002: Use Chromium BUILD to approximate Blimp protocol version, and check it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add disconnection message and unit-tests Created 4 years, 8 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <string> 6 #include <string>
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/test/test_mock_time_task_runner.h" 9 #include "base/test/test_mock_time_task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "blimp/common/create_blimp_message.h" 11 #include "blimp/common/create_blimp_message.h"
12 #include "blimp/common/proto/blimp_message.pb.h" 12 #include "blimp/common/proto/blimp_message.pb.h"
13 #include "blimp/common/version_info.h"
13 #include "blimp/net/blimp_connection.h" 14 #include "blimp/net/blimp_connection.h"
14 #include "blimp/net/blimp_transport.h" 15 #include "blimp/net/blimp_transport.h"
15 #include "blimp/net/common.h" 16 #include "blimp/net/common.h"
16 #include "blimp/net/connection_error_observer.h" 17 #include "blimp/net/connection_error_observer.h"
17 #include "blimp/net/engine_authentication_handler.h" 18 #include "blimp/net/engine_authentication_handler.h"
18 #include "blimp/net/test_common.h" 19 #include "blimp/net/test_common.h"
19 #include "net/base/completion_callback.h" 20 #include "net/base/completion_callback.h"
20 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
21 #include "net/base/test_completion_callback.h" 22 #include "net/base/test_completion_callback.h"
22 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 using testing::_; 26 using testing::_;
26 using testing::Eq; 27 using testing::Eq;
28 using testing::Return;
27 using testing::SaveArg; 29 using testing::SaveArg;
28 30
29 namespace blimp { 31 namespace blimp {
30 namespace { 32 namespace {
31 static const std::string client_token = "valid token"; 33 static const std::string client_token = "valid token";
32 } // namespace 34 } // namespace
33 35
34 class EngineAuthenticationHandlerTest : public testing::Test { 36 class EngineAuthenticationHandlerTest : public testing::Test {
35 public: 37 public:
36 EngineAuthenticationHandlerTest() 38 EngineAuthenticationHandlerTest()
(...skipping 24 matching lines...) Expand all
61 63
62 TEST_F(EngineAuthenticationHandlerTest, AuthenticationSucceeds) { 64 TEST_F(EngineAuthenticationHandlerTest, AuthenticationSucceeds) {
63 ExpectOnConnection(); 65 ExpectOnConnection();
64 EXPECT_CALL(*connection_, RemoveConnectionErrorObserver(_)); 66 EXPECT_CALL(*connection_, RemoveConnectionErrorObserver(_));
65 EXPECT_CALL(connection_handler_, HandleConnectionPtr(Eq(connection_.get()))); 67 EXPECT_CALL(connection_handler_, HandleConnectionPtr(Eq(connection_.get())));
66 auth_handler_->HandleConnection(std::move(connection_)); 68 auth_handler_->HandleConnection(std::move(connection_));
67 EXPECT_NE(nullptr, error_observer_); 69 EXPECT_NE(nullptr, error_observer_);
68 EXPECT_NE(nullptr, incoming_message_processor_); 70 EXPECT_NE(nullptr, incoming_message_processor_);
69 71
70 std::unique_ptr<BlimpMessage> blimp_message = 72 std::unique_ptr<BlimpMessage> blimp_message =
71 CreateStartConnectionMessage(client_token, 0); 73 CreateStartConnectionMessage(client_token, GetProtocolVersion());
72 net::TestCompletionCallback process_message_cb; 74 net::TestCompletionCallback process_message_cb;
73 incoming_message_processor_->ProcessMessage(std::move(blimp_message), 75 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
74 process_message_cb.callback()); 76 process_message_cb.callback());
75 EXPECT_EQ(net::OK, process_message_cb.WaitForResult()); 77 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
76 } 78 }
77 79
80 TEST_F(EngineAuthenticationHandlerTest, ProtocolMismatch) {
81 const int kInvalidProtocolVersion = -1;
82
83 BlimpMessage end_connection_message;
84 MockBlimpMessageProcessor message_processor;
85 EXPECT_CALL(message_processor, MockableProcessMessage(_, _))
86 .WillOnce(SaveArg<0>(&end_connection_message));
87 EXPECT_CALL(*connection_, GetOutgoingMessageProcessor())
88 .WillOnce(Return(&message_processor));
89
90 ExpectOnConnection();
91 auth_handler_->HandleConnection(std::move(connection_));
92
93 std::unique_ptr<BlimpMessage> blimp_message =
94 CreateStartConnectionMessage(client_token, kInvalidProtocolVersion);
95 net::TestCompletionCallback process_message_cb;
96 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
97 process_message_cb.callback());
98 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
99
100 EXPECT_EQ(BlimpMessage::PROTOCOL_CONTROL, end_connection_message.type());
101 EXPECT_EQ(ProtocolControlMessage::END_CONNECTION,
102 end_connection_message.protocol_control().type());
103 EXPECT_EQ(
104 EndConnectionMessage::PROTOCOL_MISMATCH,
105 end_connection_message.protocol_control().end_connection().reason());
106 }
107
78 TEST_F(EngineAuthenticationHandlerTest, AuthenticationFailed) { 108 TEST_F(EngineAuthenticationHandlerTest, AuthenticationFailed) {
79 ExpectOnConnection(); 109 ExpectOnConnection();
80 auth_handler_->HandleConnection(std::move(connection_)); 110 auth_handler_->HandleConnection(std::move(connection_));
81 111
82 std::unique_ptr<BlimpMessage> blimp_message = 112 std::unique_ptr<BlimpMessage> blimp_message =
83 CreateStartConnectionMessage("invalid token", 0); 113 CreateStartConnectionMessage("invalid token", GetProtocolVersion());
84 net::TestCompletionCallback process_message_cb; 114 net::TestCompletionCallback process_message_cb;
85 incoming_message_processor_->ProcessMessage(std::move(blimp_message), 115 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
86 process_message_cb.callback()); 116 process_message_cb.callback());
87 EXPECT_EQ(net::OK, process_message_cb.WaitForResult()); 117 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
88 } 118 }
89 119
90 TEST_F(EngineAuthenticationHandlerTest, WrongMessageReceived) { 120 TEST_F(EngineAuthenticationHandlerTest, WrongMessageReceived) {
91 ExpectOnConnection(); 121 ExpectOnConnection();
92 auth_handler_->HandleConnection(std::move(connection_)); 122 auth_handler_->HandleConnection(std::move(connection_));
93 123
(...skipping 22 matching lines...) Expand all
116 146
117 runner_->FastForwardBy(base::TimeDelta::FromSeconds(11)); 147 runner_->FastForwardBy(base::TimeDelta::FromSeconds(11));
118 } 148 }
119 149
120 TEST_F(EngineAuthenticationHandlerTest, AuthHandlerDeletedFirst) { 150 TEST_F(EngineAuthenticationHandlerTest, AuthHandlerDeletedFirst) {
121 ExpectOnConnection(); 151 ExpectOnConnection();
122 auth_handler_->HandleConnection(std::move(connection_)); 152 auth_handler_->HandleConnection(std::move(connection_));
123 auth_handler_.reset(); 153 auth_handler_.reset();
124 154
125 std::unique_ptr<BlimpMessage> blimp_message = 155 std::unique_ptr<BlimpMessage> blimp_message =
126 CreateStartConnectionMessage(client_token, 0); 156 CreateStartConnectionMessage(client_token, GetProtocolVersion());
127 net::TestCompletionCallback process_message_cb; 157 net::TestCompletionCallback process_message_cb;
128 incoming_message_processor_->ProcessMessage(std::move(blimp_message), 158 incoming_message_processor_->ProcessMessage(std::move(blimp_message),
129 process_message_cb.callback()); 159 process_message_cb.callback());
130 EXPECT_EQ(net::OK, process_message_cb.WaitForResult()); 160 EXPECT_EQ(net::OK, process_message_cb.WaitForResult());
131 } 161 }
132 162
133 } // namespace blimp 163 } // namespace blimp
OLDNEW
« blimp/net/engine_authentication_handler.cc ('K') | « blimp/net/engine_authentication_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698