| OLD | NEW |
| 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/core/session/assignment_source.h" | 5 #include "blimp/client/core/session/assignment_source.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 const char kSslTransportName[] = "ssl"; | 48 const char kSslTransportName[] = "ssl"; |
| 49 const char kCertRelativePath[] = | 49 const char kCertRelativePath[] = |
| 50 "blimp/client/core/session/test_selfsigned_cert.pem"; | 50 "blimp/client/core/session/test_selfsigned_cert.pem"; |
| 51 const char kTestClientAuthToken[] = "secrett0ken"; | 51 const char kTestClientAuthToken[] = "secrett0ken"; |
| 52 const char kTestAuthToken[] = "UserAuthT0kenz"; | 52 const char kTestAuthToken[] = "UserAuthT0kenz"; |
| 53 const char kAssignerUrl[] = "http://www.assigner.test/"; | 53 const char kAssignerUrl[] = "http://www.assigner.test/"; |
| 54 const char kTestClientAuthTokenPath[] = "blimp/test/data/test_client_token"; | 54 const char kTestClientAuthTokenPath[] = "blimp/test/data/test_client_token"; |
| 55 | 55 |
| 56 MATCHER_P(AssignmentEquals, assignment, "") { | 56 MATCHER_P(AssignmentEquals, assignment, "") { |
| 57 return arg.transport_protocol == assignment.transport_protocol && | 57 return arg.transport_protocol == assignment.transport_protocol && |
| 58 arg.engine_endpoint == assignment.engine_endpoint && | 58 arg.assignment_options.engine_endpoint == |
| 59 assignment.assignment_options.engine_endpoint && |
| 59 arg.client_auth_token == assignment.client_auth_token && | 60 arg.client_auth_token == assignment.client_auth_token && |
| 60 ((!assignment.cert && !arg.cert) || | 61 ((!assignment.cert && !arg.cert) || |
| 61 (arg.cert && assignment.cert && | 62 (arg.cert && assignment.cert && |
| 62 arg.cert->Equals(assignment.cert.get()))); | 63 arg.cert->Equals(assignment.cert.get()))); |
| 63 } | 64 } |
| 64 | 65 |
| 65 // Converts |value| to a JSON string. | 66 // Converts |value| to a JSON string. |
| 66 std::string ValueToString(const base::Value& value) { | 67 std::string ValueToString(const base::Value& value) { |
| 67 std::string json; | 68 std::string json; |
| 68 base::JSONWriter::Write(value, &json); | 69 base::JSONWriter::Write(value, &json); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 AssignmentSource source_; | 185 AssignmentSource source_; |
| 185 | 186 |
| 186 // Allows safe_json to parse JSON in-process, instead of depending on a | 187 // Allows safe_json to parse JSON in-process, instead of depending on a |
| 187 // utility proces. | 188 // utility proces. |
| 188 safe_json::TestingJsonParser::ScopedFactoryOverride json_parsing_factory_; | 189 safe_json::TestingJsonParser::ScopedFactoryOverride json_parsing_factory_; |
| 189 }; | 190 }; |
| 190 | 191 |
| 191 Assignment AssignmentSourceTest::BuildSslAssignment() { | 192 Assignment AssignmentSourceTest::BuildSslAssignment() { |
| 192 Assignment assignment; | 193 Assignment assignment; |
| 193 assignment.transport_protocol = Assignment::TransportProtocol::SSL; | 194 assignment.transport_protocol = Assignment::TransportProtocol::SSL; |
| 194 assignment.engine_endpoint = net::IPEndPoint(kTestIpAddress, kTestPort); | 195 assignment.assignment_options.engine_endpoint = |
| 196 net::IPEndPoint(kTestIpAddress, kTestPort); |
| 195 assignment.client_auth_token = kTestClientAuthToken; | 197 assignment.client_auth_token = kTestClientAuthToken; |
| 196 assignment.cert = cert_; | 198 assignment.cert = cert_; |
| 197 return assignment; | 199 return assignment; |
| 198 } | 200 } |
| 199 | 201 |
| 200 std::unique_ptr<base::DictionaryValue> | 202 std::unique_ptr<base::DictionaryValue> |
| 201 AssignmentSourceTest::BuildAssignerResponse() { | 203 AssignmentSourceTest::BuildAssignerResponse() { |
| 202 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 204 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 203 dict->SetString("clientToken", kTestClientAuthToken); | 205 dict->SetString("clientToken", kTestClientAuthToken); |
| 204 dict->SetString("host", kTestIpAddressString); | 206 dict->SetString("host", kTestIpAddressString); |
| 205 dict->SetInteger("port", kTestPort); | 207 dict->SetInteger("port", kTestPort); |
| 206 dict->SetString("certificate", cert_pem_); | 208 dict->SetString("certificate", cert_pem_); |
| 207 return dict; | 209 return dict; |
| 208 } | 210 } |
| 209 | 211 |
| 210 TEST_F(AssignmentSourceTest, TestTCPAlternateEndpointSuccess) { | 212 TEST_F(AssignmentSourceTest, TestTCPAlternateEndpointSuccess) { |
| 211 Assignment assignment; | 213 Assignment assignment; |
| 212 assignment.transport_protocol = Assignment::TransportProtocol::TCP; | 214 assignment.transport_protocol = Assignment::TransportProtocol::TCP; |
| 213 assignment.engine_endpoint = net::IPEndPoint(kTestIpAddress, kTestPort); | 215 assignment.assignment_options.engine_endpoint = |
| 216 net::IPEndPoint(kTestIpAddress, kTestPort); |
| 214 assignment.cert = scoped_refptr<net::X509Certificate>(nullptr); | 217 assignment.cert = scoped_refptr<net::X509Certificate>(nullptr); |
| 215 | 218 |
| 216 auto* cmd_line = base::CommandLine::ForCurrentProcess(); | 219 auto* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 217 cmd_line->AppendSwitchASCII(switches::kEngineIP, kTestIpAddressString); | 220 cmd_line->AppendSwitchASCII(switches::kEngineIP, kTestIpAddressString); |
| 218 cmd_line->AppendSwitchASCII(switches::kEnginePort, | 221 cmd_line->AppendSwitchASCII(switches::kEnginePort, std::to_string(kTestPort)); |
| 219 std::to_string(kTestPort)); | |
| 220 cmd_line->AppendSwitchASCII(switches::kEngineTransport, kTcpTransportName); | 222 cmd_line->AppendSwitchASCII(switches::kEngineTransport, kTcpTransportName); |
| 221 cmd_line->AppendSwitchASCII(kClientAuthTokenPath, | 223 cmd_line->AppendSwitchASCII(kClientAuthTokenPath, |
| 222 client_auth_token_path_.value()); | 224 client_auth_token_path_.value()); |
| 223 | 225 |
| 224 assignment.client_auth_token = GetClientAuthToken(*cmd_line); | 226 assignment.client_auth_token = GetClientAuthToken(*cmd_line); |
| 225 | 227 |
| 226 CHECK_EQ("MyVoiceIsMyPassport", assignment.client_auth_token); | 228 CHECK_EQ("MyVoiceIsMyPassport", assignment.client_auth_token); |
| 227 | 229 |
| 228 EXPECT_CALL(*this, AssignmentResponse(ASSIGNMENT_REQUEST_RESULT_OK, | 230 EXPECT_CALL(*this, AssignmentResponse(ASSIGNMENT_REQUEST_RESULT_OK, |
| 229 AssignmentEquals(assignment))) | 231 AssignmentEquals(assignment))) |
| 230 .Times(1); | 232 .Times(1); |
| 231 | 233 |
| 232 GetAlternateAssignment(); | 234 GetAlternateAssignment(); |
| 233 } | 235 } |
| 234 | 236 |
| 235 TEST_F(AssignmentSourceTest, TestSSLAlternateEndpointSuccess) { | 237 TEST_F(AssignmentSourceTest, TestSSLAlternateEndpointSuccess) { |
| 236 Assignment assignment; | 238 Assignment assignment; |
| 237 assignment.transport_protocol = Assignment::TransportProtocol::SSL; | 239 assignment.transport_protocol = Assignment::TransportProtocol::SSL; |
| 238 assignment.engine_endpoint = net::IPEndPoint(kTestIpAddress, kTestPort); | 240 assignment.assignment_options.engine_endpoint = |
| 241 net::IPEndPoint(kTestIpAddress, kTestPort); |
| 239 assignment.cert = cert_; | 242 assignment.cert = cert_; |
| 240 | 243 |
| 241 auto* cmd_line = base::CommandLine::ForCurrentProcess(); | 244 auto* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 242 | 245 |
| 243 cmd_line->AppendSwitchASCII(switches::kEngineIP, kTestIpAddressString); | 246 cmd_line->AppendSwitchASCII(switches::kEngineIP, kTestIpAddressString); |
| 244 cmd_line->AppendSwitchASCII(switches::kEnginePort, | 247 cmd_line->AppendSwitchASCII(switches::kEnginePort, std::to_string(kTestPort)); |
| 245 std::to_string(kTestPort)); | |
| 246 cmd_line->AppendSwitchASCII(switches::kEngineTransport, kSslTransportName); | 248 cmd_line->AppendSwitchASCII(switches::kEngineTransport, kSslTransportName); |
| 247 cmd_line->AppendSwitchASCII(switches::kEngineCertPath, cert_path_.value()); | 249 cmd_line->AppendSwitchASCII(switches::kEngineCertPath, cert_path_.value()); |
| 248 cmd_line->AppendSwitchASCII(kClientAuthTokenPath, | 250 cmd_line->AppendSwitchASCII(kClientAuthTokenPath, |
| 249 client_auth_token_path_.value()); | 251 client_auth_token_path_.value()); |
| 250 | 252 |
| 251 assignment.client_auth_token = GetClientAuthToken(*cmd_line); | 253 assignment.client_auth_token = GetClientAuthToken(*cmd_line); |
| 252 | 254 |
| 253 EXPECT_CALL(*this, AssignmentResponse(ASSIGNMENT_REQUEST_RESULT_OK, | 255 EXPECT_CALL(*this, AssignmentResponse(ASSIGNMENT_REQUEST_RESULT_OK, |
| 254 AssignmentEquals(assignment))) | 256 AssignmentEquals(assignment))) |
| 255 .Times(1); | 257 .Times(1); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 EXPECT_CALL(*this, | 397 EXPECT_CALL(*this, |
| 396 AssignmentResponse(ASSIGNMENT_REQUEST_RESULT_INVALID_CERT, _)); | 398 AssignmentResponse(ASSIGNMENT_REQUEST_RESULT_INVALID_CERT, _)); |
| 397 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, | 399 GetNetworkAssignmentAndWaitForResponse(net::HTTP_OK, net::Error::OK, |
| 398 ValueToString(*response), | 400 ValueToString(*response), |
| 399 kTestAuthToken, kProtocolVersion); | 401 kTestAuthToken, kProtocolVersion); |
| 400 } | 402 } |
| 401 | 403 |
| 402 } // namespace | 404 } // namespace |
| 403 } // namespace client | 405 } // namespace client |
| 404 } // namespace blimp | 406 } // namespace blimp |
| OLD | NEW |