| 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 "base/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 PolicyService* policy_service = GetPolicyService(); | 266 PolicyService* policy_service = GetPolicyService(); |
| 267 { | 267 { |
| 268 base::RunLoop run_loop; | 268 base::RunLoop run_loop; |
| 269 // This does the initial fetch and stores the initial key. | 269 // This does the initial fetch and stores the initial key. |
| 270 policy_service->RefreshPolicies(run_loop.QuitClosure()); | 270 policy_service->RefreshPolicies(run_loop.QuitClosure()); |
| 271 run_loop.Run(); | 271 run_loop.Run(); |
| 272 } | 272 } |
| 273 | 273 |
| 274 // Read the initial key. | 274 // Read the initial key. |
| 275 std::string initial_key; | 275 std::string initial_key; |
| 276 ASSERT_TRUE( | 276 ASSERT_TRUE(base::ReadFileToString(user_policy_key_file_, &initial_key)); |
| 277 file_util::ReadFileToString(user_policy_key_file_, &initial_key)); | |
| 278 | 277 |
| 279 PolicyMap empty; | 278 PolicyMap empty; |
| 280 EXPECT_TRUE(empty.Equals(policy_service->GetPolicies( | 279 EXPECT_TRUE(empty.Equals(policy_service->GetPolicies( |
| 281 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); | 280 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); |
| 282 | 281 |
| 283 // Set the new policies and a new key at the server. | 282 // Set the new policies and a new key at the server. |
| 284 ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetTestPolicy(1))); | 283 ASSERT_NO_FATAL_FAILURE(SetServerPolicy(GetTestPolicy(1))); |
| 285 PolicyMap expected; | 284 PolicyMap expected; |
| 286 GetExpectedTestPolicy(&expected); | 285 GetExpectedTestPolicy(&expected); |
| 287 { | 286 { |
| 288 base::RunLoop run_loop; | 287 base::RunLoop run_loop; |
| 289 // This fetches the new policies and does a key rotation. | 288 // This fetches the new policies and does a key rotation. |
| 290 policy_service->RefreshPolicies(run_loop.QuitClosure()); | 289 policy_service->RefreshPolicies(run_loop.QuitClosure()); |
| 291 run_loop.Run(); | 290 run_loop.Run(); |
| 292 } | 291 } |
| 293 EXPECT_TRUE(expected.Equals(policy_service->GetPolicies( | 292 EXPECT_TRUE(expected.Equals(policy_service->GetPolicies( |
| 294 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); | 293 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); |
| 295 | 294 |
| 296 // Verify that the key was rotated. | 295 // Verify that the key was rotated. |
| 297 std::string rotated_key; | 296 std::string rotated_key; |
| 298 ASSERT_TRUE( | 297 ASSERT_TRUE(base::ReadFileToString(user_policy_key_file_, &rotated_key)); |
| 299 file_util::ReadFileToString(user_policy_key_file_, &rotated_key)); | |
| 300 EXPECT_NE(rotated_key, initial_key); | 298 EXPECT_NE(rotated_key, initial_key); |
| 301 | 299 |
| 302 // Another refresh using the same key won't rotate it again. | 300 // Another refresh using the same key won't rotate it again. |
| 303 { | 301 { |
| 304 base::RunLoop run_loop; | 302 base::RunLoop run_loop; |
| 305 policy_service->RefreshPolicies(run_loop.QuitClosure()); | 303 policy_service->RefreshPolicies(run_loop.QuitClosure()); |
| 306 run_loop.Run(); | 304 run_loop.Run(); |
| 307 } | 305 } |
| 308 EXPECT_TRUE(expected.Equals(policy_service->GetPolicies( | 306 EXPECT_TRUE(expected.Equals(policy_service->GetPolicies( |
| 309 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); | 307 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())))); |
| 310 std::string current_key; | 308 std::string current_key; |
| 311 ASSERT_TRUE( | 309 ASSERT_TRUE(base::ReadFileToString(user_policy_key_file_, ¤t_key)); |
| 312 file_util::ReadFileToString(user_policy_key_file_, ¤t_key)); | |
| 313 EXPECT_EQ(rotated_key, current_key); | 310 EXPECT_EQ(rotated_key, current_key); |
| 314 } | 311 } |
| 315 #endif | 312 #endif |
| 316 | 313 |
| 317 TEST(CloudPolicyProtoTest, VerifyProtobufEquivalence) { | 314 TEST(CloudPolicyProtoTest, VerifyProtobufEquivalence) { |
| 318 // There are 2 protobufs that can be used for user cloud policy: | 315 // There are 2 protobufs that can be used for user cloud policy: |
| 319 // cloud_policy.proto and chrome_settings.proto. chrome_settings.proto is the | 316 // cloud_policy.proto and chrome_settings.proto. chrome_settings.proto is the |
| 320 // version used by the server, but generates one proto message per policy; to | 317 // version used by the server, but generates one proto message per policy; to |
| 321 // save binary size on the client, the other version shares proto messages for | 318 // save binary size on the client, the other version shares proto messages for |
| 322 // policies of the same type. They generate the same bytes on the wire though, | 319 // policies of the same type. They generate the same bytes on the wire though, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 354 |
| 358 // They should now serialize to the same bytes. | 355 // They should now serialize to the same bytes. |
| 359 std::string chrome_settings_serialized; | 356 std::string chrome_settings_serialized; |
| 360 std::string cloud_policy_serialized; | 357 std::string cloud_policy_serialized; |
| 361 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized)); | 358 ASSERT_TRUE(chrome_settings.SerializeToString(&chrome_settings_serialized)); |
| 362 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized)); | 359 ASSERT_TRUE(cloud_policy.SerializeToString(&cloud_policy_serialized)); |
| 363 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized); | 360 EXPECT_EQ(chrome_settings_serialized, cloud_policy_serialized); |
| 364 } | 361 } |
| 365 | 362 |
| 366 } // namespace policy | 363 } // namespace policy |
| OLD | NEW |