gaia_auth_util_unittest.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 "googleurl/src/gurl.h" 8#include "testing/gtest/include/gtest/gtest.h" 9 10namespace gaia { 11 12TEST(GaiaAuthUtilTest, EmailAddressNoOp) { 13 const char lower_case[] = "user@what.com"; 14 EXPECT_EQ(lower_case, CanonicalizeEmail(lower_case)); 15} 16 17TEST(GaiaAuthUtilTest, EmailAddressIgnoreCaps) { 18 EXPECT_EQ(CanonicalizeEmail("user@what.com"), 19 CanonicalizeEmail("UsEr@what.com")); 20} 21 22TEST(GaiaAuthUtilTest, EmailAddressIgnoreDomainCaps) { 23 EXPECT_EQ(CanonicalizeEmail("user@what.com"), 24 CanonicalizeEmail("UsEr@what.COM")); 25} 26 27TEST(GaiaAuthUtilTest, EmailAddressRejectOneUsernameDot) { 28 EXPECT_NE(CanonicalizeEmail("u.ser@what.com"), 29 CanonicalizeEmail("UsEr@what.com")); 30} 31 32TEST(GaiaAuthUtilTest, EmailAddressMatchWithOneUsernameDot) { 33 EXPECT_EQ(CanonicalizeEmail("u.ser@what.com"), 34 CanonicalizeEmail("U.sEr@what.com")); 35} 36 37TEST(GaiaAuthUtilTest, EmailAddressIgnoreOneUsernameDot) { 38 EXPECT_EQ(CanonicalizeEmail("us.er@gmail.com"), 39 CanonicalizeEmail("UsEr@gmail.com")); 40} 41 42TEST(GaiaAuthUtilTest, EmailAddressIgnoreManyUsernameDots) { 43 EXPECT_EQ(CanonicalizeEmail("u.ser@gmail.com"), 44 CanonicalizeEmail("Us.E.r@gmail.com")); 45} 46 47TEST(GaiaAuthUtilTest, EmailAddressIgnoreConsecutiveUsernameDots) { 48 EXPECT_EQ(CanonicalizeEmail("use.r@gmail.com"), 49 CanonicalizeEmail("Us....E.r@gmail.com")); 50} 51 52TEST(GaiaAuthUtilTest, EmailAddressDifferentOnesRejected) { 53 EXPECT_NE(CanonicalizeEmail("who@what.com"), 54 CanonicalizeEmail("Us....E.r@what.com")); 55} 56 57TEST(GaiaAuthUtilTest, EmailAddressIgnorePlusSuffix) { 58 const char with_plus[] = "user+cc@what.com"; 59 EXPECT_EQ(with_plus, CanonicalizeEmail(with_plus)); 60} 61 62TEST(GaiaAuthUtilTest, EmailAddressIgnoreMultiPlusSuffix) { 63 const char multi_plus[] = "user+cc+bcc@what.com"; 64 EXPECT_EQ(multi_plus, CanonicalizeEmail(multi_plus)); 65} 66 67TEST(GaiaAuthUtilTest, CanonicalizeDomain) { 68 const char domain[] = "example.com"; 69 EXPECT_EQ(domain, CanonicalizeDomain("example.com")); 70 EXPECT_EQ(domain, CanonicalizeDomain("EXAMPLE.cOm")); 71} 72 73TEST(GaiaAuthUtilTest, ExtractDomainName) { 74 const char domain[] = "example.com"; 75 EXPECT_EQ(domain, ExtractDomainName("who@example.com")); 76 EXPECT_EQ(domain, ExtractDomainName("who@EXAMPLE.cOm")); 77} 78 79TEST(GaiaAuthUtilTest, SanitizeMissingDomain) { 80 EXPECT_EQ("nodomain@gmail.com", SanitizeEmail("nodomain")); 81} 82 83TEST(GaiaAuthUtilTest, SanitizeExistingDomain) { 84 const char existing[] = "test@example.com"; 85 EXPECT_EQ(existing, SanitizeEmail(existing)); 86} 87 88TEST(GaiaAuthUtilTest, IsGaiaSignonRealm) { 89 // Only https versions of Gaia URLs should be considered valid. 90 EXPECT_TRUE(IsGaiaSignonRealm(GURL("https://accounts.google.com/"))); 91 EXPECT_FALSE(IsGaiaSignonRealm(GURL("http://accounts.google.com/"))); 92 93 // Other Google URLs are not valid. 94 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.google.com/"))); 95 EXPECT_FALSE(IsGaiaSignonRealm(GURL("http://www.google.com/"))); 96 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://google.com/"))); 97 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://mail.google.com/"))); 98 99 // Other https URLs are not valid. 100 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.example.com/"))); 101} 102 103} // namespace gaia 104