request_handler_for_check_android_management_unittest.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "components/policy/test_support/request_handler_for_check_android_management.h"
  5. #include <utility>
  6. #include "components/policy/core/common/cloud/cloud_policy_constants.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 "net/http/http_status_code.h"
  10. #include "testing/gtest/include/gtest/gtest.h"
  11. namespace policy {
  12. namespace {
  13. constexpr char kDeviceId[] = "fake_device_id";
  14. } // namespace
  15. class RequestHandlerForCheckAndroidManagementTest
  16. : public EmbeddedPolicyTestServerTestBase {
  17. public:
  18. RequestHandlerForCheckAndroidManagementTest() = default;
  19. ~RequestHandlerForCheckAndroidManagementTest() override = default;
  20. void SetUp() override {
  21. EmbeddedPolicyTestServerTestBase::SetUp();
  22. SetRequestTypeParam(dm_protocol::kValueRequestCheckAndroidManagement);
  23. SetAppType(dm_protocol::kValueAppType);
  24. SetDeviceIdParam(kDeviceId);
  25. SetDeviceType(dm_protocol::kValueDeviceType);
  26. }
  27. };
  28. TEST_F(RequestHandlerForCheckAndroidManagementTest, HandleRequest_Success) {
  29. SetOAuthToken(kUnmanagedAuthToken);
  30. StartRequestAndWait();
  31. EXPECT_EQ(GetResponseCode(), net::HTTP_OK);
  32. ASSERT_TRUE(HasResponseBody());
  33. auto response = GetDeviceManagementResponse();
  34. EXPECT_TRUE(response.has_check_android_management_response());
  35. }
  36. TEST_F(RequestHandlerForCheckAndroidManagementTest, HandleRequest_Conflict) {
  37. SetOAuthToken(kManagedAuthToken);
  38. StartRequestAndWait();
  39. EXPECT_EQ(GetResponseCode(), net::HTTP_CONFLICT);
  40. }
  41. TEST_F(RequestHandlerForCheckAndroidManagementTest, HandleRequest_Forbidden) {
  42. SetOAuthToken("invalid-auth-token");
  43. StartRequestAndWait();
  44. EXPECT_EQ(GetResponseCode(), net::HTTP_FORBIDDEN);
  45. }
  46. } // namespace policy