1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "google_apis/gaia/gaia_auth_util.h" 6 7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "url/gurl.h" 9 10 namespace gaia { 11 12 TEST(GaiaAuthUtilTest, EmailAddressNoOp) { 13 const char lower_case[] = "user (at) what.com"; 14 EXPECT_EQ(lower_case, CanonicalizeEmail(lower_case)); 15 } 16 17 TEST(GaiaAuthUtilTest, EmailAddressIgnoreCaps) { 18 EXPECT_EQ(CanonicalizeEmail("user (at) what.com"), 19 CanonicalizeEmail("UsEr (at) what.com")); 20 } 21 22 TEST(GaiaAuthUtilTest, EmailAddressIgnoreDomainCaps) { 23 EXPECT_EQ(CanonicalizeEmail("user (at) what.com"), 24 CanonicalizeEmail("UsEr (at) what.COM")); 25 } 26 27 TEST(GaiaAuthUtilTest, EmailAddressRejectOneUsernameDot) { 28 EXPECT_NE(CanonicalizeEmail("u.ser (at) what.com"), 29 CanonicalizeEmail("UsEr (at) what.com")); 30 } 31 32 TEST(GaiaAuthUtilTest, EmailAddressMatchWithOneUsernameDot) { 33 EXPECT_EQ(CanonicalizeEmail("u.ser (at) what.com"), 34 CanonicalizeEmail("U.sEr (at) what.com")); 35 } 36 37 TEST(GaiaAuthUtilTest, EmailAddressIgnoreOneUsernameDot) { 38 EXPECT_EQ(CanonicalizeEmail("us.er (at) gmail.com"), 39 CanonicalizeEmail("UsEr (at) gmail.com")); 40 } 41 42 TEST(GaiaAuthUtilTest, EmailAddressIgnoreManyUsernameDots) { 43 EXPECT_EQ(CanonicalizeEmail("u.ser (at) gmail.com"), 44 CanonicalizeEmail("Us.E.r (at) gmail.com")); 45 } 46 47 TEST(GaiaAuthUtilTest, EmailAddressIgnoreConsecutiveUsernameDots) { 48 EXPECT_EQ(CanonicalizeEmail("use.r (at) gmail.com"), 49 CanonicalizeEmail("Us....E.r (at) gmail.com")); 50 } 51 52 TEST(GaiaAuthUtilTest, EmailAddressDifferentOnesRejected) { 53 EXPECT_NE(CanonicalizeEmail("who (at) what.com"), 54 CanonicalizeEmail("Us....E.r (at) what.com")); 55 } 56 57 TEST(GaiaAuthUtilTest, EmailAddressIgnorePlusSuffix) { 58 const char with_plus[] = "user+cc (at) what.com"; 59 EXPECT_EQ(with_plus, CanonicalizeEmail(with_plus)); 60 } 61 62 TEST(GaiaAuthUtilTest, EmailAddressIgnoreMultiPlusSuffix) { 63 const char multi_plus[] = "user+cc+bcc (at) what.com"; 64 EXPECT_EQ(multi_plus, CanonicalizeEmail(multi_plus)); 65 } 66 67 TEST(GaiaAuthUtilTest, CanonicalizeDomain) { 68 const char domain[] = "example.com"; 69 EXPECT_EQ(domain, CanonicalizeDomain("example.com")); 70 EXPECT_EQ(domain, CanonicalizeDomain("EXAMPLE.cOm")); 71 } 72 73 TEST(GaiaAuthUtilTest, ExtractDomainName) { 74 const char domain[] = "example.com"; 75 EXPECT_EQ(domain, ExtractDomainName("who (at) example.com")); 76 EXPECT_EQ(domain, ExtractDomainName("who (at) EXAMPLE.cOm")); 77 } 78 79 TEST(GaiaAuthUtilTest, SanitizeMissingDomain) { 80 EXPECT_EQ("nodomain (at) gmail.com", SanitizeEmail("nodomain")); 81 } 82 83 TEST(GaiaAuthUtilTest, SanitizeExistingDomain) { 84 const char existing[] = "test (at) example.com"; 85 EXPECT_EQ(existing, SanitizeEmail(existing)); 86 } 87 88 TEST(GaiaAuthUtilTest, AreEmailsSame) { 89 EXPECT_TRUE(AreEmailsSame("foo", "foo")); 90 EXPECT_TRUE(AreEmailsSame("foo", "foo (at) gmail.com")); 91 EXPECT_TRUE(AreEmailsSame("foo (at) gmail.com", "Foo (at) Gmail.com")); 92 EXPECT_FALSE(AreEmailsSame("foo (at) gmail.com", "foo (at) othermail.com")); 93 EXPECT_FALSE(AreEmailsSame("user (at) gmail.com", "foo (at) gmail.com")); 94 } 95 96 TEST(GaiaAuthUtilTest, IsGaiaSignonRealm) { 97 // Only https versions of Gaia URLs should be considered valid. 98 EXPECT_TRUE(IsGaiaSignonRealm(GURL("https://accounts.google.com/"))); 99 EXPECT_FALSE(IsGaiaSignonRealm(GURL("http://accounts.google.com/"))); 100 101 // Other Google URLs are not valid. 102 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.google.com/"))); 103 EXPECT_FALSE(IsGaiaSignonRealm(GURL("http://www.google.com/"))); 104 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://google.com/"))); 105 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://mail.google.com/"))); 106 107 // Other https URLs are not valid. 108 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.example.com/"))); 109 } 110 111 } // namespace gaia 112