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

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: rsleevi feedback #40 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/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 kTestIPAddress[] = {127, 0, 0, 1};
39 const uint16_t kTestPort = 8086;
40 const char kTestIP[] = "127.0.0.1";
41 const char kTCP[] = "tcp";
42 const char kQUIC[] = "quic";
43 const char kSSL[] = "ssl";
44 const char kCertRelativePath[] =
45 "blimp/client/session/test_selfsigned_cert.pem";
46
26 MATCHER_P(AssignmentEquals, assignment, "") { 47 MATCHER_P(AssignmentEquals, assignment, "") {
27 return arg.transport_protocol == assignment.transport_protocol && 48 return arg.transport_protocol == assignment.transport_protocol &&
28 arg.ip_endpoint == assignment.ip_endpoint && 49 arg.ip_endpoint == assignment.ip_endpoint &&
29 arg.client_token == assignment.client_token && 50 arg.client_token == assignment.client_token &&
30 arg.certificate == assignment.certificate && 51 ((!assignment.cert && !arg.cert) ||
31 arg.certificate_fingerprint == assignment.certificate_fingerprint; 52 (arg.cert && assignment.cert &&
53 arg.cert->Equals(assignment.cert.get())));
32 } 54 }
33 55
34 net::IPEndPoint BuildIPEndPoint(const std::string& ip, int port) { 56 // Builds simulated JSON response from the Assigner service.
35 net::IPAddress ip_address; 57 // |assignment|: The Assignment to convert.
36 EXPECT_TRUE(ip_address.AssignFromIPLiteral(ip)); 58 // |expected_cert_str|: The PEM encoded certificate to include in the response.
37 59 std::string BuildResponseFromAssignment(const Assignment& assignment,
38 return net::IPEndPoint(ip_address, port); 60 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; 61 base::DictionaryValue dict;
53 dict.SetString("clientToken", assignment.client_token); 62 dict.SetString("clientToken", assignment.client_token);
54 dict.SetString("host", assignment.ip_endpoint.address().ToString()); 63 dict.SetString("host", assignment.ip_endpoint.address().ToString());
55 dict.SetInteger("port", assignment.ip_endpoint.port()); 64 dict.SetInteger("port", assignment.ip_endpoint.port());
56 dict.SetString("certificateFingerprint", assignment.certificate_fingerprint); 65 dict.SetString("certificate", expected_cert_str);
57 dict.SetString("certificate", assignment.certificate);
58 66
59 std::string json; 67 std::string json;
60 base::JSONWriter::Write(dict, &json); 68 base::JSONWriter::Write(dict, &json);
61 return json; 69 return json;
62 } 70 }
63 71
64 class AssignmentSourceTest : public testing::Test { 72 class AssignmentSourceTest : public testing::Test {
65 public: 73 public:
66 AssignmentSourceTest() 74 AssignmentSourceTest() : source_(message_loop_.task_runner()) {}
67 : task_runner_(new base::TestSimpleTaskRunner), 75
68 task_runner_handle_(task_runner_), 76 void SetUp() override {
69 source_(task_runner_, task_runner_) {} 77 base::FilePath src_root;
78 PathService::Get(base::DIR_SOURCE_ROOT, &src_root);
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]);
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();
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.
Bernhard Bauer 2016/02/26 16:26:30 Ooh... actually, I should probably modify TestingJ
Kevin M 2016/02/26 19:57:23 Done.
137 base::ThreadTaskRunnerHandle task_runner_handle_; 153 base::MessageLoop message_loop_;
138 154
139 net::TestURLFetcherFactory factory_; 155 net::TestURLFetcherFactory factory_;
140 156
157 base::ScopedTempDir temp_dir_;
158
159 // Path to the PEM-encoded certificate chain.
160 base::FilePath cert_path_;
161
162 // Payload of PEM certificate chain at |cert_path_|.
163 std::string cert_pem_;
164
165 // X509 certificate decoded from |cert_path_|.
166 scoped_refptr<net::X509Certificate> cert_;
167
141 AssignmentSource source_; 168 AssignmentSource source_;
169
170 safe_json::TestingJsonParser::ScopedFactoryOverride json_parsing_factory_;
142 }; 171 };
143 172
173 Assignment AssignmentSourceTest::BuildValidAssignment() {
174 Assignment assignment;
175 assignment.transport_protocol = Assignment::TransportProtocol::SSL;
176 assignment.ip_endpoint = net::IPEndPoint(kTestIPAddress, kTestPort);
177 assignment.client_token = "SecretT0kenz";
178 assignment.cert = cert_;
179 return assignment;
180 }
181
144 TEST_F(AssignmentSourceTest, TestTCPAlternateEndpointSuccess) { 182 TEST_F(AssignmentSourceTest, TestTCPAlternateEndpointSuccess) {
145 Assignment assignment; 183 Assignment assignment;
146 assignment.transport_protocol = Assignment::TransportProtocol::TCP; 184 assignment.transport_protocol = Assignment::TransportProtocol::TCP;
147 assignment.ip_endpoint = BuildIPEndPoint("100.150.200.250", 500); 185 assignment.ip_endpoint = net::IPEndPoint(kTestIPAddress, kTestPort);
148 assignment.client_token = kDummyClientToken; 186 assignment.client_token = kDummyClientToken;
187 assignment.cert = scoped_refptr<net::X509Certificate>(nullptr);
149 188
189 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kEngineIP,
190 kTestIP);
150 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 191 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
151 switches::kBlimpletEndpoint, "tcp:100.150.200.250:500"); 192 switches::kEnginePort, std::to_string(kTestPort));
193 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
194 switches::kEngineTransport, kTCP);
152 195
153 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK, 196 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
154 AssignmentEquals(assignment))) 197 AssignmentEquals(assignment)))
155 .Times(1); 198 .Times(1);
156 199
157 GetAlternateAssignment(); 200 GetAlternateAssignment();
158 } 201 }
159 202
160 TEST_F(AssignmentSourceTest, TestSSLAlternateEndpointSuccess) { 203 TEST_F(AssignmentSourceTest, TestSSLAlternateEndpointSuccess) {
161 Assignment assignment; 204 Assignment assignment;
162 assignment.transport_protocol = Assignment::TransportProtocol::SSL; 205 assignment.transport_protocol = Assignment::TransportProtocol::SSL;
163 assignment.ip_endpoint = BuildIPEndPoint("100.150.200.250", 500); 206 assignment.ip_endpoint = net::IPEndPoint(kTestIPAddress, kTestPort);
164 assignment.client_token = kDummyClientToken; 207 assignment.client_token = kDummyClientToken;
208 assignment.cert = cert_;
165 209
210 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kEngineIP,
211 kTestIP);
166 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 212 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
167 switches::kBlimpletEndpoint, "ssl:100.150.200.250:500"); 213 switches::kEnginePort, std::to_string(kTestPort));
214 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
215 switches::kEngineTransport, kSSL);
216 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
217 switches::kEngineCertPath, cert_path_.value());
168 218
169 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK, 219 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
170 AssignmentEquals(assignment))) 220 AssignmentEquals(assignment)))
171 .Times(1); 221 .Times(1);
172 222
173 GetAlternateAssignment(); 223 GetAlternateAssignment();
174 } 224 }
175 225
176 TEST_F(AssignmentSourceTest, TestQUICAlternateEndpointSuccess) { 226 TEST_F(AssignmentSourceTest, TestQUICAlternateEndpointSuccess) {
177 Assignment assignment; 227 Assignment assignment;
178 assignment.transport_protocol = Assignment::TransportProtocol::QUIC; 228 assignment.transport_protocol = Assignment::TransportProtocol::QUIC;
179 assignment.ip_endpoint = BuildIPEndPoint("100.150.200.250", 500); 229 assignment.ip_endpoint = net::IPEndPoint(kTestIPAddress, kTestPort);
180 assignment.client_token = kDummyClientToken; 230 assignment.client_token = kDummyClientToken;
231 assignment.cert = cert_;
181 232
233 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kEngineIP,
234 kTestIP);
182 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 235 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
183 switches::kBlimpletEndpoint, "quic:100.150.200.250:500"); 236 switches::kEnginePort, std::to_string(kTestPort));
237 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
238 switches::kEngineTransport, kQUIC);
239 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
240 switches::kEngineCertPath, cert_path_.value());
184 241
185 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK, 242 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
186 AssignmentEquals(assignment))) 243 AssignmentEquals(assignment)))
187 .Times(1); 244 .Times(1);
188 245
189 GetAlternateAssignment(); 246 GetAlternateAssignment();
190 } 247 }
191 248
192 TEST_F(AssignmentSourceTest, TestSuccess) { 249 TEST_F(AssignmentSourceTest, TestSuccess) {
193 Assignment assignment = BuildValidAssignment(); 250 Assignment assignment = BuildValidAssignment();
194 251
195 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK, 252 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
196 AssignmentEquals(assignment))) 253 AssignmentEquals(assignment)))
197 .Times(1); 254 .Times(1);
198 255
199 GetNetworkAssignmentAndWaitForResponse( 256 GetNetworkAssignmentAndWaitForResponse(
200 net::HTTP_OK, net::Error::OK, BuildResponseFromAssignment(assignment), 257 net::HTTP_OK, net::Error::OK,
201 "UserAuthT0kenz", kEngineVersion); 258 BuildResponseFromAssignment(assignment, cert_pem_), "UserAuthT0kenz",
259 kEngineVersion);
202 } 260 }
203 261
204 TEST_F(AssignmentSourceTest, TestSecondRequestInterruptsFirst) { 262 TEST_F(AssignmentSourceTest, TestSecondRequestInterruptsFirst) {
205 InSequence sequence; 263 InSequence sequence;
206 Assignment assignment = BuildValidAssignment(); 264 Assignment assignment = BuildValidAssignment();
207 265
208 source_.GetAssignment("", 266 source_.GetAssignment("",
209 base::Bind(&AssignmentSourceTest::AssignmentResponse, 267 base::Bind(&AssignmentSourceTest::AssignmentResponse,
210 base::Unretained(this))); 268 base::Unretained(this)));
211 269
212 EXPECT_CALL(*this, AssignmentResponse( 270 EXPECT_CALL(*this, AssignmentResponse(
213 AssignmentSource::Result::RESULT_SERVER_INTERRUPTED, 271 AssignmentSource::Result::RESULT_SERVER_INTERRUPTED,
214 AssignmentEquals(Assignment()))) 272 AssignmentEquals(Assignment())))
215 .Times(1) 273 .Times(1)
216 .RetiresOnSaturation(); 274 .RetiresOnSaturation();
217 275
218 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK, 276 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
219 AssignmentEquals(assignment))) 277 AssignmentEquals(assignment)))
220 .Times(1) 278 .Times(1)
221 .RetiresOnSaturation(); 279 .RetiresOnSaturation();
222 280
223 GetNetworkAssignmentAndWaitForResponse( 281 GetNetworkAssignmentAndWaitForResponse(
224 net::HTTP_OK, net::Error::OK, BuildResponseFromAssignment(assignment), 282 net::HTTP_OK, net::Error::OK,
225 "UserAuthT0kenz", kEngineVersion); 283 BuildResponseFromAssignment(assignment, cert_pem_), "UserAuthT0kenz",
284 kEngineVersion);
226 } 285 }
227 286
228 TEST_F(AssignmentSourceTest, TestValidAfterError) { 287 TEST_F(AssignmentSourceTest, TestValidAfterError) {
229 InSequence sequence; 288 InSequence sequence;
230 Assignment assignment = BuildValidAssignment(); 289 Assignment assignment = BuildValidAssignment();
231 290
232 EXPECT_CALL(*this, AssignmentResponse( 291 EXPECT_CALL(*this, AssignmentResponse(
233 AssignmentSource::Result::RESULT_NETWORK_FAILURE, _)) 292 AssignmentSource::Result::RESULT_NETWORK_FAILURE, _))
234 .Times(1) 293 .Times(1)
235 .RetiresOnSaturation(); 294 .RetiresOnSaturation();
236 295
237 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK, 296 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
238 AssignmentEquals(assignment))) 297 AssignmentEquals(assignment)))
239 .Times(1) 298 .Times(1)
240 .RetiresOnSaturation(); 299 .RetiresOnSaturation();
241 300
242 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, 301 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK,
243 net::Error::ERR_INSUFFICIENT_RESOURCES, 302 net::Error::ERR_INSUFFICIENT_RESOURCES,
244 "", "UserAuthT0kenz", kEngineVersion); 303 "", "UserAuthT0kenz", kEngineVersion);
245 304
246 GetNetworkAssignmentAndWaitForResponse( 305 GetNetworkAssignmentAndWaitForResponse(
247 net::HTTP_OK, net::Error::OK, BuildResponseFromAssignment(assignment), 306 net::HTTP_OK, net::Error::OK,
248 "UserAuthT0kenz", kEngineVersion); 307 BuildResponseFromAssignment(assignment, cert_pem_), "UserAuthT0kenz",
308 kEngineVersion);
249 } 309 }
250 310
251 TEST_F(AssignmentSourceTest, TestNetworkFailure) { 311 TEST_F(AssignmentSourceTest, TestNetworkFailure) {
252 EXPECT_CALL(*this, AssignmentResponse( 312 EXPECT_CALL(*this, AssignmentResponse(
253 AssignmentSource::Result::RESULT_NETWORK_FAILURE, _)); 313 AssignmentSource::Result::RESULT_NETWORK_FAILURE, _));
254 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, 314 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK,
255 net::Error::ERR_INSUFFICIENT_RESOURCES, 315 net::Error::ERR_INSUFFICIENT_RESOURCES,
256 "", "UserAuthT0kenz", kEngineVersion); 316 "", "UserAuthT0kenz", kEngineVersion);
257 } 317 }
258 318
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 AssignmentSource::Result::RESULT_BAD_RESPONSE, _)); 359 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
300 GetNetworkAssignmentAndWaitForResponse(net::HTTP_NOT_IMPLEMENTED, 360 GetNetworkAssignmentAndWaitForResponse(net::HTTP_NOT_IMPLEMENTED,
301 net::Error::OK, "", "UserAuthT0kenz", 361 net::Error::OK, "", "UserAuthT0kenz",
302 kEngineVersion); 362 kEngineVersion);
303 } 363 }
304 364
305 TEST_F(AssignmentSourceTest, TestInvalidJsonResponse) { 365 TEST_F(AssignmentSourceTest, TestInvalidJsonResponse) {
306 Assignment assignment = BuildValidAssignment(); 366 Assignment assignment = BuildValidAssignment();
307 367
308 // Remove half the response. 368 // Remove half the response.
309 std::string response = BuildResponseFromAssignment(assignment); 369 std::string response = BuildResponseFromAssignment(assignment, cert_pem_);
310 response = response.substr(response.size() / 2); 370 response = response.substr(response.size() / 2);
311 371
312 EXPECT_CALL(*this, AssignmentResponse( 372 EXPECT_CALL(*this, AssignmentResponse(
313 AssignmentSource::Result::RESULT_BAD_RESPONSE, _)); 373 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
314 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response, 374 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response,
315 "UserAuthT0kenz", kEngineVersion); 375 "UserAuthT0kenz", kEngineVersion);
316 } 376 }
317 377
318 TEST_F(AssignmentSourceTest, TestMissingResponsePort) { 378 TEST_F(AssignmentSourceTest, TestMissingResponsePort) {
319 // Purposely do not add the 'port' field to the response. 379 // Purposely do not add the 'port' field to the response.
320 base::DictionaryValue dict; 380 base::DictionaryValue dict;
321 dict.SetString("clientToken", "SecretT0kenz"); 381 dict.SetString("clientToken", "SecretT0kenz");
322 dict.SetString("host", "happywhales"); 382 dict.SetString("host", "happywhales");
323 dict.SetString("certificateFingerprint", "WhaleWhaleWhale");
324 dict.SetString("certificate", "whaaaaaaaaaaaaale"); 383 dict.SetString("certificate", "whaaaaaaaaaaaaale");
325 384
326 std::string response; 385 std::string response;
327 base::JSONWriter::Write(dict, &response); 386 base::JSONWriter::Write(dict, &response);
328 387
329 EXPECT_CALL(*this, AssignmentResponse( 388 EXPECT_CALL(*this, AssignmentResponse(
330 AssignmentSource::Result::RESULT_BAD_RESPONSE, _)); 389 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
331 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response, 390 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response,
332 "UserAuthT0kenz", kEngineVersion); 391 "UserAuthT0kenz", kEngineVersion);
333 } 392 }
334 393
335 TEST_F(AssignmentSourceTest, TestInvalidIPAddress) { 394 TEST_F(AssignmentSourceTest, TestInvalidIPAddress) {
336 // Purposely add an invalid IP field to the response. 395 // Purposely add an invalid IP field to the response.
337 base::DictionaryValue dict; 396 base::DictionaryValue dict;
338 dict.SetString("clientToken", "SecretT0kenz"); 397 dict.SetString("clientToken", "SecretT0kenz");
339 dict.SetString("host", "happywhales"); 398 dict.SetString("host", "happywhales");
340 dict.SetInteger("port", 500); 399 dict.SetInteger("port", 500);
341 dict.SetString("certificateFingerprint", "WhaleWhaleWhale");
342 dict.SetString("certificate", "whaaaaaaaaaaaaale"); 400 dict.SetString("certificate", "whaaaaaaaaaaaaale");
343 401
344 std::string response; 402 std::string response;
345 base::JSONWriter::Write(dict, &response); 403 base::JSONWriter::Write(dict, &response);
346 404
347 EXPECT_CALL(*this, AssignmentResponse( 405 EXPECT_CALL(*this, AssignmentResponse(
348 AssignmentSource::Result::RESULT_BAD_RESPONSE, _)); 406 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
349 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response, 407 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response,
350 "UserAuthT0kenz", kEngineVersion); 408 "UserAuthT0kenz", kEngineVersion);
351 } 409 }
352 410
411 TEST_F(AssignmentSourceTest, TestMissingCert) {
412 base::DictionaryValue dict;
413 dict.SetString("clientToken", "SecretT0kenz");
414 dict.SetString("host", "127.0.0.1");
415 dict.SetInteger("port", 500);
416
417 std::string response;
418 base::JSONWriter::Write(dict, &response);
419
420 EXPECT_CALL(*this, AssignmentResponse(
421 AssignmentSource::Result::RESULT_BAD_RESPONSE, _));
422 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response,
423 "UserAuthT0kenz", kEngineVersion);
424 }
425
426 TEST_F(AssignmentSourceTest, TestInvalidCert) {
427 base::DictionaryValue dict;
428 dict.SetString("clientToken", "SecretT0kenz");
429 dict.SetString("host", "127.0.0.1");
430 dict.SetInteger("port", 500);
431 dict.SetString("certificate", "h4x0r c3r7");
432
433 std::string response;
434 base::JSONWriter::Write(dict, &response);
435
436 EXPECT_CALL(*this, AssignmentResponse(
437 AssignmentSource::Result::RESULT_INVALID_CERT, _));
438 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, response,
439 "UserAuthT0kenz", kEngineVersion);
440 }
441
353 } // namespace 442 } // namespace
354 } // namespace client 443 } // namespace client
355 } // namespace blimp 444 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698