| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/proximity_auth/cryptauth/cryptauth_client_impl.h" | 5 #include "components/cryptauth/cryptauth_client_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/test/null_task_runner.h" | 10 #include "base/test/null_task_runner.h" |
| 11 #include "components/proximity_auth/cryptauth/cryptauth_access_token_fetcher.h" | 11 #include "components/cryptauth/cryptauth_access_token_fetcher.h" |
| 12 #include "components/proximity_auth/cryptauth/cryptauth_api_call_flow.h" | 12 #include "components/cryptauth/cryptauth_api_call_flow.h" |
| 13 #include "components/cryptauth/switches.h" |
| 13 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" | 14 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" |
| 14 #include "components/proximity_auth/cryptauth/switches.h" | |
| 15 #include "google_apis/gaia/fake_oauth2_token_service.h" | 15 #include "google_apis/gaia/fake_oauth2_token_service.h" |
| 16 #include "net/url_request/test_url_fetcher_factory.h" | 16 #include "net/url_request/test_url_fetcher_factory.h" |
| 17 #include "net/url_request/url_request_test_util.h" | 17 #include "net/url_request/url_request_test_util.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 21 | 21 |
| 22 using testing::_; | 22 using testing::_; |
| 23 using testing::DoAll; | 23 using testing::DoAll; |
| 24 using testing::Return; | 24 using testing::Return; |
| 25 using testing::SaveArg; | 25 using testing::SaveArg; |
| 26 using testing::StrictMock; | 26 using testing::StrictMock; |
| 27 | 27 |
| 28 namespace proximity_auth { | 28 namespace cryptauth { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 const char kTestGoogleApisUrl[] = "https://www.testgoogleapis.com"; | 32 const char kTestGoogleApisUrl[] = "https://www.testgoogleapis.com"; |
| 33 const char kAccessToken[] = "access_token"; | 33 const char kAccessToken[] = "access_token"; |
| 34 const char kPublicKey1[] = "public_key1"; | 34 const char kPublicKey1[] = "public_key1"; |
| 35 const char kPublicKey2[] = "public_key2"; | 35 const char kPublicKey2[] = "public_key2"; |
| 36 const char kBluetoothAddress1[] = "AA:AA:AA:AA:AA:AA"; | 36 const char kBluetoothAddress1[] = "AA:AA:AA:AA:AA:AA"; |
| 37 const char kBluetoothAddress2[] = "BB:BB:BB:BB:BB:BB"; | 37 const char kBluetoothAddress2[] = "BB:BB:BB:BB:BB:BB"; |
| 38 | 38 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Callback that saves the result returned by CryptAuthClient. | 87 // Callback that saves the result returned by CryptAuthClient. |
| 88 template <class T> | 88 template <class T> |
| 89 void SaveResult(T* out, const T& result) { | 89 void SaveResult(T* out, const T& result) { |
| 90 *out = result; | 90 *out = result; |
| 91 } | 91 } |
| 92 | 92 |
| 93 } // namespace | 93 } // namespace |
| 94 | 94 |
| 95 class ProximityAuthCryptAuthClientTest : public testing::Test { | 95 class CryptAuthClientTest : public testing::Test { |
| 96 protected: | 96 protected: |
| 97 ProximityAuthCryptAuthClientTest() | 97 CryptAuthClientTest() |
| 98 : access_token_fetcher_(new FakeCryptAuthAccessTokenFetcher()), | 98 : access_token_fetcher_(new FakeCryptAuthAccessTokenFetcher()), |
| 99 api_call_flow_(new StrictMock<MockCryptAuthApiCallFlow>()), | 99 api_call_flow_(new StrictMock<MockCryptAuthApiCallFlow>()), |
| 100 url_request_context_( | 100 url_request_context_( |
| 101 new net::TestURLRequestContextGetter(new base::NullTaskRunner())), | 101 new net::TestURLRequestContextGetter(new base::NullTaskRunner())), |
| 102 serialized_request_(std::string()) {} | 102 serialized_request_(std::string()) {} |
| 103 | 103 |
| 104 void SetUp() override { | 104 void SetUp() override { |
| 105 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 105 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 106 switches::kCryptAuthHTTPHost, kTestGoogleApisUrl); | 106 switches::kCryptAuthHTTPHost, kTestGoogleApisUrl); |
| 107 | 107 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 StrictMock<MockCryptAuthApiCallFlow>* api_call_flow_; | 148 StrictMock<MockCryptAuthApiCallFlow>* api_call_flow_; |
| 149 | 149 |
| 150 scoped_refptr<net::URLRequestContextGetter> url_request_context_; | 150 scoped_refptr<net::URLRequestContextGetter> url_request_context_; |
| 151 std::unique_ptr<CryptAuthClient> client_; | 151 std::unique_ptr<CryptAuthClient> client_; |
| 152 | 152 |
| 153 std::string serialized_request_; | 153 std::string serialized_request_; |
| 154 CryptAuthApiCallFlow::ResultCallback flow_result_callback_; | 154 CryptAuthApiCallFlow::ResultCallback flow_result_callback_; |
| 155 CryptAuthApiCallFlow::ErrorCallback flow_error_callback_; | 155 CryptAuthApiCallFlow::ErrorCallback flow_error_callback_; |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 TEST_F(ProximityAuthCryptAuthClientTest, GetMyDevicesSuccess) { | 158 TEST_F(CryptAuthClientTest, GetMyDevicesSuccess) { |
| 159 ExpectRequest( | 159 ExpectRequest( |
| 160 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" | 160 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" |
| 161 "getmydevices?alt=proto"); | 161 "getmydevices?alt=proto"); |
| 162 | 162 |
| 163 cryptauth::GetMyDevicesResponse result_proto; | 163 cryptauth::GetMyDevicesResponse result_proto; |
| 164 cryptauth::GetMyDevicesRequest request_proto; | 164 cryptauth::GetMyDevicesRequest request_proto; |
| 165 request_proto.set_allow_stale_read(true); | 165 request_proto.set_allow_stale_read(true); |
| 166 client_->GetMyDevices( | 166 client_->GetMyDevices( |
| 167 request_proto, | 167 request_proto, |
| 168 base::Bind(&SaveResult<cryptauth::GetMyDevicesResponse>, &result_proto), | 168 base::Bind(&SaveResult<cryptauth::GetMyDevicesResponse>, &result_proto), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 188 | 188 |
| 189 // Check that the result received in callback is the same as the response. | 189 // Check that the result received in callback is the same as the response. |
| 190 ASSERT_EQ(2, result_proto.devices_size()); | 190 ASSERT_EQ(2, result_proto.devices_size()); |
| 191 EXPECT_EQ(kPublicKey1, result_proto.devices(0).public_key()); | 191 EXPECT_EQ(kPublicKey1, result_proto.devices(0).public_key()); |
| 192 EXPECT_TRUE(result_proto.devices(0).unlock_key()); | 192 EXPECT_TRUE(result_proto.devices(0).unlock_key()); |
| 193 EXPECT_EQ(kBluetoothAddress1, result_proto.devices(0).bluetooth_address()); | 193 EXPECT_EQ(kBluetoothAddress1, result_proto.devices(0).bluetooth_address()); |
| 194 EXPECT_EQ(kPublicKey2, result_proto.devices(1).public_key()); | 194 EXPECT_EQ(kPublicKey2, result_proto.devices(1).public_key()); |
| 195 EXPECT_TRUE(result_proto.devices(1).unlockable()); | 195 EXPECT_TRUE(result_proto.devices(1).unlockable()); |
| 196 } | 196 } |
| 197 | 197 |
| 198 TEST_F(ProximityAuthCryptAuthClientTest, GetMyDevicesFailure) { | 198 TEST_F(CryptAuthClientTest, GetMyDevicesFailure) { |
| 199 ExpectRequest( | 199 ExpectRequest( |
| 200 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" | 200 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" |
| 201 "getmydevices?alt=proto"); | 201 "getmydevices?alt=proto"); |
| 202 | 202 |
| 203 std::string error_message; | 203 std::string error_message; |
| 204 client_->GetMyDevices(cryptauth::GetMyDevicesRequest(), | 204 client_->GetMyDevices(cryptauth::GetMyDevicesRequest(), |
| 205 base::Bind(&NotCalled<cryptauth::GetMyDevicesResponse>), | 205 base::Bind(&NotCalled<cryptauth::GetMyDevicesResponse>), |
| 206 base::Bind(&SaveResult<std::string>, &error_message)); | 206 base::Bind(&SaveResult<std::string>, &error_message)); |
| 207 | 207 |
| 208 std::string kStatus500Error("HTTP status: 500"); | 208 std::string kStatus500Error("HTTP status: 500"); |
| 209 FailApiCallFlow(kStatus500Error); | 209 FailApiCallFlow(kStatus500Error); |
| 210 EXPECT_EQ(kStatus500Error, error_message); | 210 EXPECT_EQ(kStatus500Error, error_message); |
| 211 } | 211 } |
| 212 | 212 |
| 213 TEST_F(ProximityAuthCryptAuthClientTest, FindEligibleUnlockDevicesSuccess) { | 213 TEST_F(CryptAuthClientTest, FindEligibleUnlockDevicesSuccess) { |
| 214 ExpectRequest( | 214 ExpectRequest( |
| 215 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" | 215 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" |
| 216 "findeligibleunlockdevices?alt=proto"); | 216 "findeligibleunlockdevices?alt=proto"); |
| 217 | 217 |
| 218 cryptauth::FindEligibleUnlockDevicesResponse result_proto; | 218 cryptauth::FindEligibleUnlockDevicesResponse result_proto; |
| 219 cryptauth::FindEligibleUnlockDevicesRequest request_proto; | 219 cryptauth::FindEligibleUnlockDevicesRequest request_proto; |
| 220 request_proto.set_callback_bluetooth_address(kBluetoothAddress2); | 220 request_proto.set_callback_bluetooth_address(kBluetoothAddress2); |
| 221 client_->FindEligibleUnlockDevices( | 221 client_->FindEligibleUnlockDevices( |
| 222 request_proto, | 222 request_proto, |
| 223 base::Bind(&SaveResult<cryptauth::FindEligibleUnlockDevicesResponse>, | 223 base::Bind(&SaveResult<cryptauth::FindEligibleUnlockDevicesResponse>, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 246 ASSERT_EQ(1, result_proto.eligible_devices_size()); | 246 ASSERT_EQ(1, result_proto.eligible_devices_size()); |
| 247 EXPECT_EQ(kPublicKey1, result_proto.eligible_devices(0).public_key()); | 247 EXPECT_EQ(kPublicKey1, result_proto.eligible_devices(0).public_key()); |
| 248 ASSERT_EQ(1, result_proto.ineligible_devices_size()); | 248 ASSERT_EQ(1, result_proto.ineligible_devices_size()); |
| 249 EXPECT_EQ(kPublicKey2, | 249 EXPECT_EQ(kPublicKey2, |
| 250 result_proto.ineligible_devices(0).device().public_key()); | 250 result_proto.ineligible_devices(0).device().public_key()); |
| 251 ASSERT_EQ(1, result_proto.ineligible_devices(0).reasons_size()); | 251 ASSERT_EQ(1, result_proto.ineligible_devices(0).reasons_size()); |
| 252 EXPECT_EQ(kIneligibilityReason, | 252 EXPECT_EQ(kIneligibilityReason, |
| 253 result_proto.ineligible_devices(0).reasons(0)); | 253 result_proto.ineligible_devices(0).reasons(0)); |
| 254 } | 254 } |
| 255 | 255 |
| 256 TEST_F(ProximityAuthCryptAuthClientTest, FindEligibleUnlockDevicesFailure) { | 256 TEST_F(CryptAuthClientTest, FindEligibleUnlockDevicesFailure) { |
| 257 ExpectRequest( | 257 ExpectRequest( |
| 258 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" | 258 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" |
| 259 "findeligibleunlockdevices?alt=proto"); | 259 "findeligibleunlockdevices?alt=proto"); |
| 260 | 260 |
| 261 std::string error_message; | 261 std::string error_message; |
| 262 cryptauth::FindEligibleUnlockDevicesRequest request_proto; | 262 cryptauth::FindEligibleUnlockDevicesRequest request_proto; |
| 263 request_proto.set_callback_bluetooth_address(kBluetoothAddress1); | 263 request_proto.set_callback_bluetooth_address(kBluetoothAddress1); |
| 264 client_->FindEligibleUnlockDevices( | 264 client_->FindEligibleUnlockDevices( |
| 265 request_proto, | 265 request_proto, |
| 266 base::Bind(&NotCalled<cryptauth::FindEligibleUnlockDevicesResponse>), | 266 base::Bind(&NotCalled<cryptauth::FindEligibleUnlockDevicesResponse>), |
| 267 base::Bind(&SaveResult<std::string>, &error_message)); | 267 base::Bind(&SaveResult<std::string>, &error_message)); |
| 268 | 268 |
| 269 std::string kStatus403Error("HTTP status: 403"); | 269 std::string kStatus403Error("HTTP status: 403"); |
| 270 FailApiCallFlow(kStatus403Error); | 270 FailApiCallFlow(kStatus403Error); |
| 271 EXPECT_EQ(kStatus403Error, error_message); | 271 EXPECT_EQ(kStatus403Error, error_message); |
| 272 } | 272 } |
| 273 | 273 |
| 274 TEST_F(ProximityAuthCryptAuthClientTest, SendDeviceSyncTickleSuccess) { | 274 TEST_F(CryptAuthClientTest, SendDeviceSyncTickleSuccess) { |
| 275 ExpectRequest( | 275 ExpectRequest( |
| 276 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" | 276 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" |
| 277 "senddevicesynctickle?alt=proto"); | 277 "senddevicesynctickle?alt=proto"); |
| 278 | 278 |
| 279 cryptauth::SendDeviceSyncTickleResponse result_proto; | 279 cryptauth::SendDeviceSyncTickleResponse result_proto; |
| 280 client_->SendDeviceSyncTickle( | 280 client_->SendDeviceSyncTickle( |
| 281 cryptauth::SendDeviceSyncTickleRequest(), | 281 cryptauth::SendDeviceSyncTickleRequest(), |
| 282 base::Bind(&SaveResult<cryptauth::SendDeviceSyncTickleResponse>, | 282 base::Bind(&SaveResult<cryptauth::SendDeviceSyncTickleResponse>, |
| 283 &result_proto), | 283 &result_proto), |
| 284 base::Bind(&NotCalled<std::string>)); | 284 base::Bind(&NotCalled<std::string>)); |
| 285 | 285 |
| 286 cryptauth::SendDeviceSyncTickleRequest expected_request; | 286 cryptauth::SendDeviceSyncTickleRequest expected_request; |
| 287 EXPECT_TRUE(expected_request.ParseFromString(serialized_request_)); | 287 EXPECT_TRUE(expected_request.ParseFromString(serialized_request_)); |
| 288 | 288 |
| 289 cryptauth::SendDeviceSyncTickleResponse response_proto; | 289 cryptauth::SendDeviceSyncTickleResponse response_proto; |
| 290 FinishApiCallFlow(&response_proto); | 290 FinishApiCallFlow(&response_proto); |
| 291 } | 291 } |
| 292 | 292 |
| 293 TEST_F(ProximityAuthCryptAuthClientTest, ToggleEasyUnlockSuccess) { | 293 TEST_F(CryptAuthClientTest, ToggleEasyUnlockSuccess) { |
| 294 ExpectRequest( | 294 ExpectRequest( |
| 295 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" | 295 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" |
| 296 "toggleeasyunlock?alt=proto"); | 296 "toggleeasyunlock?alt=proto"); |
| 297 | 297 |
| 298 cryptauth::ToggleEasyUnlockResponse result_proto; | 298 cryptauth::ToggleEasyUnlockResponse result_proto; |
| 299 cryptauth::ToggleEasyUnlockRequest request_proto; | 299 cryptauth::ToggleEasyUnlockRequest request_proto; |
| 300 request_proto.set_enable(true); | 300 request_proto.set_enable(true); |
| 301 request_proto.set_apply_to_all(false); | 301 request_proto.set_apply_to_all(false); |
| 302 request_proto.set_public_key(kPublicKey1); | 302 request_proto.set_public_key(kPublicKey1); |
| 303 client_->ToggleEasyUnlock( | 303 client_->ToggleEasyUnlock( |
| 304 request_proto, | 304 request_proto, |
| 305 base::Bind(&SaveResult<cryptauth::ToggleEasyUnlockResponse>, | 305 base::Bind(&SaveResult<cryptauth::ToggleEasyUnlockResponse>, |
| 306 &result_proto), | 306 &result_proto), |
| 307 base::Bind(&NotCalled<std::string>)); | 307 base::Bind(&NotCalled<std::string>)); |
| 308 | 308 |
| 309 cryptauth::ToggleEasyUnlockRequest expected_request; | 309 cryptauth::ToggleEasyUnlockRequest expected_request; |
| 310 EXPECT_TRUE(expected_request.ParseFromString(serialized_request_)); | 310 EXPECT_TRUE(expected_request.ParseFromString(serialized_request_)); |
| 311 EXPECT_TRUE(expected_request.enable()); | 311 EXPECT_TRUE(expected_request.enable()); |
| 312 EXPECT_EQ(kPublicKey1, expected_request.public_key()); | 312 EXPECT_EQ(kPublicKey1, expected_request.public_key()); |
| 313 EXPECT_FALSE(expected_request.apply_to_all()); | 313 EXPECT_FALSE(expected_request.apply_to_all()); |
| 314 | 314 |
| 315 cryptauth::ToggleEasyUnlockResponse response_proto; | 315 cryptauth::ToggleEasyUnlockResponse response_proto; |
| 316 FinishApiCallFlow(&response_proto); | 316 FinishApiCallFlow(&response_proto); |
| 317 } | 317 } |
| 318 | 318 |
| 319 TEST_F(ProximityAuthCryptAuthClientTest, SetupEnrollmentSuccess) { | 319 TEST_F(CryptAuthClientTest, SetupEnrollmentSuccess) { |
| 320 ExpectRequest( | 320 ExpectRequest( |
| 321 "https://www.testgoogleapis.com/cryptauth/v1/enrollment/" | 321 "https://www.testgoogleapis.com/cryptauth/v1/enrollment/" |
| 322 "setup?alt=proto"); | 322 "setup?alt=proto"); |
| 323 | 323 |
| 324 std::string kApplicationId = "mkaes"; | 324 std::string kApplicationId = "mkaes"; |
| 325 std::vector<std::string> supported_protocols; | 325 std::vector<std::string> supported_protocols; |
| 326 supported_protocols.push_back("gcmV1"); | 326 supported_protocols.push_back("gcmV1"); |
| 327 supported_protocols.push_back("testProtocol"); | 327 supported_protocols.push_back("testProtocol"); |
| 328 | 328 |
| 329 cryptauth::SetupEnrollmentResponse result_proto; | 329 cryptauth::SetupEnrollmentResponse result_proto; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 355 } | 355 } |
| 356 | 356 |
| 357 // Check that the returned proto is the same as the one just created. | 357 // Check that the returned proto is the same as the one just created. |
| 358 EXPECT_EQ("OK", result_proto.status()); | 358 EXPECT_EQ("OK", result_proto.status()); |
| 359 ASSERT_EQ(1, result_proto.infos_size()); | 359 ASSERT_EQ(1, result_proto.infos_size()); |
| 360 EXPECT_EQ("gcmV1", result_proto.infos(0).type()); | 360 EXPECT_EQ("gcmV1", result_proto.infos(0).type()); |
| 361 EXPECT_EQ("session_id", result_proto.infos(0).enrollment_session_id()); | 361 EXPECT_EQ("session_id", result_proto.infos(0).enrollment_session_id()); |
| 362 EXPECT_EQ("ephemeral_key", result_proto.infos(0).server_ephemeral_key()); | 362 EXPECT_EQ("ephemeral_key", result_proto.infos(0).server_ephemeral_key()); |
| 363 } | 363 } |
| 364 | 364 |
| 365 TEST_F(ProximityAuthCryptAuthClientTest, FinishEnrollmentSuccess) { | 365 TEST_F(CryptAuthClientTest, FinishEnrollmentSuccess) { |
| 366 ExpectRequest( | 366 ExpectRequest( |
| 367 "https://www.testgoogleapis.com/cryptauth/v1/enrollment/" | 367 "https://www.testgoogleapis.com/cryptauth/v1/enrollment/" |
| 368 "finish?alt=proto"); | 368 "finish?alt=proto"); |
| 369 | 369 |
| 370 const char kEnrollmentSessionId[] = "enrollment_session_id"; | 370 const char kEnrollmentSessionId[] = "enrollment_session_id"; |
| 371 const char kEnrollmentMessage[] = "enrollment_message"; | 371 const char kEnrollmentMessage[] = "enrollment_message"; |
| 372 const char kDeviceEphemeralKey[] = "device_ephermal_key"; | 372 const char kDeviceEphemeralKey[] = "device_ephermal_key"; |
| 373 cryptauth::FinishEnrollmentResponse result_proto; | 373 cryptauth::FinishEnrollmentResponse result_proto; |
| 374 cryptauth::FinishEnrollmentRequest request_proto; | 374 cryptauth::FinishEnrollmentRequest request_proto; |
| 375 request_proto.set_enrollment_session_id(kEnrollmentSessionId); | 375 request_proto.set_enrollment_session_id(kEnrollmentSessionId); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 388 EXPECT_EQ(kDeviceEphemeralKey, expected_request.device_ephemeral_key()); | 388 EXPECT_EQ(kDeviceEphemeralKey, expected_request.device_ephemeral_key()); |
| 389 | 389 |
| 390 { | 390 { |
| 391 cryptauth::FinishEnrollmentResponse response_proto; | 391 cryptauth::FinishEnrollmentResponse response_proto; |
| 392 response_proto.set_status("OK"); | 392 response_proto.set_status("OK"); |
| 393 FinishApiCallFlow(&response_proto); | 393 FinishApiCallFlow(&response_proto); |
| 394 } | 394 } |
| 395 EXPECT_EQ("OK", result_proto.status()); | 395 EXPECT_EQ("OK", result_proto.status()); |
| 396 } | 396 } |
| 397 | 397 |
| 398 TEST_F(ProximityAuthCryptAuthClientTest, FetchAccessTokenFailure) { | 398 TEST_F(CryptAuthClientTest, FetchAccessTokenFailure) { |
| 399 access_token_fetcher_->set_access_token(""); | 399 access_token_fetcher_->set_access_token(""); |
| 400 | 400 |
| 401 std::string error_message; | 401 std::string error_message; |
| 402 client_->GetMyDevices(cryptauth::GetMyDevicesRequest(), | 402 client_->GetMyDevices(cryptauth::GetMyDevicesRequest(), |
| 403 base::Bind(&NotCalled<cryptauth::GetMyDevicesResponse>), | 403 base::Bind(&NotCalled<cryptauth::GetMyDevicesResponse>), |
| 404 base::Bind(&SaveResult<std::string>, &error_message)); | 404 base::Bind(&SaveResult<std::string>, &error_message)); |
| 405 | 405 |
| 406 EXPECT_EQ("Failed to get a valid access token.", error_message); | 406 EXPECT_EQ("Failed to get a valid access token.", error_message); |
| 407 } | 407 } |
| 408 | 408 |
| 409 TEST_F(ProximityAuthCryptAuthClientTest, ParseResponseProtoFailure) { | 409 TEST_F(CryptAuthClientTest, ParseResponseProtoFailure) { |
| 410 ExpectRequest( | 410 ExpectRequest( |
| 411 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" | 411 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" |
| 412 "getmydevices?alt=proto"); | 412 "getmydevices?alt=proto"); |
| 413 | 413 |
| 414 std::string error_message; | 414 std::string error_message; |
| 415 client_->GetMyDevices(cryptauth::GetMyDevicesRequest(), | 415 client_->GetMyDevices(cryptauth::GetMyDevicesRequest(), |
| 416 base::Bind(&NotCalled<cryptauth::GetMyDevicesResponse>), | 416 base::Bind(&NotCalled<cryptauth::GetMyDevicesResponse>), |
| 417 base::Bind(&SaveResult<std::string>, &error_message)); | 417 base::Bind(&SaveResult<std::string>, &error_message)); |
| 418 | 418 |
| 419 flow_result_callback_.Run("Not a valid serialized response message."); | 419 flow_result_callback_.Run("Not a valid serialized response message."); |
| 420 EXPECT_EQ("Failed to parse response proto.", error_message); | 420 EXPECT_EQ("Failed to parse response proto.", error_message); |
| 421 } | 421 } |
| 422 | 422 |
| 423 TEST_F(ProximityAuthCryptAuthClientTest, | 423 TEST_F(CryptAuthClientTest, |
| 424 MakeSecondRequestBeforeFirstRequestSucceeds) { | 424 MakeSecondRequestBeforeFirstRequestSucceeds) { |
| 425 ExpectRequest( | 425 ExpectRequest( |
| 426 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" | 426 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" |
| 427 "getmydevices?alt=proto"); | 427 "getmydevices?alt=proto"); |
| 428 | 428 |
| 429 // Make first request. | 429 // Make first request. |
| 430 cryptauth::GetMyDevicesResponse result_proto; | 430 cryptauth::GetMyDevicesResponse result_proto; |
| 431 client_->GetMyDevices( | 431 client_->GetMyDevices( |
| 432 cryptauth::GetMyDevicesRequest(), | 432 cryptauth::GetMyDevicesRequest(), |
| 433 base::Bind(&SaveResult<cryptauth::GetMyDevicesResponse>, &result_proto), | 433 base::Bind(&SaveResult<cryptauth::GetMyDevicesResponse>, &result_proto), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 449 cryptauth::GetMyDevicesResponse response_proto; | 449 cryptauth::GetMyDevicesResponse response_proto; |
| 450 response_proto.add_devices(); | 450 response_proto.add_devices(); |
| 451 response_proto.mutable_devices(0)->set_public_key(kPublicKey1); | 451 response_proto.mutable_devices(0)->set_public_key(kPublicKey1); |
| 452 FinishApiCallFlow(&response_proto); | 452 FinishApiCallFlow(&response_proto); |
| 453 } | 453 } |
| 454 | 454 |
| 455 ASSERT_EQ(1, result_proto.devices_size()); | 455 ASSERT_EQ(1, result_proto.devices_size()); |
| 456 EXPECT_EQ(kPublicKey1, result_proto.devices(0).public_key()); | 456 EXPECT_EQ(kPublicKey1, result_proto.devices(0).public_key()); |
| 457 } | 457 } |
| 458 | 458 |
| 459 TEST_F(ProximityAuthCryptAuthClientTest, | 459 TEST_F(CryptAuthClientTest, |
| 460 MakeSecondRequestBeforeFirstRequestFails) { | 460 MakeSecondRequestBeforeFirstRequestFails) { |
| 461 ExpectRequest( | 461 ExpectRequest( |
| 462 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" | 462 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" |
| 463 "getmydevices?alt=proto"); | 463 "getmydevices?alt=proto"); |
| 464 | 464 |
| 465 // Make first request. | 465 // Make first request. |
| 466 std::string error_message; | 466 std::string error_message; |
| 467 client_->GetMyDevices(cryptauth::GetMyDevicesRequest(), | 467 client_->GetMyDevices(cryptauth::GetMyDevicesRequest(), |
| 468 base::Bind(&NotCalled<cryptauth::GetMyDevicesResponse>), | 468 base::Bind(&NotCalled<cryptauth::GetMyDevicesResponse>), |
| 469 base::Bind(&SaveResult<std::string>, &error_message)); | 469 base::Bind(&SaveResult<std::string>, &error_message)); |
| 470 | 470 |
| 471 // With request pending, make second request. | 471 // With request pending, make second request. |
| 472 { | 472 { |
| 473 std::string error_message; | 473 std::string error_message; |
| 474 client_->FindEligibleUnlockDevices( | 474 client_->FindEligibleUnlockDevices( |
| 475 cryptauth::FindEligibleUnlockDevicesRequest(), | 475 cryptauth::FindEligibleUnlockDevicesRequest(), |
| 476 base::Bind(&NotCalled<cryptauth::FindEligibleUnlockDevicesResponse>), | 476 base::Bind(&NotCalled<cryptauth::FindEligibleUnlockDevicesResponse>), |
| 477 base::Bind(&SaveResult<std::string>, &error_message)); | 477 base::Bind(&SaveResult<std::string>, &error_message)); |
| 478 EXPECT_EQ("Client has been used for another request. Do not reuse.", | 478 EXPECT_EQ("Client has been used for another request. Do not reuse.", |
| 479 error_message); | 479 error_message); |
| 480 } | 480 } |
| 481 | 481 |
| 482 // Fail first request. | 482 // Fail first request. |
| 483 std::string kStatus429Error = "HTTP status: 429"; | 483 std::string kStatus429Error = "HTTP status: 429"; |
| 484 FailApiCallFlow(kStatus429Error); | 484 FailApiCallFlow(kStatus429Error); |
| 485 EXPECT_EQ(kStatus429Error, error_message); | 485 EXPECT_EQ(kStatus429Error, error_message); |
| 486 } | 486 } |
| 487 | 487 |
| 488 TEST_F(ProximityAuthCryptAuthClientTest, | 488 TEST_F(CryptAuthClientTest, |
| 489 MakeSecondRequestAfterFirstRequestSucceeds) { | 489 MakeSecondRequestAfterFirstRequestSucceeds) { |
| 490 // Make first request successfully. | 490 // Make first request successfully. |
| 491 { | 491 { |
| 492 ExpectRequest( | 492 ExpectRequest( |
| 493 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" | 493 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" |
| 494 "getmydevices?alt=proto"); | 494 "getmydevices?alt=proto"); |
| 495 cryptauth::GetMyDevicesResponse result_proto; | 495 cryptauth::GetMyDevicesResponse result_proto; |
| 496 client_->GetMyDevices( | 496 client_->GetMyDevices( |
| 497 cryptauth::GetMyDevicesRequest(), | 497 cryptauth::GetMyDevicesRequest(), |
| 498 base::Bind(&SaveResult<cryptauth::GetMyDevicesResponse>, &result_proto), | 498 base::Bind(&SaveResult<cryptauth::GetMyDevicesResponse>, &result_proto), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 511 std::string error_message; | 511 std::string error_message; |
| 512 client_->FindEligibleUnlockDevices( | 512 client_->FindEligibleUnlockDevices( |
| 513 cryptauth::FindEligibleUnlockDevicesRequest(), | 513 cryptauth::FindEligibleUnlockDevicesRequest(), |
| 514 base::Bind(&NotCalled<cryptauth::FindEligibleUnlockDevicesResponse>), | 514 base::Bind(&NotCalled<cryptauth::FindEligibleUnlockDevicesResponse>), |
| 515 base::Bind(&SaveResult<std::string>, &error_message)); | 515 base::Bind(&SaveResult<std::string>, &error_message)); |
| 516 EXPECT_EQ("Client has been used for another request. Do not reuse.", | 516 EXPECT_EQ("Client has been used for another request. Do not reuse.", |
| 517 error_message); | 517 error_message); |
| 518 } | 518 } |
| 519 } | 519 } |
| 520 | 520 |
| 521 TEST_F(ProximityAuthCryptAuthClientTest, DeviceClassifierIsSet) { | 521 TEST_F(CryptAuthClientTest, DeviceClassifierIsSet) { |
| 522 ExpectRequest( | 522 ExpectRequest( |
| 523 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" | 523 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" |
| 524 "getmydevices?alt=proto"); | 524 "getmydevices?alt=proto"); |
| 525 | 525 |
| 526 cryptauth::GetMyDevicesResponse result_proto; | 526 cryptauth::GetMyDevicesResponse result_proto; |
| 527 cryptauth::GetMyDevicesRequest request_proto; | 527 cryptauth::GetMyDevicesRequest request_proto; |
| 528 request_proto.set_allow_stale_read(true); | 528 request_proto.set_allow_stale_read(true); |
| 529 client_->GetMyDevices( | 529 client_->GetMyDevices( |
| 530 request_proto, | 530 request_proto, |
| 531 base::Bind(&SaveResult<cryptauth::GetMyDevicesResponse>, &result_proto), | 531 base::Bind(&SaveResult<cryptauth::GetMyDevicesResponse>, &result_proto), |
| 532 base::Bind(&NotCalled<std::string>)); | 532 base::Bind(&NotCalled<std::string>)); |
| 533 cryptauth::GetMyDevicesRequest expected_request; | 533 cryptauth::GetMyDevicesRequest expected_request; |
| 534 EXPECT_TRUE(expected_request.ParseFromString(serialized_request_)); | 534 EXPECT_TRUE(expected_request.ParseFromString(serialized_request_)); |
| 535 | 535 |
| 536 const cryptauth::DeviceClassifier& device_classifier = | 536 const cryptauth::DeviceClassifier& device_classifier = |
| 537 expected_request.device_classifier(); | 537 expected_request.device_classifier(); |
| 538 EXPECT_EQ(kDeviceOsVersionCode, device_classifier.device_os_version_code()); | 538 EXPECT_EQ(kDeviceOsVersionCode, device_classifier.device_os_version_code()); |
| 539 EXPECT_EQ(kDeviceSoftwareVersionCode, | 539 EXPECT_EQ(kDeviceSoftwareVersionCode, |
| 540 device_classifier.device_software_version_code()); | 540 device_classifier.device_software_version_code()); |
| 541 EXPECT_EQ(kDeviceSoftwarePackage, | 541 EXPECT_EQ(kDeviceSoftwarePackage, |
| 542 device_classifier.device_software_package()); | 542 device_classifier.device_software_package()); |
| 543 EXPECT_EQ(kDeviceType, device_classifier.device_type()); | 543 EXPECT_EQ(kDeviceType, device_classifier.device_type()); |
| 544 } | 544 } |
| 545 | 545 |
| 546 TEST_F(ProximityAuthCryptAuthClientTest, GetAccessTokenUsed) { | 546 TEST_F(CryptAuthClientTest, GetAccessTokenUsed) { |
| 547 EXPECT_TRUE(client_->GetAccessTokenUsed().empty()); | 547 EXPECT_TRUE(client_->GetAccessTokenUsed().empty()); |
| 548 ExpectRequest( | 548 ExpectRequest( |
| 549 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" | 549 "https://www.testgoogleapis.com/cryptauth/v1/deviceSync/" |
| 550 "getmydevices?alt=proto"); | 550 "getmydevices?alt=proto"); |
| 551 | 551 |
| 552 cryptauth::GetMyDevicesResponse result_proto; | 552 cryptauth::GetMyDevicesResponse result_proto; |
| 553 cryptauth::GetMyDevicesRequest request_proto; | 553 cryptauth::GetMyDevicesRequest request_proto; |
| 554 request_proto.set_allow_stale_read(true); | 554 request_proto.set_allow_stale_read(true); |
| 555 client_->GetMyDevices( | 555 client_->GetMyDevices( |
| 556 request_proto, | 556 request_proto, |
| 557 base::Bind(&SaveResult<cryptauth::GetMyDevicesResponse>, &result_proto), | 557 base::Bind(&SaveResult<cryptauth::GetMyDevicesResponse>, &result_proto), |
| 558 base::Bind(&NotCalled<std::string>)); | 558 base::Bind(&NotCalled<std::string>)); |
| 559 EXPECT_EQ(kAccessToken, client_->GetAccessTokenUsed()); | 559 EXPECT_EQ(kAccessToken, client_->GetAccessTokenUsed()); |
| 560 } | 560 } |
| 561 | 561 |
| 562 } // namespace proximity_auth | 562 } // namespace cryptauth |
| OLD | NEW |