request_handler_for_device_attribute_update_permission_unittest.cc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2021 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 "base/strings/strcat.h"
  5. #include "components/policy/core/common/cloud/cloud_policy_constants.h"
  6. #include "components/policy/test_support/client_storage.h"
  7. #include "components/policy/test_support/embedded_policy_test_server_test_base.h"
  8. #include "components/policy/test_support/policy_storage.h"
  9. #include "components/policy/test_support/request_handler_for_register_browser.h"
  10. #include "device_management_backend.pb.h"
  11. #include "net/http/http_status_code.h"
  12. #include "testing/gmock/include/gmock/gmock.h"
  13. #include "testing/gtest/include/gtest/gtest.h"
  14. namespace em = enterprise_management;
  15. namespace policy {
  16. namespace {
  17. constexpr char kDeviceId[] = "fake_device_id";
  18. } // namespace
  19. class RequestHandlerForDeviceAttributeUpdatePermissionTest
  20. : public EmbeddedPolicyTestServerTestBase {
  21. protected:
  22. RequestHandlerForDeviceAttributeUpdatePermissionTest() = default;
  23. ~RequestHandlerForDeviceAttributeUpdatePermissionTest() override = default;
  24. void SetUp() override {
  25. EmbeddedPolicyTestServerTestBase::SetUp();
  26. SetRequestTypeParam(
  27. dm_protocol::kValueRequestDeviceAttributeUpdatePermission);
  28. SetAppType(dm_protocol::kValueAppType);
  29. SetDeviceIdParam(kDeviceId);
  30. SetDeviceType(dm_protocol::kValueDeviceType);
  31. }
  32. };
  33. TEST_F(RequestHandlerForDeviceAttributeUpdatePermissionTest,
  34. HandleRequest_Allowed) {
  35. policy_storage()->set_allow_set_device_attributes(true);
  36. em::DeviceManagementRequest device_management_request;
  37. SetPayload(device_management_request);
  38. StartRequestAndWait();
  39. EXPECT_EQ(GetResponseCode(), net::HTTP_OK);
  40. ASSERT_TRUE(HasResponseBody());
  41. auto response = GetDeviceManagementResponse();
  42. EXPECT_EQ(
  43. response.device_attribute_update_permission_response().result(),
  44. em::DeviceAttributeUpdatePermissionResponse::ATTRIBUTE_UPDATE_ALLOWED);
  45. }
  46. TEST_F(RequestHandlerForDeviceAttributeUpdatePermissionTest,
  47. HandleRequest_Disallowed) {
  48. policy_storage()->set_allow_set_device_attributes(false);
  49. em::DeviceManagementRequest device_management_request;
  50. SetPayload(device_management_request);
  51. StartRequestAndWait();
  52. EXPECT_EQ(GetResponseCode(), net::HTTP_OK);
  53. ASSERT_TRUE(HasResponseBody());
  54. auto response = GetDeviceManagementResponse();
  55. EXPECT_EQ(
  56. response.device_attribute_update_permission_response().result(),
  57. em::DeviceAttributeUpdatePermissionResponse::ATTRIBUTE_UPDATE_DISALLOWED);
  58. }
  59. } // namespace policy