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

Side by Side Diff: blimp/client/session/assignment_source_unittest.cc

Issue 1696563002: Blimp: add support for SSL connections. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wez feedback #48 Created 4 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "blimp/client/session/assignment_source.h" 5 #include "blimp/client/session/assignment_source.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h"
8 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/path_service.h"
15 #include "base/run_loop.h"
10 #include "base/test/test_simple_task_runner.h" 16 #include "base/test/test_simple_task_runner.h"
11 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
12 #include "base/values.h" 18 #include "base/values.h"
13 #include "blimp/client/app/blimp_client_switches.h" 19 #include "blimp/client/app/blimp_client_switches.h"
14 #include "blimp/common/protocol_version.h" 20 #include "blimp/common/protocol_version.h"
21 #include "components/safe_json/testing_json_parser.h"
22 #include "net/base/test_data_directory.h"
15 #include "net/url_request/test_url_fetcher_factory.h" 23 #include "net/url_request/test_url_fetcher_factory.h"
16 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
18 26
19 using testing::_; 27 using testing::_;
28 using testing::DoAll;
20 using testing::InSequence; 29 using testing::InSequence;
30 using testing::NotNull;
31 using testing::Return;
32 using testing::SetArgPointee;
21 33
22 namespace blimp { 34 namespace blimp {
23 namespace client { 35 namespace client {
24 namespace { 36 namespace {
25 37
38 const uint8_t kTestIPAddressStringAddress[] = {127, 0, 0, 1};
39 const uint16_t kTestPort = 8086;
40 const char kTestIPAddressString[] = "127.0.0.1";
41 const char kTCPTransportName[] = "tcp";
42 const char kSSLTransportName[] = "ssl";
43 const char kCertRelativePath[] =
44 "blimp/client/session/test_selfsigned_cert.pem";
45
26 MATCHER_P(AssignmentEquals, assignment, "") { 46 MATCHER_P(AssignmentEquals, assignment, "") {
27 return arg.transport_protocol == assignment.transport_protocol && 47 return arg.transport_protocol == assignment.transport_protocol &&
28 arg.ip_endpoint == assignment.ip_endpoint && 48 arg.engine_endpoint == assignment.engine_endpoint &&
29 arg.client_token == assignment.client_token && 49 arg.client_token == assignment.client_token &&
30 arg.certificate == assignment.certificate && 50 ((!assignment.cert && !arg.cert) ||
31 arg.certificate_fingerprint == assignment.certificate_fingerprint; 51 (arg.cert && assignment.cert &&
52 arg.cert->Equals(assignment.cert.get())));
32 } 53 }
33 54
34 net::IPEndPoint BuildIPEndPoint(const std::string& ip, int port) { 55 // Builds simulated JSON response from the Assigner service.
35 net::IPAddress ip_address; 56 // |assignment|: The Assignment to convert.
36 EXPECT_TRUE(ip_address.AssignFromIPLiteral(ip)); 57 // |expected_cert_str|: The PEM encoded certificate to include in the response.
37 58 std::string BuildResponseFromAssignment(const Assignment& assignment,
38 return net::IPEndPoint(ip_address, port); 59 const std::string& expected_cert_str) {
Wez 2016/03/02 02:26:45 nit: AFAICT all the calls to this API get passed t
Kevin M 2016/03/02 18:05:34 Good suggestion, done.
39 }
40
41 Assignment BuildValidAssignment() {
42 Assignment assignment;
43 assignment.transport_protocol = Assignment::TransportProtocol::SSL;
44 assignment.ip_endpoint = BuildIPEndPoint("100.150.200.250", 500);
45 assignment.client_token = "SecretT0kenz";
46 assignment.certificate_fingerprint = "WhaleWhaleWhale";
47 assignment.certificate = "whaaaaaaaaaaaaale";
48 return assignment;
49 }
50
51 std::string BuildResponseFromAssignment(const Assignment& assignment) {
52 base::DictionaryValue dict; 60 base::DictionaryValue dict;
53 dict.SetString("clientToken", assignment.client_token); 61 dict.SetString("clientToken", assignment.client_token);
54 dict.SetString("host", assignment.ip_endpoint.address().ToString()); 62 dict.SetString("host", assignment.engine_endpoint.address().ToString());
55 dict.SetInteger("port", assignment.ip_endpoint.port()); 63 dict.SetInteger("port", assignment.engine_endpoint.port());
56 dict.SetString("certificateFingerprint", assignment.certificate_fingerprint); 64 dict.SetString("certificate", expected_cert_str);
57 dict.SetString("certificate", assignment.certificate);
58 65
59 std::string json; 66 std::string json;
60 base::JSONWriter::Write(dict, &json); 67 base::JSONWriter::Write(dict, &json);
61 return json; 68 return json;
62 } 69 }
63 70
64 class AssignmentSourceTest : public testing::Test { 71 class AssignmentSourceTest : public testing::Test {
65 public: 72 public:
66 AssignmentSourceTest() 73 AssignmentSourceTest()
67 : task_runner_(new base::TestSimpleTaskRunner), 74 : source_(message_loop_.task_runner(), message_loop_.task_runner()) {}
68 task_runner_handle_(task_runner_), 75
69 source_(task_runner_, task_runner_) {} 76 void SetUp() override {
77 base::FilePath src_root;
78 PathService::Get(base::DIR_SOURCE_ROOT, &src_root);
Wez 2016/03/02 02:26:45 nit: ASSERT_TRUE this as well.
Kevin M 2016/03/02 18:05:34 Done.
79 cert_path_ = src_root.Append(kCertRelativePath);
80 ASSERT_TRUE(base::ReadFileToString(cert_path_, &cert_pem_));
81 cert_ = std::move(net::X509Certificate::CreateCertificateListFromBytes(
82 cert_pem_.data(), cert_pem_.size(),
83 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE)[0]);
Wez 2016/03/02 02:26:45 nit: ASSERT_TRUE that |cert_| is not empty?
Kevin M 2016/03/02 18:05:34 Done.
84 }
70 85
71 // This expects the AssignmentSource::GetAssignment to return a custom 86 // This expects the AssignmentSource::GetAssignment to return a custom
72 // endpoint without having to hit the network. This will typically be used 87 // endpoint without having to hit the network. This will typically be used
73 // for testing that specifying an assignment via the command line works as 88 // for testing that specifying an assignment via the command line works as
74 // expected. 89 // expected.
75 void GetAlternateAssignment() { 90 void GetAlternateAssignment() {
76 source_.GetAssignment("", 91 source_.GetAssignment("",
77 base::Bind(&AssignmentSourceTest::AssignmentResponse, 92 base::Bind(&AssignmentSourceTest::AssignmentResponse,
78 base::Unretained(this))); 93 base::Unretained(this)));
79 EXPECT_EQ(nullptr, factory_.GetFetcherByID(0)); 94 EXPECT_EQ(nullptr, factory_.GetFetcherByID(0));
80 task_runner_->RunUntilIdle(); 95 base::RunLoop().RunUntilIdle();
81 } 96 }
82 97
83 // See net/base/net_errors.h for possible status errors. 98 // See net/base/net_errors.h for possible status errors.
84 void GetNetworkAssignmentAndWaitForResponse( 99 void GetNetworkAssignmentAndWaitForResponse(
85 net::HttpStatusCode response_code, 100 net::HttpStatusCode response_code,
86 int status, 101 int status,
87 const std::string& response, 102 const std::string& response,
88 const std::string& client_auth_token, 103 const std::string& client_auth_token,
89 const std::string& protocol_version) { 104 const std::string& protocol_version) {
90 source_.GetAssignment(client_auth_token, 105 source_.GetAssignment(client_auth_token,
91 base::Bind(&AssignmentSourceTest::AssignmentResponse, 106 base::Bind(&AssignmentSourceTest::AssignmentResponse,
92 base::Unretained(this))); 107 base::Unretained(this)));
108 base::RunLoop().RunUntilIdle();
93 109
94 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); 110 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0);
95 111
96 task_runner_->RunUntilIdle();
97
98 EXPECT_NE(nullptr, fetcher); 112 EXPECT_NE(nullptr, fetcher);
99 EXPECT_EQ(kDefaultAssignerURL, fetcher->GetOriginalURL().spec()); 113 EXPECT_EQ(kDefaultAssignerURL, fetcher->GetOriginalURL().spec());
100 114
101 // Check that the request has a valid protocol_version. 115 // Check that the request has a valid protocol_version.
102 scoped_ptr<base::Value> json = 116 scoped_ptr<base::Value> json =
103 base::JSONReader::Read(fetcher->upload_data()); 117 base::JSONReader::Read(fetcher->upload_data());
104 EXPECT_NE(nullptr, json.get()); 118 EXPECT_NE(nullptr, json.get());
105 119
106 const base::DictionaryValue* dict; 120 const base::DictionaryValue* dict;
107 EXPECT_TRUE(json->GetAsDictionary(&dict)); 121 EXPECT_TRUE(json->GetAsDictionary(&dict));
(...skipping 10 matching lines...) Expand all
118 std::string authorization; 132 std::string authorization;
119 EXPECT_TRUE(headers.GetHeader("Authorization", &authorization)); 133 EXPECT_TRUE(headers.GetHeader("Authorization", &authorization));
120 EXPECT_EQ("Bearer " + client_auth_token, authorization); 134 EXPECT_EQ("Bearer " + client_auth_token, authorization);
121 135
122 // Send the fake response back. 136 // Send the fake response back.
123 fetcher->set_response_code(response_code); 137 fetcher->set_response_code(response_code);
124 fetcher->set_status(net::URLRequestStatus::FromError(status)); 138 fetcher->set_status(net::URLRequestStatus::FromError(status));
125 fetcher->SetResponseString(response); 139 fetcher->SetResponseString(response);
126 fetcher->delegate()->OnURLFetchComplete(fetcher); 140 fetcher->delegate()->OnURLFetchComplete(fetcher);
127 141
128 task_runner_->RunUntilIdle(); 142 base::RunLoop().RunUntilIdle();
129 } 143 }
130 144
131 MOCK_METHOD2(AssignmentResponse, 145 MOCK_METHOD2(AssignmentResponse,
132 void(AssignmentSource::Result, const Assignment&)); 146 void(AssignmentSource::Result, const Assignment&));
133 147
134 protected: 148 protected:
149 Assignment BuildValidAssignment();
Wez 2016/03/02 02:26:45 nit: Suggest renaming this to BuildSslAssignment()
Kevin M 2016/03/02 18:05:34 Done.
150
135 // Used to drive all AssignmentSource tasks. 151 // Used to drive all AssignmentSource tasks.
136 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 152 // MessageLoop is required by TestingJsonParser's self-deletion logic.
137 base::ThreadTaskRunnerHandle task_runner_handle_; 153 // TODO(bauerb): Replace this with a TestSimpleTaskRunner once
154 // TestingJsonParser no longer requires having a MessageLoop.
155 base::MessageLoop message_loop_;
138 156
139 net::TestURLFetcherFactory factory_; 157 net::TestURLFetcherFactory factory_;
140 158
159 base::ScopedTempDir temp_dir_;
Wez 2016/03/02 02:26:45 nit: Doesn't look like this is used any more?
Kevin M 2016/03/02 18:05:34 Done.
160
161 // Path to the PEM-encoded certificate chain.
162 base::FilePath cert_path_;
163
164 // Payload of PEM certificate chain at |cert_path_|.
165 std::string cert_pem_;
166
167 // X509 certificate decoded from |cert_path_|.
168 scoped_refptr<net::X509Certificate> cert_;
169
141 AssignmentSource source_; 170 AssignmentSource source_;
171
172 safe_json::TestingJsonParser::ScopedFactoryOverride json_parsing_factory_;
Wez 2016/03/02 02:26:45 nit: One-line comment to explain this?
Kevin M 2016/03/02 18:05:34 Done.
142 }; 173 };
143 174
175 Assignment AssignmentSourceTest::BuildValidAssignment() {
176 Assignment assignment;
177 assignment.transport_protocol = Assignment::TransportProtocol::SSL;
178 assignment.engine_endpoint =
179 net::IPEndPoint(kTestIPAddressStringAddress, kTestPort);
180 assignment.client_token = "SecretT0kenz";
181 assignment.cert = cert_;
182 return assignment;
183 }
184
144 TEST_F(AssignmentSourceTest, TestTCPAlternateEndpointSuccess) { 185 TEST_F(AssignmentSourceTest, TestTCPAlternateEndpointSuccess) {
145 Assignment assignment; 186 Assignment assignment;
146 assignment.transport_protocol = Assignment::TransportProtocol::TCP; 187 assignment.transport_protocol = Assignment::TransportProtocol::TCP;
147 assignment.ip_endpoint = BuildIPEndPoint("100.150.200.250", 500); 188 assignment.engine_endpoint =
189 net::IPEndPoint(kTestIPAddressStringAddress, kTestPort);
148 assignment.client_token = kDummyClientToken; 190 assignment.client_token = kDummyClientToken;
191 assignment.cert = scoped_refptr<net::X509Certificate>(nullptr);
149 192
150 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 193 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
151 switches::kBlimpletEndpoint, "tcp:100.150.200.250:500"); 194 switches::kEngineIP, kTestIPAddressString);
195 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
196 switches::kEnginePort, std::to_string(kTestPort));
197 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
198 switches::kEngineTransport, kTCPTransportName);
152 199
153 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK, 200 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
154 AssignmentEquals(assignment))) 201 AssignmentEquals(assignment)))
155 .Times(1); 202 .Times(1);
156 203
157 GetAlternateAssignment(); 204 GetAlternateAssignment();
158 } 205 }
159 206
160 TEST_F(AssignmentSourceTest, TestSSLAlternateEndpointSuccess) { 207 TEST_F(AssignmentSourceTest, TestSSLAlternateEndpointSuccess) {
161 Assignment assignment; 208 Assignment assignment;
162 assignment.transport_protocol = Assignment::TransportProtocol::SSL; 209 assignment.transport_protocol = Assignment::TransportProtocol::SSL;
163 assignment.ip_endpoint = BuildIPEndPoint("100.150.200.250", 500); 210 assignment.engine_endpoint =
211 net::IPEndPoint(kTestIPAddressStringAddress, kTestPort);
164 assignment.client_token = kDummyClientToken; 212 assignment.client_token = kDummyClientToken;
213 assignment.cert = cert_;
165 214
166 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 215 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
167 switches::kBlimpletEndpoint, "ssl:100.150.200.250:500"); 216 switches::kEngineIP, kTestIPAddressString);
217 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
218 switches::kEnginePort, std::to_string(kTestPort));
219 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
220 switches::kEngineTransport, kSSLTransportName);
221 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
222 switches::kEngineCertPath, cert_path_.value());
168 223
169 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK, 224 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
170 AssignmentEquals(assignment))) 225 AssignmentEquals(assignment)))
171 .Times(1);
172
173 GetAlternateAssignment();
174 }
175
176 TEST_F(AssignmentSourceTest, TestQUICAlternateEndpointSuccess) {
177 Assignment assignment;
178 assignment.transport_protocol = Assignment::TransportProtocol::QUIC;
179 assignment.ip_endpoint = BuildIPEndPoint("100.150.200.250", 500);
180 assignment.client_token = kDummyClientToken;
181
182 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
183 switches::kBlimpletEndpoint, "quic:100.150.200.250:500");
184
185 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
186 AssignmentEquals(assignment)))
187 .Times(1); 226 .Times(1);
188 227
189 GetAlternateAssignment(); 228 GetAlternateAssignment();
190 } 229 }
191 230
192 TEST_F(AssignmentSourceTest, TestSuccess) { 231 TEST_F(AssignmentSourceTest, TestSuccess) {
193 Assignment assignment = BuildValidAssignment(); 232 Assignment assignment = BuildValidAssignment();
194 233
195 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK, 234 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
196 AssignmentEquals(assignment))) 235 AssignmentEquals(assignment)))
197 .Times(1); 236 .Times(1);
198 237
199 GetNetworkAssignmentAndWaitForResponse( 238 GetNetworkAssignmentAndWaitForResponse(
200 net::HTTP_OK, net::Error::OK, BuildResponseFromAssignment(assignment), 239 net::HTTP_OK, net::Error::OK,
201 "UserAuthT0kenz", kEngineVersion); 240 BuildResponseFromAssignment(assignment, cert_pem_), "UserAuthT0kenz",
Wez 2016/03/02 02:26:45 nit: Move this token value into a constant?
Kevin M 2016/03/02 18:05:34 Done.
202 } 241 kEngineVersion);
203
204 TEST_F(AssignmentSourceTest, TestSecondRequestInterruptsFirst) {
205 InSequence sequence;
206 Assignment assignment = BuildValidAssignment();
207
208 source_.GetAssignment("",
209 base::Bind(&AssignmentSourceTest::AssignmentResponse,
210 base::Unretained(this)));
211
212 EXPECT_CALL(*this, AssignmentResponse(
213 AssignmentSource::Result::RESULT_SERVER_INTERRUPTED,
214 AssignmentEquals(Assignment())))
215 .Times(1)
216 .RetiresOnSaturation();
217
218 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
219 AssignmentEquals(assignment)))
220 .Times(1)
221 .RetiresOnSaturation();
222
223 GetNetworkAssignmentAndWaitForResponse(
224 net::HTTP_OK, net::Error::OK, BuildResponseFromAssignment(assignment),
225 "UserAuthT0kenz", kEngineVersion);
226 } 242 }
227 243
228 TEST_F(AssignmentSourceTest, TestValidAfterError) { 244 TEST_F(AssignmentSourceTest, TestValidAfterError) {
229 InSequence sequence; 245 InSequence sequence;
230 Assignment assignment = BuildValidAssignment(); 246 Assignment assignment = BuildValidAssignment();
231 247
232 EXPECT_CALL(*this, AssignmentResponse( 248 EXPECT_CALL(*this, AssignmentResponse(
233 AssignmentSource::Result::RESULT_NETWORK_FAILURE, _)) 249 AssignmentSource::Result::RESULT_NETWORK_FAILURE, _))
234 .Times(1) 250 .Times(1)
235 .RetiresOnSaturation(); 251 .RetiresOnSaturation();
236 252
237 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK, 253 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
238 AssignmentEquals(assignment))) 254 AssignmentEquals(assignment)))
239 .Times(1) 255 .Times(1)
240 .RetiresOnSaturation(); 256 .RetiresOnSaturation();
241 257
242 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, 258 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK,
243 net::Error::ERR_INSUFFICIENT_RESOURCES, 259 net::Error::ERR_INSUFFICIENT_RESOURCES,
244 "", "UserAuthT0kenz", kEngineVersion); 260 "", "UserAuthT0kenz", kEngineVersion);
245 261
246 GetNetworkAssignmentAndWaitForResponse( 262 GetNetworkAssignmentAndWaitForResponse(
247 net::HTTP_OK, net::Error::OK, BuildResponseFromAssignment(assignment), 263 net::HTTP_OK, net::Error::OK,
248 "UserAuthT0kenz", kEngineVersion); 264 BuildResponseFromAssignment(assignment, cert_pem_), "UserAuthT0kenz",
265 kEngineVersion);
249 } 266 }
250 267
251 TEST_F(AssignmentSourceTest, TestNetworkFailure) { 268 TEST_F(AssignmentSourceTest, TestNetworkFailure) {
252 EXPECT_CALL(*this, AssignmentResponse( 269 EXPECT_CALL(*this, AssignmentResponse(
253 AssignmentSource::Result::RESULT_NETWORK_FAILURE, _)); 270 AssignmentSource::Result::RESULT_NETWORK_FAILURE, _));
254 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, 271 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK,
255 net::Error::ERR_INSUFFICIENT_RESOURCES, 272 net::Error::ERR_INSUFFICIENT_RESOURCES,
256 "", "UserAuthT0kenz", kEngineVersion); 273 "", "UserAuthT0kenz", kEngineVersion);
257 } 274 }
258 275
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 AssignmentSource::Result::RESULT_BAD_RESPONSE, _)); 316 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
300 GetNetworkAssignmentAndWaitForResponse(net::HTTP_NOT_IMPLEMENTED, 317 GetNetworkAssignmentAndWaitForResponse(net::HTTP_NOT_IMPLEMENTED,
301 net::Error::OK, "", "UserAuthT0kenz", 318 net::Error::OK, "", "UserAuthT0kenz",
302 kEngineVersion); 319 kEngineVersion);
303 } 320 }
304 321
305 TEST_F(AssignmentSourceTest, TestInvalidJsonResponse) { 322 TEST_F(AssignmentSourceTest, TestInvalidJsonResponse) {
306 Assignment assignment = BuildValidAssignment(); 323 Assignment assignment = BuildValidAssignment();
307 324
308 // Remove half the response. 325 // Remove half the response.
309 std::string response = BuildResponseFromAssignment(assignment); 326 std::string response = BuildResponseFromAssignment(assignment, cert_pem_);
310 response = response.substr(response.size() / 2); 327 response = response.substr(response.size() / 2);
311 328
312 EXPECT_CALL(*this, AssignmentResponse( 329 EXPECT_CALL(*this, AssignmentResponse(
313 AssignmentSource::Result::RESULT_BAD_RESPONSE, _)); 330 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
314 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response, 331 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response,
315 "UserAuthT0kenz", kEngineVersion); 332 "UserAuthT0kenz", kEngineVersion);
316 } 333 }
317 334
318 TEST_F(AssignmentSourceTest, TestMissingResponsePort) { 335 TEST_F(AssignmentSourceTest, TestMissingResponsePort) {
319 // Purposely do not add the 'port' field to the response. 336 // Purposely do not add the 'port' field to the response.
320 base::DictionaryValue dict; 337 base::DictionaryValue dict;
321 dict.SetString("clientToken", "SecretT0kenz"); 338 dict.SetString("clientToken", "SecretT0kenz");
322 dict.SetString("host", "happywhales"); 339 dict.SetString("host", "happywhales");
323 dict.SetString("certificateFingerprint", "WhaleWhaleWhale");
324 dict.SetString("certificate", "whaaaaaaaaaaaaale"); 340 dict.SetString("certificate", "whaaaaaaaaaaaaale");
325 341
326 std::string response; 342 std::string response;
327 base::JSONWriter::Write(dict, &response); 343 base::JSONWriter::Write(dict, &response);
328 344
329 EXPECT_CALL(*this, AssignmentResponse( 345 EXPECT_CALL(*this, AssignmentResponse(
330 AssignmentSource::Result::RESULT_BAD_RESPONSE, _)); 346 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
331 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response, 347 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response,
332 "UserAuthT0kenz", kEngineVersion); 348 "UserAuthT0kenz", kEngineVersion);
333 } 349 }
334 350
335 TEST_F(AssignmentSourceTest, TestInvalidIPAddress) { 351 TEST_F(AssignmentSourceTest, TestInvalidIPAddress) {
336 // Purposely add an invalid IP field to the response. 352 // Purposely add an invalid IP field to the response.
337 base::DictionaryValue dict; 353 base::DictionaryValue dict;
338 dict.SetString("clientToken", "SecretT0kenz"); 354 dict.SetString("clientToken", "SecretT0kenz");
339 dict.SetString("host", "happywhales"); 355 dict.SetString("host", "happywhales");
340 dict.SetInteger("port", 500); 356 dict.SetInteger("port", 500);
341 dict.SetString("certificateFingerprint", "WhaleWhaleWhale");
342 dict.SetString("certificate", "whaaaaaaaaaaaaale"); 357 dict.SetString("certificate", "whaaaaaaaaaaaaale");
343 358
344 std::string response; 359 std::string response;
345 base::JSONWriter::Write(dict, &response); 360 base::JSONWriter::Write(dict, &response);
346 361
347 EXPECT_CALL(*this, AssignmentResponse( 362 EXPECT_CALL(*this, AssignmentResponse(
348 AssignmentSource::Result::RESULT_BAD_RESPONSE, _)); 363 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
349 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response, 364 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response,
350 "UserAuthT0kenz", kEngineVersion); 365 "UserAuthT0kenz", kEngineVersion);
351 } 366 }
352 367
368 TEST_F(AssignmentSourceTest, TestMissingCert) {
369 base::DictionaryValue dict;
370 dict.SetString("clientToken", "SecretT0kenz");
371 dict.SetString("host", "127.0.0.1");
372 dict.SetInteger("port", 500);
Wez 2016/03/02 02:26:45 nit: You could just call BuildResponse...() and th
Kevin M 2016/03/02 18:05:34 Done.
373
374 std::string response;
375 base::JSONWriter::Write(dict, &response);
376
377 EXPECT_CALL(*this, AssignmentResponse(
378 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
379 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response,
380 "UserAuthT0kenz", kEngineVersion);
381 }
382
383 TEST_F(AssignmentSourceTest, TestInvalidCert) {
384 base::DictionaryValue dict;
385 dict.SetString("clientToken", "SecretT0kenz");
386 dict.SetString("host", "127.0.0.1");
387 dict.SetInteger("port", 500);
388 dict.SetString("certificate", "h4x0r c3r7");
389
390 std::string response;
391 base::JSONWriter::Write(dict, &response);
392
393 EXPECT_CALL(*this, AssignmentResponse(
394 AssignmentSource::Result::RESULT_INVALID_CERT, _));
395 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response,
396 "UserAuthT0kenz", kEngineVersion);
397 }
398
353 } // namespace 399 } // namespace
354 } // namespace client 400 } // namespace client
355 } // namespace blimp 401 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698