diff options
author | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-15 17:55:54 +0000 |
---|---|---|
committer | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-15 17:55:54 +0000 |
commit | de265119899a864f047a8124b7f414dc54beb8cd (patch) | |
tree | fd696750a7bab169b8f8402874421cc4f288324c | |
parent | fb69c0969bf3f5bc389011a6d31a9fa2469b6c75 (diff) | |
download | chromium_src-de265119899a864f047a8124b7f414dc54beb8cd.zip chromium_src-de265119899a864f047a8124b7f414dc54beb8cd.tar.gz chromium_src-de265119899a864f047a8124b7f414dc54beb8cd.tar.bz2 |
gaia::AreEmailsSame() should consider X@gmail.com == X@googlemail.com.
BUG=253081
Review URL: https://codereview.chromium.org/235603003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@263914 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | google_apis/gaia/gaia_auth_util.cc | 29 | ||||
-rw-r--r-- | google_apis/gaia/gaia_auth_util.h | 5 | ||||
-rw-r--r-- | google_apis/gaia/gaia_auth_util_unittest.cc | 16 |
3 files changed, 32 insertions, 18 deletions
diff --git a/google_apis/gaia/gaia_auth_util.cc b/google_apis/gaia/gaia_auth_util.cc index 6532d19..287cd46 100644 --- a/google_apis/gaia/gaia_auth_util.cc +++ b/google_apis/gaia/gaia_auth_util.cc @@ -15,24 +15,41 @@ namespace gaia { namespace { + const char kGmailDomain[] = "gmail.com"; -} +const char kGooglemailDomain[] = "googlemail.com"; -std::string CanonicalizeEmail(const std::string& email_address) { +std::string CanonicalizeEmailImpl(const std::string& email_address, + bool change_googlemail_to_gmail) { std::vector<std::string> parts; char at = '@'; base::SplitString(email_address, at, &parts); if (parts.size() != 2U) { NOTREACHED() << "expecting exactly one @, but got " << parts.size()-1 << " : " << email_address; - } else if (parts[1] == kGmailDomain) { // only strip '.' for gmail accounts. - base::RemoveChars(parts[0], ".", &parts[0]); + } else { + if (change_googlemail_to_gmail && parts[1] == kGooglemailDomain) + parts[1] = kGmailDomain; + + if (parts[1] == kGmailDomain) // only strip '.' for gmail accounts. + base::RemoveChars(parts[0], ".", &parts[0]); } + std::string new_email = StringToLowerASCII(JoinString(parts, at)); VLOG(1) << "Canonicalized " << email_address << " to " << new_email; return new_email; } +} // namespace + +std::string CanonicalizeEmail(const std::string& email_address) { + // CanonicalizeEmail() is called to process email strings that are eventually + // shown to the user, and may also be used in persisting email strings. To + // avoid breaking this existing behavior, this function will not try to + // change googlemail to gmail. + return CanonicalizeEmailImpl(email_address, false); +} + std::string CanonicalizeDomain(const std::string& domain) { // Canonicalization of domain names means lower-casing them. Make sure to // update this function in sync with Canonicalize if this ever changes. @@ -52,8 +69,8 @@ std::string SanitizeEmail(const std::string& email_address) { } bool AreEmailsSame(const std::string& email1, const std::string& email2) { - return gaia::CanonicalizeEmail(gaia::SanitizeEmail(email1)) == - gaia::CanonicalizeEmail(gaia::SanitizeEmail(email2)); + return CanonicalizeEmailImpl(gaia::SanitizeEmail(email1), true) == + CanonicalizeEmailImpl(gaia::SanitizeEmail(email2), true); } std::string ExtractDomainName(const std::string& email_address) { diff --git a/google_apis/gaia/gaia_auth_util.h b/google_apis/gaia/gaia_auth_util.h index 68f75b5..d28f546 100644 --- a/google_apis/gaia/gaia_auth_util.h +++ b/google_apis/gaia/gaia_auth_util.h @@ -14,10 +14,7 @@ class GURL; namespace gaia { // Perform basic canonicalization of |email_address|, taking into account that -// gmail does not consider '.' or caps inside a username to matter. It also -// ignores everything after a '+'. For example, c.masone+abc@gmail.com == -// cMaSone@gmail.com, per -// http://mail.google.com/support/bin/answer.py?hl=en&ctx=mail&answer=10313# +// gmail does not consider '.' or caps inside a username to matter. std::string CanonicalizeEmail(const std::string& email_address); // Returns the canonical form of the given domain. diff --git a/google_apis/gaia/gaia_auth_util_unittest.cc b/google_apis/gaia/gaia_auth_util_unittest.cc index aa7a512..b17ac57 100644 --- a/google_apis/gaia/gaia_auth_util_unittest.cc +++ b/google_apis/gaia/gaia_auth_util_unittest.cc @@ -54,14 +54,9 @@ TEST(GaiaAuthUtilTest, EmailAddressDifferentOnesRejected) { CanonicalizeEmail("Us....E.r@what.com")); } -TEST(GaiaAuthUtilTest, EmailAddressIgnorePlusSuffix) { - const char with_plus[] = "user+cc@what.com"; - EXPECT_EQ(with_plus, CanonicalizeEmail(with_plus)); -} - -TEST(GaiaAuthUtilTest, EmailAddressIgnoreMultiPlusSuffix) { - const char multi_plus[] = "user+cc+bcc@what.com"; - EXPECT_EQ(multi_plus, CanonicalizeEmail(multi_plus)); +TEST(GaiaAuthUtilTest, GooglemailNotCanonicalizedToGmail) { + const char googlemail[] = "user@googlemail.com"; + EXPECT_EQ(googlemail, CanonicalizeEmail(googlemail)); } TEST(GaiaAuthUtilTest, CanonicalizeDomain) { @@ -93,6 +88,11 @@ TEST(GaiaAuthUtilTest, AreEmailsSame) { EXPECT_FALSE(AreEmailsSame("user@gmail.com", "foo@gmail.com")); } +TEST(GaiaAuthUtilTest, GmailAndGooglemailAreSame) { + EXPECT_TRUE(AreEmailsSame("foo@gmail.com", "foo@googlemail.com")); + EXPECT_FALSE(AreEmailsSame("bar@gmail.com", "foo@googlemail.com")); +} + TEST(GaiaAuthUtilTest, IsGaiaSignonRealm) { // Only https versions of Gaia URLs should be considered valid. EXPECT_TRUE(IsGaiaSignonRealm(GURL("https://accounts.google.com/"))); |