| 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 EXPECT_CALL( | 383 EXPECT_CALL( |
| 384 mock_async_method_caller_, | 384 mock_async_method_caller_, |
| 385 TpmAttestationSignEnterpriseChallenge( | 385 TpmAttestationSignEnterpriseChallenge( |
| 386 chromeos::attestation::KEY_DEVICE, cryptohome::Identification(), | 386 chromeos::attestation::KEY_DEVICE, cryptohome::Identification(), |
| 387 "attest-ent-machine", "google.com", "device_id", _, "challenge", _)) | 387 "attest-ent-machine", "google.com", "device_id", _, "challenge", _)) |
| 388 .Times(1); | 388 .Times(1); |
| 389 | 389 |
| 390 std::unique_ptr<base::Value> value( | 390 std::unique_ptr<base::Value> value( |
| 391 RunFunctionAndReturnSingleResult(func_.get(), CreateArgs(), browser())); | 391 RunFunctionAndReturnSingleResult(func_.get(), CreateArgs(), browser())); |
| 392 | 392 |
| 393 const base::Value* response; | 393 ASSERT_TRUE(value->is_blob()); |
| 394 ASSERT_TRUE(value->GetAsBinary(&response)); | 394 EXPECT_EQ("response", |
| 395 EXPECT_EQ("response", std::string(response->GetBlob().data(), | 395 std::string(value->GetBlob().data(), value->GetBlob().size())); |
| 396 response->GetBlob().size())); | |
| 397 } | 396 } |
| 398 | 397 |
| 399 TEST_F(EPKChallengeMachineKeyTest, KeyRegisteredSuccess) { | 398 TEST_F(EPKChallengeMachineKeyTest, KeyRegisteredSuccess) { |
| 400 // GetCertificate must be called exactly once. | 399 // GetCertificate must be called exactly once. |
| 401 EXPECT_CALL(mock_attestation_flow_, | 400 EXPECT_CALL(mock_attestation_flow_, |
| 402 GetCertificate( | 401 GetCertificate( |
| 403 chromeos::attestation::PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, | 402 chromeos::attestation::PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, |
| 404 _, _, _, _)) | 403 _, _, _, _)) |
| 405 .Times(1); | 404 .Times(1); |
| 406 // TpmAttestationRegisterKey must be called exactly once. | 405 // TpmAttestationRegisterKey must be called exactly once. |
| 407 EXPECT_CALL(mock_async_method_caller_, | 406 EXPECT_CALL(mock_async_method_caller_, |
| 408 TpmAttestationRegisterKey(chromeos::attestation::KEY_DEVICE, | 407 TpmAttestationRegisterKey(chromeos::attestation::KEY_DEVICE, |
| 409 _ /* Unused by the API. */, | 408 _ /* Unused by the API. */, |
| 410 "attest-ent-machine", _)) | 409 "attest-ent-machine", _)) |
| 411 .Times(1); | 410 .Times(1); |
| 412 // SignEnterpriseChallenge must be called exactly once. | 411 // SignEnterpriseChallenge must be called exactly once. |
| 413 EXPECT_CALL( | 412 EXPECT_CALL( |
| 414 mock_async_method_caller_, | 413 mock_async_method_caller_, |
| 415 TpmAttestationSignEnterpriseChallenge( | 414 TpmAttestationSignEnterpriseChallenge( |
| 416 chromeos::attestation::KEY_DEVICE, cryptohome::Identification(), | 415 chromeos::attestation::KEY_DEVICE, cryptohome::Identification(), |
| 417 "attest-ent-machine", "google.com", "device_id", _, "challenge", _)) | 416 "attest-ent-machine", "google.com", "device_id", _, "challenge", _)) |
| 418 .Times(1); | 417 .Times(1); |
| 419 | 418 |
| 420 std::unique_ptr<base::Value> value(RunFunctionAndReturnSingleResult( | 419 std::unique_ptr<base::Value> value(RunFunctionAndReturnSingleResult( |
| 421 func_.get(), CreateArgsRegister(), browser())); | 420 func_.get(), CreateArgsRegister(), browser())); |
| 422 | 421 |
| 423 const base::Value* response; | 422 ASSERT_TRUE(value->is_blob()); |
| 424 ASSERT_TRUE(value->GetAsBinary(&response)); | 423 EXPECT_EQ("response", |
| 425 EXPECT_EQ("response", std::string(response->GetBlob().data(), | 424 std::string(value->GetBlob().data(), value->GetBlob().size())); |
| 426 response->GetBlob().size())); | |
| 427 } | 425 } |
| 428 | 426 |
| 429 TEST_F(EPKChallengeMachineKeyTest, AttestationNotPrepared) { | 427 TEST_F(EPKChallengeMachineKeyTest, AttestationNotPrepared) { |
| 430 EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_)) | 428 EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_)) |
| 431 .WillRepeatedly(Invoke( | 429 .WillRepeatedly(Invoke( |
| 432 FakeBoolDBusMethod(chromeos::DBUS_METHOD_CALL_SUCCESS, false))); | 430 FakeBoolDBusMethod(chromeos::DBUS_METHOD_CALL_SUCCESS, false))); |
| 433 | 431 |
| 434 EXPECT_EQ(GetCertificateError(kResetRequired), | 432 EXPECT_EQ(GetCertificateError(kResetRequired), |
| 435 RunFunctionAndReturnError(func_.get(), CreateArgs(), browser())); | 433 RunFunctionAndReturnError(func_.get(), CreateArgs(), browser())); |
| 436 } | 434 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 .Times(1); | 586 .Times(1); |
| 589 // RegisterKey must be called exactly once. | 587 // RegisterKey must be called exactly once. |
| 590 EXPECT_CALL(mock_async_method_caller_, | 588 EXPECT_CALL(mock_async_method_caller_, |
| 591 TpmAttestationRegisterKey(chromeos::attestation::KEY_USER, | 589 TpmAttestationRegisterKey(chromeos::attestation::KEY_USER, |
| 592 cryptohome_id, "attest-ent-user", _)) | 590 cryptohome_id, "attest-ent-user", _)) |
| 593 .Times(1); | 591 .Times(1); |
| 594 | 592 |
| 595 std::unique_ptr<base::Value> value( | 593 std::unique_ptr<base::Value> value( |
| 596 RunFunctionAndReturnSingleResult(func_.get(), CreateArgs(), browser())); | 594 RunFunctionAndReturnSingleResult(func_.get(), CreateArgs(), browser())); |
| 597 | 595 |
| 598 const base::Value* response; | 596 ASSERT_TRUE(value->is_blob()); |
| 599 ASSERT_TRUE(value->GetAsBinary(&response)); | 597 EXPECT_EQ("response", |
| 600 EXPECT_EQ("response", std::string(response->GetBlob().data(), | 598 std::string(value->GetBlob().data(), value->GetBlob().size())); |
| 601 response->GetBlob().size())); | |
| 602 } | 599 } |
| 603 | 600 |
| 604 TEST_F(EPKChallengeUserKeyTest, AttestationNotPrepared) { | 601 TEST_F(EPKChallengeUserKeyTest, AttestationNotPrepared) { |
| 605 EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_)) | 602 EXPECT_CALL(mock_cryptohome_client_, TpmAttestationIsPrepared(_)) |
| 606 .WillRepeatedly(Invoke( | 603 .WillRepeatedly(Invoke( |
| 607 FakeBoolDBusMethod(chromeos::DBUS_METHOD_CALL_SUCCESS, false))); | 604 FakeBoolDBusMethod(chromeos::DBUS_METHOD_CALL_SUCCESS, false))); |
| 608 | 605 |
| 609 EXPECT_EQ(GetCertificateError(kResetRequired), | 606 EXPECT_EQ(GetCertificateError(kResetRequired), |
| 610 RunFunctionAndReturnError(func_.get(), CreateArgs(), browser())); | 607 RunFunctionAndReturnError(func_.get(), CreateArgs(), browser())); |
| 611 } | 608 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 AccountId::FromUserEmailGaiaId("test@chromium.com", "12345"); | 660 AccountId::FromUserEmailGaiaId("test@chromium.com", "12345"); |
| 664 }; | 661 }; |
| 665 | 662 |
| 666 TEST_F(EPKChallengeUserKeyUnmanagedUserTest, UserNotManaged) { | 663 TEST_F(EPKChallengeUserKeyUnmanagedUserTest, UserNotManaged) { |
| 667 EXPECT_EQ(EPKPChallengeKeyBase::kUserNotManaged, | 664 EXPECT_EQ(EPKPChallengeKeyBase::kUserNotManaged, |
| 668 RunFunctionAndReturnError(func_.get(), CreateArgs(), browser())); | 665 RunFunctionAndReturnError(func_.get(), CreateArgs(), browser())); |
| 669 } | 666 } |
| 670 | 667 |
| 671 } // namespace | 668 } // namespace |
| 672 } // namespace extensions | 669 } // namespace extensions |
| OLD | NEW |