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