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/policy/cloud/component_cloud_policy_service.h" | 5 #include "chrome/browser/policy/cloud/component_cloud_policy_service.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 "{" | 50 "{" |
51 " \"Name\": {" | 51 " \"Name\": {" |
52 " \"Value\": \"disabled\"" | 52 " \"Value\": \"disabled\"" |
53 " }," | 53 " }," |
54 " \"Second\": {" | 54 " \"Second\": {" |
55 " \"Value\": \"maybe\"," | 55 " \"Value\": \"maybe\"," |
56 " \"Level\": \"Recommended\"" | 56 " \"Level\": \"Recommended\"" |
57 " }" | 57 " }" |
58 "}"; | 58 "}"; |
59 | 59 |
| 60 const char kInvalidTestPolicy[] = |
| 61 "{" |
| 62 " \"Name\": {" |
| 63 " \"Value\": \"published\"" |
| 64 " }," |
| 65 " \"Undeclared Name\": {" |
| 66 " \"Value\": \"not published\"" |
| 67 " }" |
| 68 "}"; |
| 69 |
60 const char kTestSchema[] = | 70 const char kTestSchema[] = |
61 "{" | 71 "{" |
62 " \"type\": \"object\"," | 72 " \"type\": \"object\"," |
63 " \"properties\": {" | 73 " \"properties\": {" |
64 " \"Name\": { \"type\": \"string\" }," | 74 " \"Name\": { \"type\": \"string\" }," |
65 " \"Second\": { \"type\": \"string\" }" | 75 " \"Second\": { \"type\": \"string\" }" |
66 " }" | 76 " }" |
67 "}"; | 77 "}"; |
68 | 78 |
69 class MockComponentCloudPolicyDelegate | 79 class MockComponentCloudPolicyDelegate |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 store_.policy_.reset(); | 519 store_.policy_.reset(); |
510 store_.NotifyStoreLoaded(); | 520 store_.NotifyStoreLoaded(); |
511 RunUntilIdle(); | 521 RunUntilIdle(); |
512 Mock::VerifyAndClearExpectations(&delegate_); | 522 Mock::VerifyAndClearExpectations(&delegate_); |
513 const PolicyBundle empty_bundle; | 523 const PolicyBundle empty_bundle; |
514 EXPECT_TRUE(service_->policy().Equals(empty_bundle)); | 524 EXPECT_TRUE(service_->policy().Equals(empty_bundle)); |
515 cache_->LoadAllSubkeys("extension-policy", &contents); | 525 cache_->LoadAllSubkeys("extension-policy", &contents); |
516 ASSERT_EQ(0u, contents.size()); | 526 ASSERT_EQ(0u, contents.size()); |
517 } | 527 } |
518 | 528 |
| 529 TEST_F(ComponentCloudPolicyServiceTest, LoadInvalidPolicyFromCache) { |
| 530 // Put the invalid test policy in the cache. One of its policies will be |
| 531 // loaded, the other should be filtered out by the schema. |
| 532 builder_.payload().set_secure_hash(base::SHA1HashString(kInvalidTestPolicy)); |
| 533 EXPECT_TRUE(cache_->Store( |
| 534 "extension-policy", kTestExtension, CreateSerializedResponse())); |
| 535 EXPECT_TRUE(cache_->Store( |
| 536 "extension-policy-data", kTestExtension, kInvalidTestPolicy)); |
| 537 |
| 538 LoadStore(); |
| 539 InitializeRegistry(); |
| 540 |
| 541 // The initial, cached policy will be served once the backend is initialized. |
| 542 EXPECT_CALL(delegate_, OnComponentCloudPolicyUpdated()); |
| 543 RunUntilIdle(); |
| 544 Mock::VerifyAndClearExpectations(&delegate_); |
| 545 |
| 546 PolicyBundle expected_bundle; |
| 547 const PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension); |
| 548 expected_bundle.Get(ns).Set("Name", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 549 base::Value::CreateStringValue("published"), |
| 550 NULL); |
| 551 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); |
| 552 } |
| 553 |
519 } // namespace policy | 554 } // namespace policy |
OLD | NEW |