summaryrefslogtreecommitdiff
path: root/chromium/components/policy/test_support/request_handler_for_device_attribute_update_permission_unittest.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2022-06-22 09:53:13 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2022-06-22 10:23:17 +0000
commitc5dbcb143405a38088d78b4b760d64aaff5157ab (patch)
treeb37edca540b35f898e212bebfa6ded0806988122 /chromium/components/policy/test_support/request_handler_for_device_attribute_update_permission_unittest.cc
parent774f54339e5db91f785733232d3950366db65d07 (diff)
downloadqtwebengine-chromium-c5dbcb143405a38088d78b4b760d64aaff5157ab.tar.gz
BASELINE: Update Chromium to 102.0.5005.137
Change-Id: I162cdc7f56760218868e000a4c8ea92573344036 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/policy/test_support/request_handler_for_device_attribute_update_permission_unittest.cc')
-rw-r--r--chromium/components/policy/test_support/request_handler_for_device_attribute_update_permission_unittest.cc79
1 files changed, 79 insertions, 0 deletions
diff --git a/chromium/components/policy/test_support/request_handler_for_device_attribute_update_permission_unittest.cc b/chromium/components/policy/test_support/request_handler_for_device_attribute_update_permission_unittest.cc
new file mode 100644
index 00000000000..64444c2f6f9
--- /dev/null
+++ b/chromium/components/policy/test_support/request_handler_for_device_attribute_update_permission_unittest.cc
@@ -0,0 +1,79 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/strings/strcat.h"
+#include "components/policy/core/common/cloud/cloud_policy_constants.h"
+#include "components/policy/test_support/client_storage.h"
+#include "components/policy/test_support/embedded_policy_test_server_test_base.h"
+#include "components/policy/test_support/policy_storage.h"
+#include "components/policy/test_support/request_handler_for_register_browser.h"
+#include "device_management_backend.pb.h"
+#include "net/http/http_status_code.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace em = enterprise_management;
+
+namespace policy {
+
+namespace {
+
+constexpr char kDeviceId[] = "fake_device_id";
+
+} // namespace
+
+class RequestHandlerForDeviceAttributeUpdatePermissionTest
+ : public EmbeddedPolicyTestServerTestBase {
+ protected:
+ RequestHandlerForDeviceAttributeUpdatePermissionTest() = default;
+ ~RequestHandlerForDeviceAttributeUpdatePermissionTest() override = default;
+
+ void SetUp() override {
+ EmbeddedPolicyTestServerTestBase::SetUp();
+
+ SetRequestTypeParam(
+ dm_protocol::kValueRequestDeviceAttributeUpdatePermission);
+ SetAppType(dm_protocol::kValueAppType);
+ SetDeviceIdParam(kDeviceId);
+ SetDeviceType(dm_protocol::kValueDeviceType);
+ }
+};
+
+TEST_F(RequestHandlerForDeviceAttributeUpdatePermissionTest,
+ HandleRequest_Allowed) {
+ policy_storage()->set_allow_set_device_attributes(true);
+
+ em::DeviceManagementRequest device_management_request;
+ SetPayload(device_management_request);
+
+ StartRequestAndWait();
+
+ EXPECT_EQ(GetResponseCode(), net::HTTP_OK);
+
+ ASSERT_TRUE(HasResponseBody());
+ auto response = GetDeviceManagementResponse();
+ EXPECT_EQ(
+ response.device_attribute_update_permission_response().result(),
+ em::DeviceAttributeUpdatePermissionResponse::ATTRIBUTE_UPDATE_ALLOWED);
+}
+
+TEST_F(RequestHandlerForDeviceAttributeUpdatePermissionTest,
+ HandleRequest_Disallowed) {
+ policy_storage()->set_allow_set_device_attributes(false);
+
+ em::DeviceManagementRequest device_management_request;
+ SetPayload(device_management_request);
+
+ StartRequestAndWait();
+
+ EXPECT_EQ(GetResponseCode(), net::HTTP_OK);
+
+ ASSERT_TRUE(HasResponseBody());
+ auto response = GetDeviceManagementResponse();
+ EXPECT_EQ(
+ response.device_attribute_update_permission_response().result(),
+ em::DeviceAttributeUpdatePermissionResponse::ATTRIBUTE_UPDATE_DISALLOWED);
+}
+
+} // namespace policy