request_handler_for_device_initial_enrollment_state_unittest.cc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. constexpr char kBrandCode[] = "Google Pixel";
  19. constexpr char kSerialNumber[] = "AXD123145";
  20. constexpr char kManagementDomain[] = "example.com";
  21. } // namespace
  22. class RequestHandlerForDeviceInitialEnrollmentStateTest
  23. : public EmbeddedPolicyTestServerTestBase {
  24. protected:
  25. RequestHandlerForDeviceInitialEnrollmentStateTest() = default;
  26. ~RequestHandlerForDeviceInitialEnrollmentStateTest() override = default;
  27. void SetUp() override {
  28. EmbeddedPolicyTestServerTestBase::SetUp();
  29. SetRequestTypeParam(
  30. dm_protocol::kValueRequestInitialEnrollmentStateRetrieval);
  31. SetAppType(dm_protocol::kValueAppType);
  32. SetDeviceIdParam(kDeviceId);
  33. SetDeviceType(dm_protocol::kValueDeviceType);
  34. }
  35. };
  36. TEST_F(RequestHandlerForDeviceInitialEnrollmentStateTest, HandleRequest) {
  37. policy_storage()->SetInitialEnrollmentState(
  38. base::StrCat({kBrandCode, "_", kSerialNumber}),
  39. PolicyStorage::InitialEnrollmentState{
  40. .initial_enrollment_mode = em::DeviceInitialEnrollmentStateResponse::
  41. INITIAL_ENROLLMENT_MODE_ZERO_TOUCH_ENFORCED,
  42. .management_domain = kManagementDomain});
  43. em::DeviceManagementRequest device_management_request;
  44. em::DeviceInitialEnrollmentStateRequest* enrollment_request =
  45. device_management_request
  46. .mutable_device_initial_enrollment_state_request();
  47. enrollment_request->set_brand_code(kBrandCode);
  48. enrollment_request->set_serial_number(kSerialNumber);
  49. SetPayload(device_management_request);
  50. StartRequestAndWait();
  51. EXPECT_EQ(GetResponseCode(), net::HTTP_OK);
  52. ASSERT_TRUE(HasResponseBody());
  53. auto response = GetDeviceManagementResponse();
  54. EXPECT_EQ(response.device_initial_enrollment_state_response()
  55. .initial_enrollment_mode(),
  56. em::DeviceInitialEnrollmentStateResponse::
  57. INITIAL_ENROLLMENT_MODE_ZERO_TOUCH_ENFORCED);
  58. EXPECT_EQ(
  59. response.device_initial_enrollment_state_response().management_domain(),
  60. kManagementDomain);
  61. }
  62. } // namespace policy