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.
5 #include "google_apis/gaia/gaia_auth_util.h"
7 #include "googleurl/src/gurl.h"
8 #include "testing/gtest/include/gtest/gtest.h"
12 TEST(GaiaAuthUtilTest
, EmailAddressNoOp
) {
13 const char lower_case
[] = "user@what.com";
14 EXPECT_EQ(lower_case
, CanonicalizeEmail(lower_case
));
17 TEST(GaiaAuthUtilTest
, EmailAddressIgnoreCaps
) {
18 EXPECT_EQ(CanonicalizeEmail("user@what.com"),
19 CanonicalizeEmail("UsEr@what.com"));
22 TEST(GaiaAuthUtilTest
, EmailAddressIgnoreDomainCaps
) {
23 EXPECT_EQ(CanonicalizeEmail("user@what.com"),
24 CanonicalizeEmail("UsEr@what.COM"));
27 TEST(GaiaAuthUtilTest
, EmailAddressRejectOneUsernameDot
) {
28 EXPECT_NE(CanonicalizeEmail("u.ser@what.com"),
29 CanonicalizeEmail("UsEr@what.com"));
32 TEST(GaiaAuthUtilTest
, EmailAddressMatchWithOneUsernameDot
) {
33 EXPECT_EQ(CanonicalizeEmail("u.ser@what.com"),
34 CanonicalizeEmail("U.sEr@what.com"));
37 TEST(GaiaAuthUtilTest
, EmailAddressIgnoreOneUsernameDot
) {
38 EXPECT_EQ(CanonicalizeEmail("us.er@gmail.com"),
39 CanonicalizeEmail("UsEr@gmail.com"));
42 TEST(GaiaAuthUtilTest
, EmailAddressIgnoreManyUsernameDots
) {
43 EXPECT_EQ(CanonicalizeEmail("u.ser@gmail.com"),
44 CanonicalizeEmail("Us.E.r@gmail.com"));
47 TEST(GaiaAuthUtilTest
, EmailAddressIgnoreConsecutiveUsernameDots
) {
48 EXPECT_EQ(CanonicalizeEmail("use.r@gmail.com"),
49 CanonicalizeEmail("Us....E.r@gmail.com"));
52 TEST(GaiaAuthUtilTest
, EmailAddressDifferentOnesRejected
) {
53 EXPECT_NE(CanonicalizeEmail("who@what.com"),
54 CanonicalizeEmail("Us....E.r@what.com"));
57 TEST(GaiaAuthUtilTest
, EmailAddressIgnorePlusSuffix
) {
58 const char with_plus
[] = "user+cc@what.com";
59 EXPECT_EQ(with_plus
, CanonicalizeEmail(with_plus
));
62 TEST(GaiaAuthUtilTest
, EmailAddressIgnoreMultiPlusSuffix
) {
63 const char multi_plus
[] = "user+cc+bcc@what.com";
64 EXPECT_EQ(multi_plus
, CanonicalizeEmail(multi_plus
));
67 TEST(GaiaAuthUtilTest
, CanonicalizeDomain
) {
68 const char domain
[] = "example.com";
69 EXPECT_EQ(domain
, CanonicalizeDomain("example.com"));
70 EXPECT_EQ(domain
, CanonicalizeDomain("EXAMPLE.cOm"));
73 TEST(GaiaAuthUtilTest
, ExtractDomainName
) {
74 const char domain
[] = "example.com";
75 EXPECT_EQ(domain
, ExtractDomainName("who@example.com"));
76 EXPECT_EQ(domain
, ExtractDomainName("who@EXAMPLE.cOm"));
79 TEST(GaiaAuthUtilTest
, SanitizeMissingDomain
) {
80 EXPECT_EQ("nodomain@gmail.com", SanitizeEmail("nodomain"));
83 TEST(GaiaAuthUtilTest
, SanitizeExistingDomain
) {
84 const char existing
[] = "test@example.com";
85 EXPECT_EQ(existing
, SanitizeEmail(existing
));
88 TEST(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/")));
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/")));
99 // Other https URLs are not valid.
100 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.example.com/")));