summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos
diff options
context:
space:
mode:
authorcmasone@google.com <cmasone@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-12 22:15:43 +0000
committercmasone@google.com <cmasone@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-12 22:15:43 +0000
commitbf485013f81afb5ef08956d9a658c2ef8c52987b (patch)
tree5a2f16b83e58a73d7aacfccc93984b4360f2c36c /chrome/browser/chromeos
parentcba5c5856aa0f75af980122b7738fb11f947b8b4 (diff)
downloadchromium_src-bf485013f81afb5ef08956d9a658c2ef8c52987b.zip
chromium_src-bf485013f81afb5ef08956d9a658c2ef8c52987b.tar.gz
chromium_src-bf485013f81afb5ef08956d9a658c2ef8c52987b.tar.bz2
Canonicalize email addresses for chrome OS.
According to http://mail.google.com/support/bin/answer.py?hl=en&ctx=mail&answer=10313#, gmail ignores period characters and case differences in the username portion of an email address. Follow those rules. BUG=chromiumos:2260 TEST=unit tests, also run on device and log in with user@google.com and user@GOOGLE.COM; verify that you get the same tab state, etc. in both sessions. Review URL: http://codereview.chromium.org/1539030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44286 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r--chrome/browser/chromeos/login/google_authenticator.cc14
-rw-r--r--chrome/browser/chromeos/login/google_authenticator.h14
-rw-r--r--chrome/browser/chromeos/login/google_authenticator_unittest.cc35
3 files changed, 62 insertions, 1 deletions
diff --git a/chrome/browser/chromeos/login/google_authenticator.cc b/chrome/browser/chromeos/login/google_authenticator.cc
index 0d8ba14..7c0a752 100644
--- a/chrome/browser/chromeos/login/google_authenticator.cc
+++ b/chrome/browser/chromeos/login/google_authenticator.cc
@@ -93,7 +93,7 @@ bool GoogleAuthenticator::Authenticate(Profile* profile,
kAccountType,
kSource);
fetcher_->set_upload_data("application/x-www-form-urlencoded", body);
- username_.assign(username);
+ username_.assign(Canonicalize(username));
StoreHashedPassword(password);
fetcher_->Start();
return true;
@@ -136,6 +136,7 @@ void GoogleAuthenticator::OnLoginSuccess(const std::string& data) {
}
void GoogleAuthenticator::CheckOffline(const URLRequestStatus& status) {
+ LOG(INFO) << "Attempting offline login";
if (CrosLibrary::Get()->GetCryptohomeLibrary()->CheckKey(
username_.c_str(),
ascii_hash_.c_str())) {
@@ -255,4 +256,15 @@ bool GoogleAuthenticator::BinaryToHex(const std::vector<unsigned char>& binary,
return true;
}
+// static
+std::string GoogleAuthenticator::Canonicalize(
+ const std::string& email_address) {
+ std::vector<std::string> parts;
+ char at = '@';
+ SplitString(email_address, at, &parts);
+ DCHECK(parts.size() == 2) << "email_address should have only one @";
+ RemoveChars(parts[0], ".", &parts[0]);
+ return StringToLowerASCII(JoinString(parts, at));
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/google_authenticator.h b/chrome/browser/chromeos/login/google_authenticator.h
index c89b7f0..34ff871 100644
--- a/chrome/browser/chromeos/login/google_authenticator.h
+++ b/chrome/browser/chromeos/login/google_authenticator.h
@@ -108,6 +108,12 @@ class GoogleAuthenticator : public Authenticator,
char* hex_string,
const unsigned int len);
+ // Perform basic canonicalization of |email_address|, taking into account
+ // that gmail does not consider '.' or caps inside a username to matter.
+ // For example, c.masone@gmail.com == cMaSone@gmail.com, per
+ // http://mail.google.com/support/bin/answer.py?hl=en&ctx=mail&answer=10313#
+ static std::string Canonicalize(const std::string& email_address);
+
// Constants to use in the ClientLogin request POST body.
static const char kCookiePersistence[];
static const char kAccountType[];
@@ -134,6 +140,14 @@ class GoogleAuthenticator : public Authenticator,
friend class GoogleAuthenticatorTest;
FRIEND_TEST(GoogleAuthenticatorTest, SaltToAsciiTest);
+ FRIEND_TEST(GoogleAuthenticatorTest, EmailAddressNoOp);
+ FRIEND_TEST(GoogleAuthenticatorTest, EmailAddressIgnoreCaps);
+ FRIEND_TEST(GoogleAuthenticatorTest, EmailAddressIgnoreDomainCaps);
+ FRIEND_TEST(GoogleAuthenticatorTest, EmailAddressIgnoreOneUsernameDot);
+ FRIEND_TEST(GoogleAuthenticatorTest, EmailAddressIgnoreManyUsernameDots);
+ FRIEND_TEST(GoogleAuthenticatorTest,
+ EmailAddressIgnoreConsecutiveUsernameDots);
+ FRIEND_TEST(GoogleAuthenticatorTest, EmailAddressDifferentOnesRejected);
FRIEND_TEST(GoogleAuthenticatorTest, ReadSaltTest);
FRIEND_TEST(GoogleAuthenticatorTest, ReadLocalaccountTest);
FRIEND_TEST(GoogleAuthenticatorTest, ReadLocalaccountTrailingWSTest);
diff --git a/chrome/browser/chromeos/login/google_authenticator_unittest.cc b/chrome/browser/chromeos/login/google_authenticator_unittest.cc
index be84c70..4d2fad0 100644
--- a/chrome/browser/chromeos/login/google_authenticator_unittest.cc
+++ b/chrome/browser/chromeos/login/google_authenticator_unittest.cc
@@ -134,6 +134,41 @@ TEST_F(GoogleAuthenticatorTest, SaltToAsciiTest) {
EXPECT_EQ("0a010000000000a0", auth->SaltAsAscii());
}
+TEST_F(GoogleAuthenticatorTest, EmailAddressNoOp) {
+ const char lower_case[] = "user@what.com";
+ EXPECT_EQ(lower_case, GoogleAuthenticator::Canonicalize(lower_case));
+}
+
+TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreCaps) {
+ EXPECT_EQ(GoogleAuthenticator::Canonicalize("user@what.com"),
+ GoogleAuthenticator::Canonicalize("UsEr@what.com"));
+}
+
+TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreDomainCaps) {
+ EXPECT_EQ(GoogleAuthenticator::Canonicalize("user@what.com"),
+ GoogleAuthenticator::Canonicalize("UsEr@what.COM"));
+}
+
+TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreOneUsernameDot) {
+ EXPECT_EQ(GoogleAuthenticator::Canonicalize("us.er@what.com"),
+ GoogleAuthenticator::Canonicalize("UsEr@what.com"));
+}
+
+TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreManyUsernameDots) {
+ EXPECT_EQ(GoogleAuthenticator::Canonicalize("u.ser@what.com"),
+ GoogleAuthenticator::Canonicalize("Us.E.r@what.com"));
+}
+
+TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreConsecutiveUsernameDots) {
+ EXPECT_EQ(GoogleAuthenticator::Canonicalize("use.r@what.com"),
+ GoogleAuthenticator::Canonicalize("Us....E.r@what.com"));
+}
+
+TEST_F(GoogleAuthenticatorTest, EmailAddressDifferentOnesRejected) {
+ EXPECT_NE(GoogleAuthenticator::Canonicalize("who@what.com"),
+ GoogleAuthenticator::Canonicalize("Us....E.r@what.com"));
+}
+
TEST_F(GoogleAuthenticatorTest, ReadSaltTest) {
FilePath tmp_file_path = PopulateTempFile(raw_bytes_, sizeof(raw_bytes_));