Home | History | Annotate | Download | only in login
      1 // Copyright (c) 2010 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 "chrome/browser/chromeos/login/authenticator.h"
      6 
      7 #include "testing/gtest/include/gtest/gtest.h"
      8 
      9 namespace chromeos {
     10 
     11 TEST(AuthenticatorTest, EmailAddressNoOp) {
     12   const char lower_case[] = "user (at) what.com";
     13   EXPECT_EQ(lower_case, Authenticator::Canonicalize(lower_case));
     14 }
     15 
     16 TEST(AuthenticatorTest, EmailAddressIgnoreCaps) {
     17   EXPECT_EQ(Authenticator::Canonicalize("user (at) what.com"),
     18             Authenticator::Canonicalize("UsEr (at) what.com"));
     19 }
     20 
     21 TEST(AuthenticatorTest, EmailAddressIgnoreDomainCaps) {
     22   EXPECT_EQ(Authenticator::Canonicalize("user (at) what.com"),
     23             Authenticator::Canonicalize("UsEr (at) what.COM"));
     24 }
     25 
     26 TEST(AuthenticatorTest, EmailAddressRejectOneUsernameDot) {
     27   EXPECT_NE(Authenticator::Canonicalize("u.ser (at) what.com"),
     28             Authenticator::Canonicalize("UsEr (at) what.com"));
     29 }
     30 
     31 TEST(AuthenticatorTest, EmailAddressMatchWithOneUsernameDot) {
     32   EXPECT_EQ(Authenticator::Canonicalize("u.ser (at) what.com"),
     33             Authenticator::Canonicalize("U.sEr (at) what.com"));
     34 }
     35 
     36 TEST(AuthenticatorTest, EmailAddressIgnoreOneUsernameDot) {
     37   EXPECT_EQ(Authenticator::Canonicalize("us.er (at) gmail.com"),
     38             Authenticator::Canonicalize("UsEr (at) gmail.com"));
     39 }
     40 
     41 TEST(AuthenticatorTest, EmailAddressIgnoreManyUsernameDots) {
     42   EXPECT_EQ(Authenticator::Canonicalize("u.ser (at) gmail.com"),
     43             Authenticator::Canonicalize("Us.E.r (at) gmail.com"));
     44 }
     45 
     46 TEST(AuthenticatorTest, EmailAddressIgnoreConsecutiveUsernameDots) {
     47   EXPECT_EQ(Authenticator::Canonicalize("use.r (at) gmail.com"),
     48             Authenticator::Canonicalize("Us....E.r (at) gmail.com"));
     49 }
     50 
     51 TEST(AuthenticatorTest, EmailAddressDifferentOnesRejected) {
     52   EXPECT_NE(Authenticator::Canonicalize("who (at) what.com"),
     53             Authenticator::Canonicalize("Us....E.r (at) what.com"));
     54 }
     55 
     56 TEST(AuthenticatorTest, EmailAddressIgnorePlusSuffix) {
     57   const char with_plus[] = "user+cc (at) what.com";
     58   EXPECT_EQ(with_plus, Authenticator::Canonicalize(with_plus));
     59 }
     60 
     61 TEST(AuthenticatorTest, EmailAddressIgnoreMultiPlusSuffix) {
     62   const char multi_plus[] = "user+cc+bcc (at) what.com";
     63   EXPECT_EQ(multi_plus, Authenticator::Canonicalize(multi_plus));
     64 }
     65 
     66 }  // namespace chromeos
     67