Commit 0f916417 authored by Yusuf Sengul's avatar Yusuf Sengul Committed by Commit Bot

Trim period at the end of OS user name

Bug: 1113075
Change-Id: If6dd51dc9adf71fbceea1421a650a8f0e906c97c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2337769
Commit-Queue: Rakesh Soma <rakeshsoma@google.com>
Reviewed-by: default avatarRakesh Soma <rakeshsoma@google.com>
Cr-Commit-Position: refs/heads/master@{#794914}
parent 53be2d5a
......@@ -565,6 +565,12 @@ HRESULT MakeUsernameForAccount(const base::Value& result,
if (os_username.size() > kWindowsUsernameBufferLength - 1)
os_username.resize(kWindowsUsernameBufferLength - 1);
// After resizing the os user name above, the last char may be a '.' which is
// illegal as the last character per Microsoft documentation.
// https://docs.microsoft.com/en-us/windows/win32/api/lmaccess/ns-lmaccess-user_info_1#remarks
if (os_username.size() > 0 && os_username.back() == '.')
os_username.resize(os_username.size() - 1);
// Replace invalid characters. While @ is not strictly invalid according to
// MSDN docs, it causes trouble.
for (auto& c : os_username) {
......
......@@ -854,6 +854,31 @@ TEST_F(GcpGaiaCredentialBaseTest, StripEmailTLD) {
EXPECT_EQ(test->GetFinalEmail(), email);
}
TEST_F(GcpGaiaCredentialBaseTest, TrimPeriodAtTheEnd) {
USES_CONVERSION;
// 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));
// The top level domain("info" in this example) is removed and the rest is
// truncated to be 20 characters. However, in this example, this will result
// with "abcdefghijklmn_abcd." which isn't valid per Microsoft documentation.
// The rule says there shouldn't be a '.' at the end. Thus it needs to be
// removed.
constexpr char email[] = "abcdefghijklmn@abcd.ef.info";
ASSERT_EQ(S_OK, test->SetGlsEmailAddress(email));
ASSERT_EQ(S_OK, StartLogonProcessAndWait());
ASSERT_STREQ(W2COLE(L"abcdefghijklmn_abcd"), test->GetFinalUsername());
EXPECT_EQ(test->GetFinalEmail(), email);
}
TEST_F(GcpGaiaCredentialBaseTest, NewUserDisabledThroughUsageScenario) {
USES_CONVERSION;
// Create provider and start logon.
......
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