enterprise_authentication_app_link_policy_handler_unittest.cc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "android_webview/browser/enterprise_authentication_app_link_policy_handler.h"
  5. #include "base/json/json_reader.h"
  6. #include "components/policy/core/browser/configuration_policy_pref_store.h"
  7. #include "components/policy/core/browser/configuration_policy_pref_store_test.h"
  8. #include "components/policy/core/common/policy_map.h"
  9. #include "components/policy/core/common/policy_pref_names.h"
  10. #include "components/policy/policy_constants.h"
  11. namespace policy {
  12. class EnterpriseAuthenticationAppLinkPolicyHandlerTest
  13. : public ConfigurationPolicyPrefStoreTest {
  14. void SetUp() override {
  15. Schema chrome_schema = Schema::Wrap(policy::GetChromeSchemaData());
  16. handler_list_.AddHandler(base::WrapUnique<ConfigurationPolicyHandler>(
  17. new EnterpriseAuthenticationAppLinkPolicyHandler(
  18. policy::key::kEnterpriseAuthenticationAppLinkPolicy,
  19. android_webview::prefs::kEnterpriseAuthAppLinkPolicy)));
  20. }
  21. };
  22. TEST_F(EnterpriseAuthenticationAppLinkPolicyHandlerTest, ValidPolicy) {
  23. PolicyMap policy;
  24. policy.Set(policy::key::kEnterpriseAuthenticationAppLinkPolicy,
  25. POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_PLATFORM,
  26. base::JSONReader::Read(
  27. "["
  28. " {"
  29. " \"url\": \"https://www.testserver1.com/login\""
  30. " },"
  31. " {"
  32. " \"url\": \"https://www.testserver2.com/login\""
  33. " }"
  34. "]"),
  35. nullptr);
  36. this->UpdateProviderPolicy(policy);
  37. const base::Value* pref_value = nullptr;
  38. absl::optional<base::Value> expected = base::JSONReader::Read(R"(
  39. [
  40. "https://www.testserver1.com/login",
  41. "https://www.testserver2.com/login"
  42. ]
  43. )");
  44. EXPECT_TRUE(store_->GetValue(
  45. android_webview::prefs::kEnterpriseAuthAppLinkPolicy, &pref_value));
  46. ASSERT_TRUE(pref_value);
  47. EXPECT_EQ(expected, *pref_value);
  48. }
  49. TEST_F(EnterpriseAuthenticationAppLinkPolicyHandlerTest, InvalidPolicy) {
  50. PolicyMap policy;
  51. policy.Set(policy::key::kEnterpriseAuthenticationAppLinkPolicy,
  52. POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_PLATFORM,
  53. base::JSONReader::Read(
  54. "["
  55. " {"
  56. " \"abc\": \"https://www.testserver1.com/login\""
  57. " },"
  58. "]"),
  59. nullptr);
  60. this->UpdateProviderPolicy(policy);
  61. const base::Value* pref_value = nullptr;
  62. EXPECT_FALSE(store_->GetValue(
  63. android_webview::prefs::kEnterpriseAuthAppLinkPolicy, &pref_value));
  64. ASSERT_FALSE(pref_value);
  65. }
  66. } // namespace policy