| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/policy/user_cloud_policy_store_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 private: | 232 private: |
| 233 content::TestBrowserThread ui_thread_; | 233 content::TestBrowserThread ui_thread_; |
| 234 content::TestBrowserThread file_thread_; | 234 content::TestBrowserThread file_thread_; |
| 235 base::ScopedTempDir tmp_dir_; | 235 base::ScopedTempDir tmp_dir_; |
| 236 | 236 |
| 237 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyStoreChromeOSTest); | 237 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyStoreChromeOSTest); |
| 238 }; | 238 }; |
| 239 | 239 |
| 240 TEST_F(UserCloudPolicyStoreChromeOSTest, InitialStore) { | 240 TEST_F(UserCloudPolicyStoreChromeOSTest, InitialStore) { |
| 241 // Start without any public key to trigger the initial key checks. | 241 // Start without any public key to trigger the initial key checks. |
| 242 ASSERT_TRUE(base::Delete(user_policy_key_file(), false)); | 242 ASSERT_TRUE(base::DeleteFile(user_policy_key_file(), false)); |
| 243 // Make the policy blob contain a new public key. | 243 // Make the policy blob contain a new public key. |
| 244 policy_.set_new_signing_key(PolicyBuilder::CreateTestNewSigningKey()); | 244 policy_.set_new_signing_key(PolicyBuilder::CreateTestNewSigningKey()); |
| 245 policy_.Build(); | 245 policy_.Build(); |
| 246 std::vector<uint8> new_public_key; | 246 std::vector<uint8> new_public_key; |
| 247 ASSERT_TRUE(policy_.new_signing_key()->ExportPublicKey(&new_public_key)); | 247 ASSERT_TRUE(policy_.new_signing_key()->ExportPublicKey(&new_public_key)); |
| 248 ASSERT_NO_FATAL_FAILURE( | 248 ASSERT_NO_FATAL_FAILURE( |
| 249 PerformStorePolicy(&new_public_key, NULL, kDefaultHomepage)); | 249 PerformStorePolicy(&new_public_key, NULL, kDefaultHomepage)); |
| 250 } | 250 } |
| 251 | 251 |
| 252 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithExistingKey) { | 252 TEST_F(UserCloudPolicyStoreChromeOSTest, StoreWithExistingKey) { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 policy_.policy_data().clear_policy_type(); | 376 policy_.policy_data().clear_policy_type(); |
| 377 policy_.Build(); | 377 policy_.Build(); |
| 378 | 378 |
| 379 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); | 379 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); |
| 380 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob())); | 380 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob())); |
| 381 VerifyStoreHasValidationError(); | 381 VerifyStoreHasValidationError(); |
| 382 } | 382 } |
| 383 | 383 |
| 384 TEST_F(UserCloudPolicyStoreChromeOSTest, LoadNoKey) { | 384 TEST_F(UserCloudPolicyStoreChromeOSTest, LoadNoKey) { |
| 385 // The loaded policy can't be verified without the public key. | 385 // The loaded policy can't be verified without the public key. |
| 386 ASSERT_TRUE(base::Delete(user_policy_key_file(), false)); | 386 ASSERT_TRUE(base::DeleteFile(user_policy_key_file(), false)); |
| 387 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); | 387 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); |
| 388 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob())); | 388 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob())); |
| 389 VerifyStoreHasValidationError(); | 389 VerifyStoreHasValidationError(); |
| 390 } | 390 } |
| 391 | 391 |
| 392 TEST_F(UserCloudPolicyStoreChromeOSTest, LoadInvalidSignature) { | 392 TEST_F(UserCloudPolicyStoreChromeOSTest, LoadInvalidSignature) { |
| 393 // Break the signature. | 393 // Break the signature. |
| 394 policy_.policy().mutable_policy_data_signature()->append("garbage"); | 394 policy_.policy().mutable_policy_data_signature()->append("garbage"); |
| 395 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); | 395 ExpectError(CloudPolicyStore::STATUS_VALIDATION_ERROR); |
| 396 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob())); | 396 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad(policy_.GetBlob())); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 expected_policy_data.set_device_id(kLegacyDeviceId); | 473 expected_policy_data.set_device_id(kLegacyDeviceId); |
| 474 ASSERT_TRUE(store_->policy()); | 474 ASSERT_TRUE(store_->policy()); |
| 475 EXPECT_EQ(expected_policy_data.SerializeAsString(), | 475 EXPECT_EQ(expected_policy_data.SerializeAsString(), |
| 476 store_->policy()->SerializeAsString()); | 476 store_->policy()->SerializeAsString()); |
| 477 EXPECT_TRUE(store_->policy_map().empty()); | 477 EXPECT_TRUE(store_->policy_map().empty()); |
| 478 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); | 478 EXPECT_EQ(CloudPolicyStore::STATUS_OK, store_->status()); |
| 479 } | 479 } |
| 480 | 480 |
| 481 TEST_F(UserCloudPolicyStoreChromeOSTest, MigrationAndStoreNew) { | 481 TEST_F(UserCloudPolicyStoreChromeOSTest, MigrationAndStoreNew) { |
| 482 // Start without an existing public key. | 482 // Start without an existing public key. |
| 483 ASSERT_TRUE(base::Delete(user_policy_key_file(), false)); | 483 ASSERT_TRUE(base::DeleteFile(user_policy_key_file(), false)); |
| 484 | 484 |
| 485 std::string data; | 485 std::string data; |
| 486 em::CachedCloudPolicyResponse cached_policy; | 486 em::CachedCloudPolicyResponse cached_policy; |
| 487 cached_policy.mutable_cloud_policy()->CopyFrom(policy_.policy()); | 487 cached_policy.mutable_cloud_policy()->CopyFrom(policy_.policy()); |
| 488 ASSERT_TRUE(cached_policy.SerializeToString(&data)); | 488 ASSERT_TRUE(cached_policy.SerializeToString(&data)); |
| 489 ASSERT_NE(-1, file_util::WriteFile(policy_file(), data.c_str(), data.size())); | 489 ASSERT_NE(-1, file_util::WriteFile(policy_file(), data.c_str(), data.size())); |
| 490 | 490 |
| 491 EXPECT_CALL(observer_, OnStoreLoaded(store_.get())); | 491 EXPECT_CALL(observer_, OnStoreLoaded(store_.get())); |
| 492 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad("")); | 492 ASSERT_NO_FATAL_FAILURE(PerformPolicyLoad("")); |
| 493 Mock::VerifyAndClearExpectations(&observer_); | 493 Mock::VerifyAndClearExpectations(&observer_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 515 PerformStorePolicy(&new_public_key, kDefaultHomepage, kNewHomepage)); | 515 PerformStorePolicy(&new_public_key, kDefaultHomepage, kNewHomepage)); |
| 516 VerifyPolicyMap(kNewHomepage); | 516 VerifyPolicyMap(kNewHomepage); |
| 517 | 517 |
| 518 // Verify that the legacy cache has been removed. | 518 // Verify that the legacy cache has been removed. |
| 519 EXPECT_FALSE(base::PathExists(policy_file())); | 519 EXPECT_FALSE(base::PathExists(policy_file())); |
| 520 } | 520 } |
| 521 | 521 |
| 522 } // namespace | 522 } // namespace |
| 523 | 523 |
| 524 } // namespace policy | 524 } // namespace policy |
| OLD | NEW |