Commit fb33c714 authored by Robin Lewis's avatar Robin Lewis Committed by Commit Bot

Store device resource id returned in UploadDeviceDetails response.

Also add this to future requests when it's available.

Bug: 1043199
Change-Id: I466bd42d221aaf7f961f702e12306b12cae1de04
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2096108Reviewed-by: default avatarRakesh Soma <rakeshsoma@google.com>
Commit-Queue: Robin Lewis <wrlewis@google.com>
Cr-Commit-Position: refs/heads/master@{#748760}
parent fcb09214
...@@ -2641,6 +2641,7 @@ INSTANTIATE_TEST_SUITE_P(All, ...@@ -2641,6 +2641,7 @@ INSTANTIATE_TEST_SUITE_P(All,
// 1. Fails the upload device details call due to network timeout. // 1. Fails the upload device details call due to network timeout.
// 2. Fails the upload device details call due to invalid response // 2. Fails the upload device details call due to invalid response
// from the GEM http server. // from the GEM http server.
// 3 A previously saved device resource ID is present on the device.
class GcpGaiaCredentialBaseUploadDeviceDetailsTest class GcpGaiaCredentialBaseUploadDeviceDetailsTest
: public GcpGaiaCredentialBaseTest, : public GcpGaiaCredentialBaseTest,
public ::testing::WithParamInterface<int> {}; public ::testing::WithParamInterface<int> {};
...@@ -2648,6 +2649,7 @@ class GcpGaiaCredentialBaseUploadDeviceDetailsTest ...@@ -2648,6 +2649,7 @@ class GcpGaiaCredentialBaseUploadDeviceDetailsTest
TEST_P(GcpGaiaCredentialBaseUploadDeviceDetailsTest, UploadDeviceDetails) { TEST_P(GcpGaiaCredentialBaseUploadDeviceDetailsTest, UploadDeviceDetails) {
bool fail_upload_device_details_timeout = (GetParam() == 1); bool fail_upload_device_details_timeout = (GetParam() == 1);
bool fail_upload_device_details_invalid_response = (GetParam() == 2); bool fail_upload_device_details_invalid_response = (GetParam() == 2);
bool registry_has_device_resource_id = (GetParam() == 3);
GoogleMdmEnrolledStatusForTesting force_success(true); GoogleMdmEnrolledStatusForTesting force_success(true);
// Set a fake serial number. // Set a fake serial number.
...@@ -2681,16 +2683,25 @@ TEST_P(GcpGaiaCredentialBaseUploadDeviceDetailsTest, UploadDeviceDetails) { ...@@ -2681,16 +2683,25 @@ TEST_P(GcpGaiaCredentialBaseUploadDeviceDetailsTest, UploadDeviceDetails) {
fake_gem_device_details_manager()->SetRequestTimeoutForTesting( fake_gem_device_details_manager()->SetRequestTimeoutForTesting(
base::TimeDelta::FromMilliseconds(50)); base::TimeDelta::FromMilliseconds(50));
} }
const std::string device_resource_id = "test-device-resource-id";
const std::string valid_server_response =
"{\"deviceResourceId\": \"" + device_resource_id + "\"}";
fake_http_url_fetcher_factory()->SetFakeResponse( fake_http_url_fetcher_factory()->SetFakeResponse(
fake_gem_device_details_manager()->GetGemServiceUploadDeviceDetailsUrl(), fake_gem_device_details_manager()->GetGemServiceUploadDeviceDetailsUrl(),
FakeWinHttpUrlFetcher::Headers(), FakeWinHttpUrlFetcher::Headers(),
fail_upload_device_details_invalid_response ? "Invalid json response" fail_upload_device_details_invalid_response ? "Invalid json response"
: "{}", : valid_server_response,
upload_device_details_key_event upload_device_details_key_event
? upload_device_details_key_event->handle() ? upload_device_details_key_event->handle()
: INVALID_HANDLE_VALUE); : INVALID_HANDLE_VALUE);
if (registry_has_device_resource_id) {
HRESULT hr = SetUserProperty(sid.Copy(), kRegUserDeviceResourceId,
base::UTF8ToUTF16(device_resource_id));
EXPECT_TRUE(SUCCEEDED(hr));
}
// Create provider and start logon. // Create provider and start logon.
Microsoft::WRL::ComPtr<ICredentialProviderCredential> cred; Microsoft::WRL::ComPtr<ICredentialProviderCredential> cred;
...@@ -2730,8 +2741,8 @@ TEST_P(GcpGaiaCredentialBaseUploadDeviceDetailsTest, UploadDeviceDetails) { ...@@ -2730,8 +2741,8 @@ TEST_P(GcpGaiaCredentialBaseUploadDeviceDetailsTest, UploadDeviceDetails) {
base::UTF16ToUTF8((BSTR)sid)); base::UTF16ToUTF8((BSTR)sid));
ASSERT_TRUE(request_dict.FindBoolKey("is_ad_joined_user").has_value()); ASSERT_TRUE(request_dict.FindBoolKey("is_ad_joined_user").has_value());
ASSERT_EQ(request_dict.FindBoolKey("is_ad_joined_user").value(), true); ASSERT_EQ(request_dict.FindBoolKey("is_ad_joined_user").value(), true);
ASSERT_TRUE(request_dict.FindKey("wlan_mac_addr")->is_list()); ASSERT_TRUE(request_dict.FindKey("wlan_mac_addr")->is_list());
std::vector<std::string> actual_mac_address_list; std::vector<std::string> actual_mac_address_list;
for (const base::Value& value : for (const base::Value& value :
request_dict.FindKey("wlan_mac_addr")->GetList()) { request_dict.FindKey("wlan_mac_addr")->GetList()) {
...@@ -2742,12 +2753,28 @@ TEST_P(GcpGaiaCredentialBaseUploadDeviceDetailsTest, UploadDeviceDetails) { ...@@ -2742,12 +2753,28 @@ TEST_P(GcpGaiaCredentialBaseUploadDeviceDetailsTest, UploadDeviceDetails) {
ASSERT_TRUE(std::equal(actual_mac_address_list.begin(), ASSERT_TRUE(std::equal(actual_mac_address_list.begin(),
actual_mac_address_list.end(), mac_addresses.begin())); actual_mac_address_list.end(), mac_addresses.begin()));
if (registry_has_device_resource_id) {
ASSERT_EQ(*request_dict.FindStringKey("device_resource_id"),
device_resource_id);
}
if (!fail_upload_device_details_timeout &&
!fail_upload_device_details_invalid_response) {
wchar_t resource_id[512];
ULONG resource_id_size = base::size(resource_id);
hr = GetUserProperty(sid.Copy(), kRegUserDeviceResourceId, resource_id,
&resource_id_size);
ASSERT_TRUE(SUCCEEDED(hr));
ASSERT_TRUE(resource_id_size > 0);
ASSERT_EQ(device_resource_id, base::UTF16ToUTF8(resource_id));
}
ASSERT_EQ(S_OK, ReleaseProvider()); ASSERT_EQ(S_OK, ReleaseProvider());
} }
INSTANTIATE_TEST_SUITE_P(All, INSTANTIATE_TEST_SUITE_P(All,
GcpGaiaCredentialBaseUploadDeviceDetailsTest, GcpGaiaCredentialBaseUploadDeviceDetailsTest,
::testing::Values(0, 1, 2)); ::testing::Values(0, 1, 2, 3));
class GcpGaiaCredentialBaseFullNameUpdateTest class GcpGaiaCredentialBaseFullNameUpdateTest
: public GcpGaiaCredentialBaseTest, : public GcpGaiaCredentialBaseTest,
......
...@@ -39,13 +39,16 @@ const char kUploadDeviceDetailsRequestSerialNumberParameterName[] = ...@@ -39,13 +39,16 @@ const char kUploadDeviceDetailsRequestSerialNumberParameterName[] =
"device_serial_number"; "device_serial_number";
const char kUploadDeviceDetailsRequestMachineGuidParameterName[] = const char kUploadDeviceDetailsRequestMachineGuidParameterName[] =
"machine_guid"; "machine_guid";
const char kUploadDeviceDetailsRequestDeviceResourceIdParameterName[] =
"device_resource_id";
const char kUploadDeviceDetailsRequestUserSidParameterName[] = "user_sid"; const char kUploadDeviceDetailsRequestUserSidParameterName[] = "user_sid";
const char kUploadDeviceDetailsRequestUsernameParameterName[] = const char kUploadDeviceDetailsRequestUsernameParameterName[] =
"account_username"; "account_username";
const char kUploadDeviceDetailsRequestDomainParameterName[] = "device_domain"; const char kUploadDeviceDetailsRequestDomainParameterName[] = "device_domain";
const char kIsAdJoinedUserParameterName[] = "is_ad_joined_user"; const char kIsAdJoinedUserParameterName[] = "is_ad_joined_user";
const char kMacAddressParameterName[] = "wlan_mac_addr"; const char kMacAddressParameterName[] = "wlan_mac_addr";
const char kUploadDeviceDetailsResponseDeviceResourceIdParameterName[] =
"deviceResourceId";
} // namespace } // namespace
// static // static
...@@ -77,8 +80,6 @@ GURL GemDeviceDetailsManager::GetGemServiceUploadDeviceDetailsUrl() { ...@@ -77,8 +80,6 @@ GURL GemDeviceDetailsManager::GetGemServiceUploadDeviceDetailsUrl() {
// Uploads the device details into GEM database using |access_token| for // Uploads the device details into GEM database using |access_token| for
// authentication and authorization. The GEM service would use |serial_number| // authentication and authorization. The GEM service would use |serial_number|
// and |machine_guid| for identifying the device entry in GEM database. // and |machine_guid| for identifying the device entry in GEM database.
// TODO(crbug.com/1043199): Store device_resource_id on device and send that to
// GEM service for further optimizations.
HRESULT GemDeviceDetailsManager::UploadDeviceDetails( HRESULT GemDeviceDetailsManager::UploadDeviceDetails(
const std::string& access_token, const std::string& access_token,
const base::string16& sid, const base::string16& sid,
...@@ -114,6 +115,16 @@ HRESULT GemDeviceDetailsManager::UploadDeviceDetails( ...@@ -114,6 +115,16 @@ HRESULT GemDeviceDetailsManager::UploadDeviceDetails(
request_dict_->SetKey(kMacAddressParameterName, request_dict_->SetKey(kMacAddressParameterName,
std::move(mac_address_value_list)); std::move(mac_address_value_list));
wchar_t known_resource_id[512];
ULONG known_resource_id_size = base::size(known_resource_id);
hr = GetUserProperty(sid, kRegUserDeviceResourceId, known_resource_id,
&known_resource_id_size);
if (SUCCEEDED(hr) && known_resource_id_size > 0) {
request_dict_->SetStringKey(
kUploadDeviceDetailsRequestDeviceResourceIdParameterName,
base::UTF16ToUTF8(known_resource_id));
}
base::Optional<base::Value> request_result; base::Optional<base::Value> request_result;
hr = WinHttpUrlFetcher::BuildRequestAndFetchResultFromHttpService( hr = WinHttpUrlFetcher::BuildRequestAndFetchResultFromHttpService(
...@@ -134,6 +145,17 @@ HRESULT GemDeviceDetailsManager::UploadDeviceDetails( ...@@ -134,6 +145,17 @@ HRESULT GemDeviceDetailsManager::UploadDeviceDetails(
hr = E_FAIL; hr = E_FAIL;
} }
std::string* resource_id = request_result->FindStringKey(
kUploadDeviceDetailsResponseDeviceResourceIdParameterName);
if (resource_id) {
hr = SetUserProperty(sid, kRegUserDeviceResourceId,
base::UTF8ToUTF16(*resource_id));
} else {
LOGFN(ERROR) << "Server response does not contain "
<< kUploadDeviceDetailsResponseDeviceResourceIdParameterName;
hr = E_FAIL;
}
return hr; return hr;
} }
......
...@@ -44,6 +44,7 @@ constexpr wchar_t kRegMdmAllowConsumerAccounts[] = L"enable_consumer_accounts "; ...@@ -44,6 +44,7 @@ constexpr wchar_t kRegMdmAllowConsumerAccounts[] = L"enable_consumer_accounts ";
constexpr wchar_t kRegDeviceDetailsUploadStatus[] = constexpr wchar_t kRegDeviceDetailsUploadStatus[] =
L"device_details_upload_status"; L"device_details_upload_status";
constexpr wchar_t kRegGlsPath[] = L"gls_path"; constexpr wchar_t kRegGlsPath[] = L"gls_path";
constexpr wchar_t kRegUserDeviceResourceId[] = L"device_resource_id";
constexpr wchar_t kUserPasswordLsaStoreKeyPrefix[] = constexpr wchar_t kUserPasswordLsaStoreKeyPrefix[] =
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
L"Chrome-GCPW-"; L"Chrome-GCPW-";
......
...@@ -56,6 +56,9 @@ extern const wchar_t kRegDeviceDetailsUploadStatus[]; ...@@ -56,6 +56,9 @@ extern const wchar_t kRegDeviceDetailsUploadStatus[];
// Specifies custom Chrome path to use for GLS. // Specifies custom Chrome path to use for GLS.
extern const wchar_t kRegGlsPath[]; extern const wchar_t kRegGlsPath[];
// Registry key where user device resource ID is stored.
extern const wchar_t kRegUserDeviceResourceId[];
// Class used in tests to force either a successful on unsuccessful enrollment // Class used in tests to force either a successful on unsuccessful enrollment
// to google MDM. // to google MDM.
class GoogleMdmEnrollmentStatusForTesting { class GoogleMdmEnrollmentStatusForTesting {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment