| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/gcm_driver/crypto/gcm_key_store.h" | 5 #include "components/gcm_driver/crypto/gcm_key_store.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/test/gtest_util.h" |
| 15 #include "base/test/histogram_tester.h" | 16 #include "base/test/histogram_tester.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "components/gcm_driver/crypto/p256_key_util.h" | 18 #include "components/gcm_driver/crypto/p256_key_util.h" |
| 18 #include "net/test/gtest_util.h" | |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 namespace gcm { | 21 namespace gcm { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const char kFakeAppId[] = "my_app_id"; | 25 const char kFakeAppId[] = "my_app_id"; |
| 26 const char kSecondFakeAppId[] = "my_other_app_id"; | 26 const char kSecondFakeAppId[] = "my_other_app_id"; |
| 27 const char kFakeAuthorizedEntity[] = "my_sender_id"; | 27 const char kFakeAuthorizedEntity[] = "my_sender_id"; |
| 28 const char kSecondFakeAuthorizedEntity[] = "my_other_sender_id"; | 28 const char kSecondFakeAuthorizedEntity[] = "my_other_sender_id"; |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 EXPECT_FALSE(read_pair.IsInitialized()); | 507 EXPECT_FALSE(read_pair.IsInitialized()); |
| 508 | 508 |
| 509 // Now run the message loop. Both tasks should have finished executing. Due | 509 // Now run the message loop. Both tasks should have finished executing. Due |
| 510 // to the asynchronous nature of operations, however, we can't rely on the | 510 // to the asynchronous nature of operations, however, we can't rely on the |
| 511 // write to have finished before the read begins. | 511 // write to have finished before the read begins. |
| 512 base::RunLoop().RunUntilIdle(); | 512 base::RunLoop().RunUntilIdle(); |
| 513 | 513 |
| 514 EXPECT_TRUE(pair.IsInitialized()); | 514 EXPECT_TRUE(pair.IsInitialized()); |
| 515 } | 515 } |
| 516 | 516 |
| 517 #if !defined(NDEBUG) && DCHECK_IS_ON() | |
| 518 | |
| 519 TEST_F(GCMKeyStoreTest, CannotShareAppIdFromGCMToInstanceID) { | 517 TEST_F(GCMKeyStoreTest, CannotShareAppIdFromGCMToInstanceID) { |
| 520 KeyPair pair_unused; | 518 KeyPair pair_unused; |
| 521 std::string auth_secret_unused; | 519 std::string auth_secret_unused; |
| 522 gcm_key_store()->CreateKeys( | 520 gcm_key_store()->CreateKeys( |
| 523 kFakeAppId, "" /* empty authorized entity for non-InstanceID */, | 521 kFakeAppId, "" /* empty authorized entity for non-InstanceID */, |
| 524 base::Bind(&GCMKeyStoreTest::GotKeys, base::Unretained(this), | 522 base::Bind(&GCMKeyStoreTest::GotKeys, base::Unretained(this), |
| 525 &pair_unused, &auth_secret_unused)); | 523 &pair_unused, &auth_secret_unused)); |
| 526 | 524 |
| 527 base::RunLoop().RunUntilIdle(); | 525 base::RunLoop().RunUntilIdle(); |
| 528 | 526 |
| 529 static_assert(logging::LOG_DCHECK == logging::LOG_DFATAL, | 527 EXPECT_DCHECK_DEATH( |
| 530 "Unless these are equal, EXPECT_DFATAL will miss the DCHECK"); | |
| 531 EXPECT_DFATAL( | |
| 532 { | 528 { |
| 533 gcm_key_store()->CreateKeys( | 529 gcm_key_store()->CreateKeys( |
| 534 kFakeAppId, kFakeAuthorizedEntity, | 530 kFakeAppId, kFakeAuthorizedEntity, |
| 535 base::Bind(&GCMKeyStoreTest::GotKeys, base::Unretained(this), | 531 base::Bind(&GCMKeyStoreTest::GotKeys, base::Unretained(this), |
| 536 &pair_unused, &auth_secret_unused)); | 532 &pair_unused, &auth_secret_unused)); |
| 537 | 533 |
| 538 base::RunLoop().RunUntilIdle(); | 534 base::RunLoop().RunUntilIdle(); |
| 539 }, | 535 }); |
| 540 "Instance ID tokens cannot share an app_id with a non-InstanceID GCM " | |
| 541 "registration"); | |
| 542 } | 536 } |
| 543 | 537 |
| 544 TEST_F(GCMKeyStoreTest, CannotShareAppIdFromInstanceIDToGCM) { | 538 TEST_F(GCMKeyStoreTest, CannotShareAppIdFromInstanceIDToGCM) { |
| 545 KeyPair pair_unused; | 539 KeyPair pair_unused; |
| 546 std::string auth_secret_unused; | 540 std::string auth_secret_unused; |
| 547 gcm_key_store()->CreateKeys( | 541 gcm_key_store()->CreateKeys( |
| 548 kFakeAppId, kFakeAuthorizedEntity, | 542 kFakeAppId, kFakeAuthorizedEntity, |
| 549 base::Bind(&GCMKeyStoreTest::GotKeys, base::Unretained(this), | 543 base::Bind(&GCMKeyStoreTest::GotKeys, base::Unretained(this), |
| 550 &pair_unused, &auth_secret_unused)); | 544 &pair_unused, &auth_secret_unused)); |
| 551 | 545 |
| 552 base::RunLoop().RunUntilIdle(); | 546 base::RunLoop().RunUntilIdle(); |
| 553 | 547 |
| 554 gcm_key_store()->CreateKeys( | 548 gcm_key_store()->CreateKeys( |
| 555 kFakeAppId, kSecondFakeAuthorizedEntity, | 549 kFakeAppId, kSecondFakeAuthorizedEntity, |
| 556 base::Bind(&GCMKeyStoreTest::GotKeys, base::Unretained(this), | 550 base::Bind(&GCMKeyStoreTest::GotKeys, base::Unretained(this), |
| 557 &pair_unused, &auth_secret_unused)); | 551 &pair_unused, &auth_secret_unused)); |
| 558 | 552 |
| 559 base::RunLoop().RunUntilIdle(); | 553 base::RunLoop().RunUntilIdle(); |
| 560 | 554 |
| 561 static_assert(logging::LOG_DCHECK == logging::LOG_DFATAL, | 555 EXPECT_DCHECK_DEATH( |
| 562 "Unless these are equal, EXPECT_DFATAL will miss the DCHECK"); | |
| 563 EXPECT_DFATAL( | |
| 564 { | 556 { |
| 565 gcm_key_store()->CreateKeys( | 557 gcm_key_store()->CreateKeys( |
| 566 kFakeAppId, "" /* empty authorized entity for non-InstanceID */, | 558 kFakeAppId, "" /* empty authorized entity for non-InstanceID */, |
| 567 base::Bind(&GCMKeyStoreTest::GotKeys, base::Unretained(this), | 559 base::Bind(&GCMKeyStoreTest::GotKeys, base::Unretained(this), |
| 568 &pair_unused, &auth_secret_unused)); | 560 &pair_unused, &auth_secret_unused)); |
| 569 | 561 |
| 570 base::RunLoop().RunUntilIdle(); | 562 base::RunLoop().RunUntilIdle(); |
| 571 }, | 563 }); |
| 572 "Instance ID tokens cannot share an app_id with a non-InstanceID GCM " | |
| 573 "registration"); | |
| 574 } | 564 } |
| 575 | 565 |
| 576 #endif // !defined(NDEBUG) && DCHECK_IS_ON() | |
| 577 | |
| 578 } // namespace | 566 } // namespace |
| 579 | 567 |
| 580 } // namespace gcm | 568 } // namespace gcm |
| OLD | NEW |