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

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

Powered by Google App Engine
This is Rietveld 408576698