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

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

Issue 1958033003: Allows client to access auth token from command line specified file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/test/test_simple_task_runner.h" 15 #include "base/test/test_simple_task_runner.h"
16 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "blimp/client/app/blimp_client_switches.h" 18 #include "blimp/client/app/blimp_client_switches.h"
19 #include "blimp/common/fake_commandline.h"
20 #include "blimp/common/get_client_token.h"
19 #include "blimp/common/protocol_version.h" 21 #include "blimp/common/protocol_version.h"
20 #include "components/safe_json/testing_json_parser.h" 22 #include "components/safe_json/testing_json_parser.h"
21 #include "net/base/test_data_directory.h" 23 #include "net/base/test_data_directory.h"
22 #include "net/url_request/test_url_fetcher_factory.h" 24 #include "net/url_request/test_url_fetcher_factory.h"
23 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
25 #include "url/gurl.h" 27 #include "url/gurl.h"
26 28
27 using testing::_; 29 using testing::_;
28 using testing::DoAll; 30 using testing::DoAll;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 ASSERT_FALSE(src_root.empty()); 77 ASSERT_FALSE(src_root.empty());
76 cert_path_ = src_root.Append(kCertRelativePath); 78 cert_path_ = src_root.Append(kCertRelativePath);
77 ASSERT_TRUE(base::ReadFileToString(cert_path_, &cert_pem_)); 79 ASSERT_TRUE(base::ReadFileToString(cert_path_, &cert_pem_));
78 net::CertificateList cert_list = 80 net::CertificateList cert_list =
79 net::X509Certificate::CreateCertificateListFromBytes( 81 net::X509Certificate::CreateCertificateListFromBytes(
80 cert_pem_.data(), cert_pem_.size(), 82 cert_pem_.data(), cert_pem_.size(),
81 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE); 83 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
82 ASSERT_FALSE(cert_list.empty()); 84 ASSERT_FALSE(cert_list.empty());
83 cert_ = std::move(cert_list[0]); 85 cert_ = std::move(cert_list[0]);
84 ASSERT_TRUE(cert_); 86 ASSERT_TRUE(cert_);
87 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
Kevin M 2016/05/10 18:06:34 This variable doesn't exist? You can compile the
CJ 2016/05/10 20:58:06 It exists in fake_commandline.h. Too obscured away
Kevin M 2016/05/11 00:39:56 Ah, I thought that test_dir_ was a private class f
CJ 2016/05/11 21:49:30 It got removed because it is unneeded in the prefe
88 CreateFileForSwitch(engine::kClientTokenPath, kTestClientToken);
85 } 89 }
86 90
87 // This expects the AssignmentSource::GetAssignment to return a custom 91 // This expects the AssignmentSource::GetAssignment to return a custom
88 // endpoint without having to hit the network. This will typically be used 92 // endpoint without having to hit the network. This will typically be used
89 // for testing that specifying an assignment via the command line works as 93 // for testing that specifying an assignment via the command line works as
90 // expected. 94 // expected.
91 void GetAlternateAssignment() { 95 void GetAlternateAssignment() {
92 source_.GetAssignment("", 96 source_.GetAssignment("",
93 base::Bind(&AssignmentSourceTest::AssignmentResponse, 97 base::Bind(&AssignmentSourceTest::AssignmentResponse,
94 base::Unretained(this))); 98 base::Unretained(this)));
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 AssignmentSourceTest::BuildAssignerResponse() { 193 AssignmentSourceTest::BuildAssignerResponse() {
190 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 194 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
191 dict->SetString("clientToken", kTestClientToken); 195 dict->SetString("clientToken", kTestClientToken);
192 dict->SetString("host", kTestIpAddressString); 196 dict->SetString("host", kTestIpAddressString);
193 dict->SetInteger("port", kTestPort); 197 dict->SetInteger("port", kTestPort);
194 dict->SetString("certificate", cert_pem_); 198 dict->SetString("certificate", cert_pem_);
195 return dict; 199 return dict;
196 } 200 }
197 201
198 TEST_F(AssignmentSourceTest, TestTCPAlternateEndpointSuccess) { 202 TEST_F(AssignmentSourceTest, TestTCPAlternateEndpointSuccess) {
203 auto cmd_line = CreateCommandLine(all_filepath_switches_);
Kevin M 2016/05/10 18:06:34 We should be consistent with how we're manipulatin
CJ 2016/05/10 20:58:06 Is this similar to what is done in assignment_sour
Kevin M 2016/05/11 00:39:56 Check out line 210 of this patch, which mutates th
CJ 2016/05/11 21:49:30 Done.
199 Assignment assignment; 204 Assignment assignment;
200 assignment.transport_protocol = Assignment::TransportProtocol::TCP; 205 assignment.transport_protocol = Assignment::TransportProtocol::TCP;
201 assignment.engine_endpoint = net::IPEndPoint(kTestIpAddress, kTestPort); 206 assignment.engine_endpoint = net::IPEndPoint(kTestIpAddress, kTestPort);
202 assignment.client_token = kDummyClientToken; 207 assignment.client_token = GetClientToken(cmd_line);
Kevin M 2016/05/10 18:06:34 Set the expectations directly here; otherwise we c
CJ 2016/05/10 20:58:06 I'm not sure what you mean by this. What do you me
Kevin M 2016/05/11 00:39:56 In this patch, we're testing GetClientToken() by i
CJ 2016/05/11 21:49:30 So, would adding an assert like so work? Or are we
203 assignment.cert = scoped_refptr<net::X509Certificate>(nullptr); 208 assignment.cert = scoped_refptr<net::X509Certificate>(nullptr);
204 209
205 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 210 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
206 switches::kEngineIP, kTestIpAddressString); 211 switches::kEngineIP, kTestIpAddressString);
207 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 212 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
208 switches::kEnginePort, std::to_string(kTestPort)); 213 switches::kEnginePort, std::to_string(kTestPort));
209 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 214 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
210 switches::kEngineTransport, kTcpTransportName); 215 switches::kEngineTransport, kTcpTransportName);
211 216
212 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK, 217 EXPECT_CALL(*this, AssignmentResponse(AssignmentSource::Result::RESULT_OK,
213 AssignmentEquals(assignment))) 218 AssignmentEquals(assignment)))
214 .Times(1); 219 .Times(1);
215 220
216 GetAlternateAssignment(); 221 GetAlternateAssignment();
217 } 222 }
218 223
219 TEST_F(AssignmentSourceTest, TestSSLAlternateEndpointSuccess) { 224 TEST_F(AssignmentSourceTest, TestSSLAlternateEndpointSuccess) {
225 auto cmd_line = CreateCommandLine(all_filepath_switches_);
220 Assignment assignment; 226 Assignment assignment;
221 assignment.transport_protocol = Assignment::TransportProtocol::SSL; 227 assignment.transport_protocol = Assignment::TransportProtocol::SSL;
222 assignment.engine_endpoint = net::IPEndPoint(kTestIpAddress, kTestPort); 228 assignment.engine_endpoint = net::IPEndPoint(kTestIpAddress, kTestPort);
223 assignment.client_token = kDummyClientToken; 229 assignment.client_token = GetClientToken(cmd_line);
224 assignment.cert = cert_; 230 assignment.cert = cert_;
225 231
226 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 232 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
227 switches::kEngineIP, kTestIpAddressString); 233 switches::kEngineIP, kTestIpAddressString);
228 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 234 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
229 switches::kEnginePort, std::to_string(kTestPort)); 235 switches::kEnginePort, std::to_string(kTestPort));
230 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 236 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
231 switches::kEngineTransport, kSslTransportName); 237 switches::kEngineTransport, kSslTransportName);
232 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 238 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
233 switches::kEngineCertPath, cert_path_.value()); 239 switches::kEngineCertPath, cert_path_.value());
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 EXPECT_CALL(*this, AssignmentResponse( 384 EXPECT_CALL(*this, AssignmentResponse(
379 AssignmentSource::Result::RESULT_INVALID_CERT, _)); 385 AssignmentSource::Result::RESULT_INVALID_CERT, _));
380 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, 386 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK,
381 ValueToString(*response), 387 ValueToString(*response),
382 kTestAuthToken, kEngineVersion); 388 kTestAuthToken, kEngineVersion);
383 } 389 }
384 390
385 } // namespace 391 } // namespace
386 } // namespace client 392 } // namespace client
387 } // namespace blimp 393 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698