| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/extensions/api/enterprise_platform_keys/enterprise_plat
form_keys_api.h" | 5 #include "chrome/browser/extensions/api/enterprise_platform_keys/enterprise_plat
form_keys_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 256 } |
| 257 | 257 |
| 258 // Returns an error string for the given code. | 258 // Returns an error string for the given code. |
| 259 std::string GetCertificateError(int error_code) { | 259 std::string GetCertificateError(int error_code) { |
| 260 return base::StringPrintf( | 260 return base::StringPrintf( |
| 261 EPKPChallengeMachineKey::kGetCertificateFailedError, error_code); | 261 EPKPChallengeMachineKey::kGetCertificateFailedError, error_code); |
| 262 } | 262 } |
| 263 | 263 |
| 264 std::unique_ptr<base::ListValue> CreateArgs() { | 264 std::unique_ptr<base::ListValue> CreateArgs() { |
| 265 std::unique_ptr<base::ListValue> args(new base::ListValue); | 265 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 266 args->Append(base::BinaryValue::CreateWithCopiedBuffer("challenge", 9)); | 266 args->Append(base::Value::CreateWithCopiedBuffer("challenge", 9)); |
| 267 return args; | 267 return args; |
| 268 } | 268 } |
| 269 | 269 |
| 270 EPKPChallengeMachineKey impl_; | 270 EPKPChallengeMachineKey impl_; |
| 271 scoped_refptr<EnterprisePlatformKeysChallengeMachineKeyFunction> func_; | 271 scoped_refptr<EnterprisePlatformKeysChallengeMachineKeyFunction> func_; |
| 272 base::ListValue args_; | 272 base::ListValue args_; |
| 273 }; | 273 }; |
| 274 | 274 |
| 275 TEST_F(EPKChallengeMachineKeyTest, NonEnterpriseDevice) { | 275 TEST_F(EPKChallengeMachineKeyTest, NonEnterpriseDevice) { |
| 276 stub_install_attributes_.SetConsumerOwned(); | 276 stub_install_attributes_.SetConsumerOwned(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 EXPECT_CALL( | 342 EXPECT_CALL( |
| 343 mock_async_method_caller_, | 343 mock_async_method_caller_, |
| 344 TpmAttestationSignEnterpriseChallenge( | 344 TpmAttestationSignEnterpriseChallenge( |
| 345 chromeos::attestation::KEY_DEVICE, cryptohome::Identification(), | 345 chromeos::attestation::KEY_DEVICE, cryptohome::Identification(), |
| 346 "attest-ent-machine", "google.com", "device_id", _, "challenge", _)) | 346 "attest-ent-machine", "google.com", "device_id", _, "challenge", _)) |
| 347 .Times(1); | 347 .Times(1); |
| 348 | 348 |
| 349 std::unique_ptr<base::Value> value( | 349 std::unique_ptr<base::Value> value( |
| 350 RunFunctionAndReturnSingleResult(func_.get(), CreateArgs(), browser())); | 350 RunFunctionAndReturnSingleResult(func_.get(), CreateArgs(), browser())); |
| 351 | 351 |
| 352 const base::BinaryValue* response; | 352 const base::Value* response; |
| 353 ASSERT_TRUE(value->GetAsBinary(&response)); | 353 ASSERT_TRUE(value->GetAsBinary(&response)); |
| 354 EXPECT_EQ("response", | 354 EXPECT_EQ("response", |
| 355 std::string(response->GetBuffer(), response->GetSize())); | 355 std::string(response->GetBuffer(), response->GetSize())); |
| 356 } | 356 } |
| 357 | 357 |
| 358 TEST_F(EPKChallengeMachineKeyTest, AttestationNotPrepared) { | 358 TEST_F(EPKChallengeMachineKeyTest, AttestationNotPrepared) { |
| 359 EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_)) | 359 EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_)) |
| 360 .WillRepeatedly(Invoke( | 360 .WillRepeatedly(Invoke( |
| 361 FakeBoolDBusMethod(chromeos::DBUS_METHOD_CALL_SUCCESS, false))); | 361 FakeBoolDBusMethod(chromeos::DBUS_METHOD_CALL_SUCCESS, false))); |
| 362 | 362 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 std::unique_ptr<base::ListValue> CreateArgs() { | 400 std::unique_ptr<base::ListValue> CreateArgs() { |
| 401 return CreateArgsInternal(true); | 401 return CreateArgsInternal(true); |
| 402 } | 402 } |
| 403 | 403 |
| 404 std::unique_ptr<base::ListValue> CreateArgsNoRegister() { | 404 std::unique_ptr<base::ListValue> CreateArgsNoRegister() { |
| 405 return CreateArgsInternal(false); | 405 return CreateArgsInternal(false); |
| 406 } | 406 } |
| 407 | 407 |
| 408 std::unique_ptr<base::ListValue> CreateArgsInternal(bool register_key) { | 408 std::unique_ptr<base::ListValue> CreateArgsInternal(bool register_key) { |
| 409 std::unique_ptr<base::ListValue> args(new base::ListValue); | 409 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 410 args->Append(base::BinaryValue::CreateWithCopiedBuffer("challenge", 9)); | 410 args->Append(base::Value::CreateWithCopiedBuffer("challenge", 9)); |
| 411 args->AppendBoolean(register_key); | 411 args->AppendBoolean(register_key); |
| 412 return args; | 412 return args; |
| 413 } | 413 } |
| 414 | 414 |
| 415 EPKPChallengeUserKey impl_; | 415 EPKPChallengeUserKey impl_; |
| 416 scoped_refptr<EnterprisePlatformKeysChallengeUserKeyFunction> func_; | 416 scoped_refptr<EnterprisePlatformKeysChallengeUserKeyFunction> func_; |
| 417 }; | 417 }; |
| 418 | 418 |
| 419 TEST_F(EPKChallengeUserKeyTest, UserPolicyDisabled) { | 419 TEST_F(EPKChallengeUserKeyTest, UserPolicyDisabled) { |
| 420 prefs_->SetBoolean(prefs::kAttestationEnabled, false); | 420 prefs_->SetBoolean(prefs::kAttestationEnabled, false); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 .Times(1); | 517 .Times(1); |
| 518 // RegisterKey must be called exactly once. | 518 // RegisterKey must be called exactly once. |
| 519 EXPECT_CALL(mock_async_method_caller_, | 519 EXPECT_CALL(mock_async_method_caller_, |
| 520 TpmAttestationRegisterKey(chromeos::attestation::KEY_USER, | 520 TpmAttestationRegisterKey(chromeos::attestation::KEY_USER, |
| 521 cryptohome_id, "attest-ent-user", _)) | 521 cryptohome_id, "attest-ent-user", _)) |
| 522 .Times(1); | 522 .Times(1); |
| 523 | 523 |
| 524 std::unique_ptr<base::Value> value( | 524 std::unique_ptr<base::Value> value( |
| 525 RunFunctionAndReturnSingleResult(func_.get(), CreateArgs(), browser())); | 525 RunFunctionAndReturnSingleResult(func_.get(), CreateArgs(), browser())); |
| 526 | 526 |
| 527 const base::BinaryValue* response; | 527 const base::Value* response; |
| 528 ASSERT_TRUE(value->GetAsBinary(&response)); | 528 ASSERT_TRUE(value->GetAsBinary(&response)); |
| 529 EXPECT_EQ("response", | 529 EXPECT_EQ("response", |
| 530 std::string(response->GetBuffer(), response->GetSize())); | 530 std::string(response->GetBuffer(), response->GetSize())); |
| 531 } | 531 } |
| 532 | 532 |
| 533 TEST_F(EPKChallengeUserKeyTest, AttestationNotPrepared) { | 533 TEST_F(EPKChallengeUserKeyTest, AttestationNotPrepared) { |
| 534 EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_)) | 534 EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_)) |
| 535 .WillRepeatedly(Invoke( | 535 .WillRepeatedly(Invoke( |
| 536 FakeBoolDBusMethod(chromeos::DBUS_METHOD_CALL_SUCCESS, false))); | 536 FakeBoolDBusMethod(chromeos::DBUS_METHOD_CALL_SUCCESS, false))); |
| 537 | 537 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 AccountId::FromUserEmailGaiaId("test@chromium.com", "12345"); | 592 AccountId::FromUserEmailGaiaId("test@chromium.com", "12345"); |
| 593 }; | 593 }; |
| 594 | 594 |
| 595 TEST_F(EPKChallengeUserKeyUnmanagedUserTest, UserNotManaged) { | 595 TEST_F(EPKChallengeUserKeyUnmanagedUserTest, UserNotManaged) { |
| 596 EXPECT_EQ(EPKPChallengeKeyBase::kUserNotManaged, | 596 EXPECT_EQ(EPKPChallengeKeyBase::kUserNotManaged, |
| 597 RunFunctionAndReturnError(func_.get(), CreateArgs(), browser())); | 597 RunFunctionAndReturnError(func_.get(), CreateArgs(), browser())); |
| 598 } | 598 } |
| 599 | 599 |
| 600 } // namespace | 600 } // namespace |
| 601 } // namespace extensions | 601 } // namespace extensions |
| OLD | NEW |