Commit d8453b0a authored by Yusuf Sengul's avatar Yusuf Sengul Committed by Commit Bot

Add reg to config how Windows account name is derived

Bug: 1122370
Change-Id: I6759cdcde7ce2940be62b934e16a61d8be9bcd4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2378778
Commit-Queue: Yusuf Sengul <yusufsn@google.com>
Reviewed-by: default avatarRakesh Soma <rakeshsoma@google.com>
Cr-Commit-Position: refs/heads/master@{#803256}
parent 5ac4038b
...@@ -536,16 +536,28 @@ HRESULT MakeUsernameForAccount(const base::Value& result, ...@@ -536,16 +536,28 @@ HRESULT MakeUsernameForAccount(const base::Value& result,
std::string username_utf8 = std::string username_utf8 =
gaia::SanitizeEmail(base::UTF16ToUTF8(os_username)); gaia::SanitizeEmail(base::UTF16ToUTF8(os_username));
size_t tld_length = if (GetGlobalFlagOrDefault(kRegUseShorterAccountName, 0)) {
net::registry_controlled_domains::GetCanonicalHostRegistryLength( size_t separator_pos = username_utf8.find('@');
gaia::ExtractDomainName(username_utf8),
net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, // os_username carries the email. Fall through if not find "@" in the
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); // email.
if (separator_pos != username_utf8.npos) {
// If an TLD is found strip it off, plus 1 to remove the separating dot too. username_utf8 = username_utf8.substr(0, separator_pos);
if (tld_length > 0) { os_username = base::UTF8ToUTF16(username_utf8);
username_utf8.resize(username_utf8.length() - tld_length - 1); }
os_username = base::UTF8ToUTF16(username_utf8); } else {
size_t tld_length =
net::registry_controlled_domains::GetCanonicalHostRegistryLength(
gaia::ExtractDomainName(username_utf8),
net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
// If an TLD is found strip it off, plus 1 to remove the separating dot
// too.
if (tld_length > 0) {
username_utf8.resize(username_utf8.length() - tld_length - 1);
os_username = base::UTF8ToUTF16(username_utf8);
}
} }
} }
......
...@@ -822,6 +822,60 @@ TEST_F(GcpGaiaCredentialBaseTest, TrimPeriodAtTheEnd) { ...@@ -822,6 +822,60 @@ TEST_F(GcpGaiaCredentialBaseTest, TrimPeriodAtTheEnd) {
EXPECT_EQ(test->GetFinalEmail(), email); EXPECT_EQ(test->GetFinalEmail(), email);
} }
TEST_F(GcpGaiaCredentialBaseTest, UseShorterFormForAccountName) {
USES_CONVERSION;
ASSERT_EQ(S_OK, SetGlobalFlagForTesting(kRegUseShorterAccountName, 1));
// Create provider and start logon.
Microsoft::WRL::ComPtr<ICredentialProviderCredential> cred;
ASSERT_EQ(S_OK, InitializeProviderAndGetCredential(0, &cred));
Microsoft::WRL::ComPtr<ITestCredential> test;
ASSERT_EQ(S_OK, cred.As(&test));
constexpr char email[] = "abc@def.com";
ASSERT_EQ(S_OK, test->SetGlsEmailAddress(email));
ASSERT_EQ(S_OK, StartLogonProcessAndWait());
ASSERT_STREQ(W2COLE(L"abc"), test->GetFinalUsername());
EXPECT_EQ(test->GetFinalEmail(), email);
}
TEST_F(GcpGaiaCredentialBaseTest, UseShorterFormForAccountNameWithConflict) {
USES_CONVERSION;
ASSERT_EQ(S_OK, SetGlobalFlagForTesting(kRegUseShorterAccountName, 1));
const wchar_t user_name[] = L"abc";
const wchar_t password[] = L"password";
CComBSTR local_sid;
DWORD error;
HRESULT hr = fake_os_user_manager()->AddUser(
user_name, password, L"fullname", L"comment", true, &local_sid, &error);
ASSERT_EQ(S_OK, hr);
ASSERT_EQ(0u, error);
// Create provider and start logon.
Microsoft::WRL::ComPtr<ICredentialProviderCredential> cred;
ASSERT_EQ(S_OK, InitializeProviderAndGetCredential(0, &cred));
Microsoft::WRL::ComPtr<ITestCredential> test;
ASSERT_EQ(S_OK, cred.As(&test));
constexpr char email[] = "abc@def.com";
ASSERT_EQ(S_OK, test->SetGlsEmailAddress(email));
ASSERT_EQ(S_OK, StartLogonProcessAndWait());
ASSERT_STREQ(W2COLE(L"abc2"), test->GetFinalUsername());
EXPECT_EQ(test->GetFinalEmail(), email);
}
TEST_F(GcpGaiaCredentialBaseTest, NewUserDisabledThroughUsageScenario) { TEST_F(GcpGaiaCredentialBaseTest, NewUserDisabledThroughUsageScenario) {
USES_CONVERSION; USES_CONVERSION;
// Create provider and start logon. // Create provider and start logon.
......
...@@ -54,6 +54,7 @@ constexpr wchar_t kRegGlsPath[] = L"gls_path"; ...@@ -54,6 +54,7 @@ constexpr wchar_t kRegGlsPath[] = L"gls_path";
constexpr wchar_t kRegUpdateCredentialsOnChange[] = constexpr wchar_t kRegUpdateCredentialsOnChange[] =
L"update_credentials_on_change"; L"update_credentials_on_change";
constexpr wchar_t kRegUserDeviceResourceId[] = L"device_resource_id"; constexpr wchar_t kRegUserDeviceResourceId[] = L"device_resource_id";
constexpr wchar_t kRegUseShorterAccountName[] = L"use_shorter_account_name";
constexpr wchar_t kUserPasswordLsaStoreKeyPrefix[] = constexpr wchar_t kUserPasswordLsaStoreKeyPrefix[] =
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
L"Chrome-GCPW-"; L"Chrome-GCPW-";
......
...@@ -78,6 +78,10 @@ extern const wchar_t kRegUpdateCredentialsOnChange[]; ...@@ -78,6 +78,10 @@ extern const wchar_t kRegUpdateCredentialsOnChange[];
// again. // again.
extern const base::TimeDelta kMaxTimeDeltaSinceLastUserPolicyRefresh; extern const base::TimeDelta kMaxTimeDeltaSinceLastUserPolicyRefresh;
// Registry key that indicates account name for an unassociated Windows account
// should be in shorter form.
extern const wchar_t kRegUseShorterAccountName[];
// 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