diff options
author | Louis Collard <louiscollard@chromium.org> | 2019-10-14 17:50:16 +0800 |
---|---|---|
committer | Louis Collard <louiscollard@chromium.org> | 2019-10-17 23:54:22 +0000 |
commit | b4ca6adbb8b9698a9fc57150666c901207caf38c (patch) | |
tree | 4a7c2949b62868dc5bc046504908a98d3119a782 | |
parent | 7de8ab17fc3e6ea6943d7dc6d07c159176528f79 (diff) | |
download | platform_external_libbrillo-b4ca6adbb8b9698a9fc57150666c901207caf38c.tar.gz platform_external_libbrillo-b4ca6adbb8b9698a9fc57150666c901207caf38c.tar.bz2 platform_external_libbrillo-b4ca6adbb8b9698a9fc57150666c901207caf38c.zip |
libbrillo: Add method to retrieve Directory API ID
This will be used by the new allowlisting flow for the
Integrated U2F function.
BUG=b:135412897
TEST=unit tests, manual check of returned value on enterprise-enrolled DUT
Change-Id: I3568aa027792bca0ccea7dc5a610e5dd0aa362e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/1857281
Tested-by: Louis Collard <louiscollard@chromium.org>
Commit-Queue: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Maksim Ivanov <emaxx@chromium.org>
Cr-Mirrored-From: https://chromium.googlesource.com/chromiumos/platform2
Cr-Mirrored-Commit: 2cd6c6d4c90f7297b56255ee3b00a161575a6487
-rw-r--r-- | policy/device_policy.h | 6 | ||||
-rw-r--r-- | policy/device_policy_impl.cc | 9 | ||||
-rw-r--r-- | policy/device_policy_impl.h | 2 | ||||
-rw-r--r-- | policy/mock_device_policy.h | 1 | ||||
-rw-r--r-- | policy/tests/device_policy_impl_test.cc | 39 |
5 files changed, 49 insertions, 8 deletions
diff --git a/policy/device_policy.h b/policy/device_policy.h index 5cf75fb..29e1ed3 100644 --- a/policy/device_policy.h +++ b/policy/device_policy.h @@ -234,6 +234,12 @@ class DevicePolicy { virtual bool GetDeviceQuickFixBuildToken( std::string* device_quick_fix_build_token) const = 0; + // Writes the value of the Directory API ID to |directory_api_id_out|. + // Returns true on success, false if the ID is not available (eg if the device + // is not enrolled). + virtual bool GetDeviceDirectoryApiId( + std::string* directory_api_id_out) const = 0; + private: // Verifies that the policy signature is correct. virtual bool VerifyPolicySignature() = 0; diff --git a/policy/device_policy_impl.cc b/policy/device_policy_impl.cc index 6ba2974..958b7eb 100644 --- a/policy/device_policy_impl.cc +++ b/policy/device_policy_impl.cc @@ -690,6 +690,15 @@ bool DevicePolicyImpl::GetDeviceQuickFixBuildToken( return true; } +bool DevicePolicyImpl::GetDeviceDirectoryApiId( + std::string* directory_api_id_out) const { + if (!policy_data_.has_directory_api_id()) + return false; + + *directory_api_id_out = policy_data_.directory_api_id(); + return true; +} + bool DevicePolicyImpl::VerifyPolicyFile(const base::FilePath& policy_path) { if (!verify_root_ownership_) { return true; diff --git a/policy/device_policy_impl.h b/policy/device_policy_impl.h index d789ca3..47426df 100644 --- a/policy/device_policy_impl.h +++ b/policy/device_policy_impl.h @@ -86,6 +86,8 @@ class DevicePolicyImpl : public DevicePolicy { std::vector<DayPercentagePair> *staging_schedule_out) const override; bool GetDeviceQuickFixBuildToken( std::string* device_quick_fix_build_token) const override; + bool GetDeviceDirectoryApiId( + std::string* device_directory_api_out) const override; // Methods that can be used only for testing. void set_policy_data_for_testing( diff --git a/policy/mock_device_policy.h b/policy/mock_device_policy.h index 5cd9ce8..8bf4b07 100644 --- a/policy/mock_device_policy.h +++ b/policy/mock_device_policy.h @@ -117,6 +117,7 @@ class MockDevicePolicy : public DevicePolicy { GetDeviceQuickFixBuildToken, (std::string*), (const, override)); + MOCK_METHOD(bool, GetDeviceDirectoryApiId, (std::string*), (const, override)); MOCK_METHOD(bool, VerifyPolicySignature, (), (override)); }; } // namespace policy diff --git a/policy/tests/device_policy_impl_test.cc b/policy/tests/device_policy_impl_test.cc index ba1b1b7..2e68eb7 100644 --- a/policy/tests/device_policy_impl_test.cc +++ b/policy/tests/device_policy_impl_test.cc @@ -22,8 +22,8 @@ class DevicePolicyImplTest : public testing::Test, public DevicePolicyImpl { const em::ChromeDeviceSettingsProto& proto) { device_policy_.set_policy_for_testing(proto); device_policy_.set_install_attributes_for_testing( - std::make_unique<MockInstallAttributesReader>( - device_mode, true /* initialized */)); + std::make_unique<MockInstallAttributesReader>(device_mode, + true /* initialized */)); } DevicePolicyImpl device_policy_; @@ -183,7 +183,7 @@ TEST_F(DevicePolicyImplTest, GetRollbackAllowedMilestones_SetTooSmall) { // Update staging schedule has no values TEST_F(DevicePolicyImplTest, GetDeviceUpdateStagingSchedule_NoValues) { em::ChromeDeviceSettingsProto device_policy_proto; - em::AutoUpdateSettingsProto *auto_update_settings = + em::AutoUpdateSettingsProto* auto_update_settings = device_policy_proto.mutable_auto_update_settings(); auto_update_settings->set_staging_schedule("[]"); InitializePolicy(InstallAttributesReader::kDeviceModeEnterprise, @@ -197,7 +197,7 @@ TEST_F(DevicePolicyImplTest, GetDeviceUpdateStagingSchedule_NoValues) { // Update staging schedule has valid values TEST_F(DevicePolicyImplTest, GetDeviceUpdateStagingSchedule_Valid) { em::ChromeDeviceSettingsProto device_policy_proto; - em::AutoUpdateSettingsProto *auto_update_settings = + em::AutoUpdateSettingsProto* auto_update_settings = device_policy_proto.mutable_auto_update_settings(); auto_update_settings->set_staging_schedule( "[{\"days\": 4, \"percentage\": 40}, {\"days\": 10, \"percentage\": " @@ -214,7 +214,7 @@ TEST_F(DevicePolicyImplTest, GetDeviceUpdateStagingSchedule_Valid) { // Update staging schedule has valid values, set using AD. TEST_F(DevicePolicyImplTest, GetDeviceUpdateStagingSchedule_Valid_AD) { em::ChromeDeviceSettingsProto device_policy_proto; - em::AutoUpdateSettingsProto *auto_update_settings = + em::AutoUpdateSettingsProto* auto_update_settings = device_policy_proto.mutable_auto_update_settings(); auto_update_settings->set_staging_schedule( "[{\"days\": 4, \"percentage\": 40}, {\"days\": 10, \"percentage\": " @@ -233,7 +233,7 @@ TEST_F(DevicePolicyImplTest, GetDeviceUpdateStagingSchedule_Valid_AD) { TEST_F(DevicePolicyImplTest, GetDeviceUpdateStagingSchedule_SetOutsideAllowable) { em::ChromeDeviceSettingsProto device_policy_proto; - em::AutoUpdateSettingsProto *auto_update_settings = + em::AutoUpdateSettingsProto* auto_update_settings = device_policy_proto.mutable_auto_update_settings(); auto_update_settings->set_staging_schedule( "[{\"days\": -1, \"percentage\": -10}, {\"days\": 30, \"percentage\": " @@ -243,8 +243,8 @@ TEST_F(DevicePolicyImplTest, std::vector<DayPercentagePair> staging_schedule; ASSERT_TRUE(device_policy_.GetDeviceUpdateStagingSchedule(&staging_schedule)); - EXPECT_THAT(staging_schedule, ElementsAre(DayPercentagePair{1, 0}, - DayPercentagePair{28, 100})); + EXPECT_THAT(staging_schedule, + ElementsAre(DayPercentagePair{1, 0}, DayPercentagePair{28, 100})); } // Updates should only be disabled for enterprise managed devices. @@ -334,4 +334,27 @@ TEST_F(DevicePolicyImplTest, GetDeviceQuickFixBuildToken_NotSet) { EXPECT_TRUE(value.empty()); } +// Should only write a value and return true if the ID is present. +TEST_F(DevicePolicyImplTest, GetDeviceDirectoryApiId_Set) { + constexpr char kDummyDeviceId[] = "aa-bb-cc-dd"; + + em::PolicyData policy_data; + policy_data.set_directory_api_id(kDummyDeviceId); + + device_policy_.set_policy_data_for_testing(policy_data); + + std::string id; + EXPECT_TRUE(device_policy_.GetDeviceDirectoryApiId(&id)); + EXPECT_EQ(kDummyDeviceId, id); +} + +TEST_F(DevicePolicyImplTest, GetDeviceDirectoryApiId_NotSet) { + em::PolicyData policy_data; + device_policy_.set_policy_data_for_testing(policy_data); + + std::string id; + EXPECT_FALSE(device_policy_.GetDeviceDirectoryApiId(&id)); + EXPECT_TRUE(id.empty()); +} + } // namespace policy |