summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-25 12:36:05 +0000
committermnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-25 12:36:05 +0000
commit9008b35a1a6c49905694a93215148ec6d86696e5 (patch)
treed0a0acb45fa9c752c8dcceb10e9510721034f206
parentb4c71c1b9c5daa9afd39a121ca8e68eb576acbf9 (diff)
downloadchromium_src-9008b35a1a6c49905694a93215148ec6d86696e5.zip
chromium_src-9008b35a1a6c49905694a93215148ec6d86696e5.tar.gz
chromium_src-9008b35a1a6c49905694a93215148ec6d86696e5.tar.bz2
Move email and domain canonicalization helper to common/net/gaia
This is in preparation for a CL that uses this functionality in non-chromeos code. BUG=None TEST=Compiles and passes tests, no functional changes. R=nkostylev@chromium.org TBR=arv@chromium.org Review URL: https://chromiumcodereview.appspot.com/10584039 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143899 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/cros_settings.cc6
-rw-r--r--chrome/browser/chromeos/login/authenticator.cc57
-rw-r--r--chrome/browser/chromeos/login/authenticator.h19
-rw-r--r--chrome/browser/chromeos/login/authenticator_unittest.cc87
-rw-r--r--chrome/browser/chromeos/login/enrollment/enterprise_enrollment_screen.cc9
-rw-r--r--chrome/browser/chromeos/login/login_performer.cc3
-rw-r--r--chrome/browser/chromeos/login/online_attempt_host.cc4
-rw-r--r--chrome/browser/chromeos/login/parallel_authenticator.cc9
-rw-r--r--chrome/browser/policy/device_policy_cache.cc5
-rw-r--r--chrome/browser/policy/enterprise_install_attributes.cc13
-rw-r--r--chrome/browser/policy/user_cloud_policy_store_chromeos.cc5
-rw-r--r--chrome/browser/ui/webui/chromeos/login/enterprise_oauth_enrollment_screen_handler.cc6
-rw-r--r--chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc6
-rw-r--r--chrome/browser/ui/webui/options2/chromeos/accounts_options_handler2.cc8
-rw-r--r--chrome/chrome_common.gypi2
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--chrome/common/net/gaia/gaia_auth_util.cc61
-rw-r--r--chrome/common/net/gaia/gaia_auth_util.h32
-rw-r--r--chrome/common/net/gaia/gaia_auth_util_unittest.cc87
19 files changed, 220 insertions, 201 deletions
diff --git a/chrome/browser/chromeos/cros_settings.cc b/chrome/browser/chromeos/cros_settings.cc
index 81e4560..df4e065f 100644
--- a/chrome/browser/chromeos/cros_settings.cc
+++ b/chrome/browser/chromeos/cros_settings.cc
@@ -11,12 +11,12 @@
#include "base/string_util.h"
#include "base/values.h"
#include "chrome/browser/chromeos/device_settings_provider.h"
-#include "chrome/browser/chromeos/login/authenticator.h"
#include "chrome/browser/chromeos/login/signed_settings_helper.h"
#include "chrome/browser/chromeos/stub_cros_settings_provider.h"
#include "chrome/browser/ui/webui/options2/chromeos/system_settings_provider2.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/net/gaia/gaia_auth_util.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
@@ -108,7 +108,7 @@ bool CrosSettings::FindEmailInList(const std::string& path,
const std::string& email) const {
DCHECK(CalledOnValidThread());
std::string canonicalized_email(
- Authenticator::Canonicalize(Authenticator::Sanitize(email)));
+ gaia::CanonicalizeEmail(gaia::SanitizeEmail(email)));
std::string wildcard_email;
std::string::size_type at_pos = canonicalized_email.find('@');
if (at_pos != std::string::npos) {
@@ -128,7 +128,7 @@ bool CrosSettings::FindEmailInList(const std::string& path,
continue;
}
std::string canonicalized_entry(
- Authenticator::Canonicalize(Authenticator::Sanitize(entry_string)));
+ gaia::CanonicalizeEmail(gaia::SanitizeEmail(entry_string)));
if (canonicalized_entry == canonicalized_email ||
canonicalized_entry == wildcard_email) {
diff --git a/chrome/browser/chromeos/login/authenticator.cc b/chrome/browser/chromeos/login/authenticator.cc
index 97abe06..0a641d5 100644
--- a/chrome/browser/chromeos/login/authenticator.cc
+++ b/chrome/browser/chromeos/login/authenticator.cc
@@ -4,71 +4,14 @@
#include "chrome/browser/chromeos/login/authenticator.h"
-#include <string>
-#include <vector>
-
-#include "base/logging.h"
-#include "base/string_split.h"
-#include "base/string_util.h"
-
namespace chromeos {
class LoginStatusConsumer;
-namespace {
-const char kGmailDomain[] = "gmail.com";
-}
-
Authenticator::Authenticator(LoginStatusConsumer* consumer)
: consumer_(consumer), authentication_profile_(NULL) {
}
Authenticator::~Authenticator() {}
-// static
-std::string Authenticator::Canonicalize(const std::string& email_address) {
- 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();
- else if (parts[1] == kGmailDomain) // only strip '.' for gmail accounts.
- RemoveChars(parts[0], ".", &parts[0]);
- std::string new_email = StringToLowerASCII(JoinString(parts, at));
- VLOG(1) << "Canonicalized " << email_address << " to " << new_email;
- return new_email;
-}
-
-// static
-std::string Authenticator::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.
- return StringToLowerASCII(domain);
-}
-
-// static
-std::string Authenticator::Sanitize(const std::string& email_address) {
- std::string sanitized(email_address);
-
- // Apply a default domain if necessary.
- if (sanitized.find('@') == std::string::npos) {
- sanitized += '@';
- sanitized += kGmailDomain;
- }
-
- return sanitized;
-}
-
-// static
-std::string Authenticator::ExtractDomainName(const std::string& email_address) {
- // First canonicalize which will also verify we have proper domain part.
- std::string email = Canonicalize(email_address);
- size_t separator_pos = email.find('@');
- if (separator_pos != email.npos && separator_pos < email.length() - 1)
- return email.substr(separator_pos + 1);
- else
- NOTREACHED() << "Not a proper email address: " << email;
- return std::string();
-}
-
} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/authenticator.h b/chrome/browser/chromeos/login/authenticator.h
index ab0e2f2..88fd043 100644
--- a/chrome/browser/chromeos/login/authenticator.h
+++ b/chrome/browser/chromeos/login/authenticator.h
@@ -6,6 +6,8 @@
#define CHROME_BROWSER_CHROMEOS_LOGIN_AUTHENTICATOR_H_
#pragma once
+#include <string>
+
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/chromeos/login/login_status_consumer.h"
@@ -90,23 +92,6 @@ class Authenticator : public base::RefCountedThreadSafe<Authenticator> {
// authentication process.
Profile* authentication_profile() { return authentication_profile_; }
- // 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#
- static std::string Canonicalize(const std::string& email_address);
-
- // Returns the canonical form of the given domain.
- static std::string CanonicalizeDomain(const std::string& domain);
-
- // Sanitize emails. Currently, it only ensures all emails have a domain by
- // adding gmail.com if no domain is present.
- static std::string Sanitize(const std::string& email_address);
-
- // Extract the domain part from the canonical form of the given email.
- static std::string ExtractDomainName(const std::string& email);
-
protected:
LoginStatusConsumer* consumer_;
Profile* authentication_profile_;
diff --git a/chrome/browser/chromeos/login/authenticator_unittest.cc b/chrome/browser/chromeos/login/authenticator_unittest.cc
deleted file mode 100644
index 0787df1..0000000
--- a/chrome/browser/chromeos/login/authenticator_unittest.cc
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/chromeos/login/authenticator.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace chromeos {
-
-TEST(AuthenticatorTest, EmailAddressNoOp) {
- const char lower_case[] = "user@what.com";
- EXPECT_EQ(lower_case, Authenticator::Canonicalize(lower_case));
-}
-
-TEST(AuthenticatorTest, EmailAddressIgnoreCaps) {
- EXPECT_EQ(Authenticator::Canonicalize("user@what.com"),
- Authenticator::Canonicalize("UsEr@what.com"));
-}
-
-TEST(AuthenticatorTest, EmailAddressIgnoreDomainCaps) {
- EXPECT_EQ(Authenticator::Canonicalize("user@what.com"),
- Authenticator::Canonicalize("UsEr@what.COM"));
-}
-
-TEST(AuthenticatorTest, EmailAddressRejectOneUsernameDot) {
- EXPECT_NE(Authenticator::Canonicalize("u.ser@what.com"),
- Authenticator::Canonicalize("UsEr@what.com"));
-}
-
-TEST(AuthenticatorTest, EmailAddressMatchWithOneUsernameDot) {
- EXPECT_EQ(Authenticator::Canonicalize("u.ser@what.com"),
- Authenticator::Canonicalize("U.sEr@what.com"));
-}
-
-TEST(AuthenticatorTest, EmailAddressIgnoreOneUsernameDot) {
- EXPECT_EQ(Authenticator::Canonicalize("us.er@gmail.com"),
- Authenticator::Canonicalize("UsEr@gmail.com"));
-}
-
-TEST(AuthenticatorTest, EmailAddressIgnoreManyUsernameDots) {
- EXPECT_EQ(Authenticator::Canonicalize("u.ser@gmail.com"),
- Authenticator::Canonicalize("Us.E.r@gmail.com"));
-}
-
-TEST(AuthenticatorTest, EmailAddressIgnoreConsecutiveUsernameDots) {
- EXPECT_EQ(Authenticator::Canonicalize("use.r@gmail.com"),
- Authenticator::Canonicalize("Us....E.r@gmail.com"));
-}
-
-TEST(AuthenticatorTest, EmailAddressDifferentOnesRejected) {
- EXPECT_NE(Authenticator::Canonicalize("who@what.com"),
- Authenticator::Canonicalize("Us....E.r@what.com"));
-}
-
-TEST(AuthenticatorTest, EmailAddressIgnorePlusSuffix) {
- const char with_plus[] = "user+cc@what.com";
- EXPECT_EQ(with_plus, Authenticator::Canonicalize(with_plus));
-}
-
-TEST(AuthenticatorTest, EmailAddressIgnoreMultiPlusSuffix) {
- const char multi_plus[] = "user+cc+bcc@what.com";
- EXPECT_EQ(multi_plus, Authenticator::Canonicalize(multi_plus));
-}
-
-TEST(AuthenticatorTest, CanonicalizeDomain) {
- const char domain[] = "example.com";
- EXPECT_EQ(domain, Authenticator::CanonicalizeDomain("example.com"));
- EXPECT_EQ(domain, Authenticator::CanonicalizeDomain("EXAMPLE.cOm"));
-}
-
-TEST(AuthenticatorTest, ExtractDomainName) {
- const char domain[] = "example.com";
- EXPECT_EQ(domain, Authenticator::ExtractDomainName("who@example.com"));
- EXPECT_EQ(domain, Authenticator::ExtractDomainName("who@EXAMPLE.cOm"));
-}
-
-TEST(AuthenticatorTest, SanitizeMissingDomain) {
- EXPECT_EQ("nodomain@gmail.com", Authenticator::Sanitize("nodomain"));
-}
-
-TEST(AuthenticatorTest, SanitizeExistingDomain) {
- const char existing[] = "test@example.com";
- EXPECT_EQ(existing, Authenticator::Sanitize(existing));
-}
-
-} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/enrollment/enterprise_enrollment_screen.cc b/chrome/browser/chromeos/login/enrollment/enterprise_enrollment_screen.cc
index 359dde4..d076869 100644
--- a/chrome/browser/chromeos/login/enrollment/enterprise_enrollment_screen.cc
+++ b/chrome/browser/chromeos/login/enrollment/enterprise_enrollment_screen.cc
@@ -11,13 +11,13 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/cryptohome_library.h"
-#include "chrome/browser/chromeos/login/authenticator.h"
#include "chrome/browser/chromeos/login/screen_observer.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/policy/auto_enrollment_client.h"
#include "chrome/browser/policy/browser_policy_connector.h"
#include "chrome/browser/policy/cloud_policy_data_store.h"
#include "chrome/browser/policy/enterprise_metrics.h"
+#include "chrome/common/net/gaia/gaia_auth_util.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/session_manager_client.h"
@@ -59,7 +59,7 @@ EnterpriseEnrollmentScreen::~EnterpriseEnrollmentScreen() {}
void EnterpriseEnrollmentScreen::SetParameters(bool is_auto_enrollment,
const std::string& user) {
is_auto_enrollment_ = is_auto_enrollment;
- user_ = user.empty() ? user : Authenticator::Canonicalize(user);
+ user_ = user.empty() ? user : gaia::CanonicalizeEmail(user);
}
void EnterpriseEnrollmentScreen::PrepareToShow() {
@@ -83,7 +83,7 @@ std::string EnterpriseEnrollmentScreen::GetName() const {
void EnterpriseEnrollmentScreen::OnOAuthTokenAvailable(
const std::string& user,
const std::string& token) {
- user_ = Authenticator::Canonicalize(user);
+ user_ = gaia::CanonicalizeEmail(user);
RegisterForDevicePolicy(token);
}
@@ -233,8 +233,7 @@ void EnterpriseEnrollmentScreen::RegisterForDevicePolicy(
LOG(ERROR) << "A previous enrollment already succeeded!";
} else {
if (connector->IsEnterpriseManaged() &&
- connector->GetEnterpriseDomain() !=
- chromeos::Authenticator::ExtractDomainName(user_)) {
+ connector->GetEnterpriseDomain() != gaia::ExtractDomainName(user_)) {
LOG(ERROR) << "Trying to re-enroll to a different domain than "
<< connector->GetEnterpriseDomain();
if (is_showing_)
diff --git a/chrome/browser/chromeos/login/login_performer.cc b/chrome/browser/chromeos/login/login_performer.cc
index 4ceb8bf..5a77afc 100644
--- a/chrome/browser/chromeos/login/login_performer.cc
+++ b/chrome/browser/chromeos/login/login_performer.cc
@@ -25,6 +25,7 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/net/gaia/gaia_auth_util.h"
#include "chrome/common/pref_names.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager_client.h"
@@ -290,7 +291,7 @@ void LoginPerformer::CompleteLogin(const std::string& username,
}
bool is_whitelisted = LoginUtils::IsWhitelisted(
- Authenticator::Canonicalize(username));
+ gaia::CanonicalizeEmail(username));
if (ScreenLocker::default_screen_locker() || is_whitelisted) {
// Starts authentication if guest login is allowed or online auth pending.
StartLoginCompletion();
diff --git a/chrome/browser/chromeos/login/online_attempt_host.cc b/chrome/browser/chromeos/login/online_attempt_host.cc
index d2464e8..8674bd5 100644
--- a/chrome/browser/chromeos/login/online_attempt_host.cc
+++ b/chrome/browser/chromeos/login/online_attempt_host.cc
@@ -7,9 +7,9 @@
#include "base/bind.h"
#include "base/sha1.h"
#include "chrome/browser/chromeos/login/auth_attempt_state.h"
-#include "chrome/browser/chromeos/login/authenticator.h"
#include "chrome/browser/chromeos/login/online_attempt.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/net/gaia/gaia_auth_util.h"
#include "content/public/browser/browser_thread.h"
namespace chromeos {
@@ -34,7 +34,7 @@ void OnlineAttemptHost::Check(Profile* profile,
state_.reset(
new AuthAttemptState(
- Authenticator::Canonicalize(username),
+ gaia::CanonicalizeEmail(username),
password,
std::string(),
std::string(),
diff --git a/chrome/browser/chromeos/login/parallel_authenticator.cc b/chrome/browser/chromeos/login/parallel_authenticator.cc
index ddd2c3b..d6ccdde 100644
--- a/chrome/browser/chromeos/login/parallel_authenticator.cc
+++ b/chrome/browser/chromeos/login/parallel_authenticator.cc
@@ -22,6 +22,7 @@
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/net/gaia/gaia_auth_util.h"
#include "chromeos/dbus/cryptohome_client.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "content/public/browser/browser_thread.h"
@@ -188,7 +189,7 @@ void ParallelAuthenticator::AuthenticateToLogin(
const std::string& password,
const std::string& login_token,
const std::string& login_captcha) {
- std::string canonicalized = Authenticator::Canonicalize(username);
+ std::string canonicalized = gaia::CanonicalizeEmail(username);
authentication_profile_ = profile;
current_state_.reset(
new AuthAttemptState(
@@ -225,7 +226,7 @@ void ParallelAuthenticator::AuthenticateToLogin(
void ParallelAuthenticator::CompleteLogin(Profile* profile,
const std::string& username,
const std::string& password) {
- std::string canonicalized = Authenticator::Canonicalize(username);
+ std::string canonicalized = gaia::CanonicalizeEmail(username);
authentication_profile_ = profile;
current_state_.reset(
new AuthAttemptState(
@@ -270,7 +271,7 @@ void ParallelAuthenticator::AuthenticateToUnlock(const std::string& username,
const std::string& password) {
current_state_.reset(
new AuthAttemptState(
- Authenticator::Canonicalize(username),
+ gaia::CanonicalizeEmail(username),
CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(password)));
check_key_attempted_ = true;
BrowserThread::PostTask(
@@ -431,7 +432,7 @@ void ParallelAuthenticator::RetryAuth(Profile* profile,
const std::string& login_captcha) {
reauth_state_.reset(
new AuthAttemptState(
- Authenticator::Canonicalize(username),
+ gaia::CanonicalizeEmail(username),
password,
CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(password),
login_token,
diff --git a/chrome/browser/policy/device_policy_cache.cc b/chrome/browser/policy/device_policy_cache.cc
index a9fcce9..29e2225 100644
--- a/chrome/browser/policy/device_policy_cache.cc
+++ b/chrome/browser/policy/device_policy_cache.cc
@@ -16,7 +16,6 @@
#include "base/metrics/histogram.h"
#include "base/values.h"
#include "chrome/browser/chromeos/cros_settings.h"
-#include "chrome/browser/chromeos/login/authenticator.h"
#include "chrome/browser/chromeos/login/ownership_service.h"
#include "chrome/browser/chromeos/login/signed_settings_helper.h"
#include "chrome/browser/policy/app_pack_updater.h"
@@ -26,6 +25,7 @@
#include "chrome/browser/policy/policy_map.h"
#include "chrome/browser/policy/proto/device_management_backend.pb.h"
#include "chrome/browser/policy/proto/device_management_local.pb.h"
+#include "chrome/common/net/gaia/gaia_auth_util.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/update_engine_client.h"
#include "policy/policy_constants.h"
@@ -191,8 +191,7 @@ bool DevicePolicyCache::SetPolicy(const em::PolicyFetchResponse& policy) {
// Existing installations may not have a canonicalized version of the
// registration domain in install attributes, so lower-case the data here.
- if (registration_domain !=
- chromeos::Authenticator::ExtractDomainName(policy_data.username())) {
+ if (registration_domain != gaia::ExtractDomainName(policy_data.username())) {
LOG(WARNING) << "Refusing policy blob for " << policy_data.username()
<< " which doesn't match domain " << registration_domain;
UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchUserMismatch,
diff --git a/chrome/browser/policy/enterprise_install_attributes.cc b/chrome/browser/policy/enterprise_install_attributes.cc
index 6b3d868..277bf90 100644
--- a/chrome/browser/policy/enterprise_install_attributes.cc
+++ b/chrome/browser/policy/enterprise_install_attributes.cc
@@ -6,7 +6,7 @@
#include "base/logging.h"
#include "chrome/browser/chromeos/cros/cryptohome_library.h"
-#include "chrome/browser/chromeos/login/authenticator.h"
+#include "chrome/common/net/gaia/gaia_auth_util.h"
namespace policy {
@@ -69,7 +69,7 @@ EnterpriseInstallAttributes::LockResult EnterpriseInstallAttributes::LockDevice(
CHECK_NE(device_mode, DEVICE_MODE_PENDING);
CHECK_NE(device_mode, DEVICE_MODE_NOT_SET);
- std::string domain = chromeos::Authenticator::ExtractDomainName(user);
+ std::string domain = gaia::ExtractDomainName(user);
// Check for existing lock first.
if (device_locked_) {
@@ -168,8 +168,7 @@ void EnterpriseInstallAttributes::ReadImmutableAttributes() {
&enterprise_user) &&
enterprise_owned == "true" &&
!enterprise_user.empty()) {
- registration_user_ =
- chromeos::Authenticator::Canonicalize(enterprise_user);
+ registration_user_ = gaia::CanonicalizeEmail(enterprise_user);
// Initialize the mode to the legacy enterprise mode here and update
// below if more information is present.
@@ -181,11 +180,9 @@ void EnterpriseInstallAttributes::ReadImmutableAttributes() {
// pre 19 revisions of the code, before these new attributes were added.
if (cryptohome_->InstallAttributesGet(kAttrEnterpriseDomain,
&registration_domain_)) {
- registration_domain_ =
- chromeos::Authenticator::CanonicalizeDomain(registration_domain_);
+ registration_domain_ = gaia::CanonicalizeDomain(registration_domain_);
} else {
- registration_domain_ =
- chromeos::Authenticator::ExtractDomainName(registration_user_);
+ registration_domain_ = gaia::ExtractDomainName(registration_user_);
}
if (!cryptohome_->InstallAttributesGet(kAttrEnterpriseDeviceId,
&registration_device_id_)) {
diff --git a/chrome/browser/policy/user_cloud_policy_store_chromeos.cc b/chrome/browser/policy/user_cloud_policy_store_chromeos.cc
index cb1bf3f..aaf9f4e 100644
--- a/chrome/browser/policy/user_cloud_policy_store_chromeos.cc
+++ b/chrome/browser/policy/user_cloud_policy_store_chromeos.cc
@@ -10,12 +10,12 @@
#include "base/callback.h"
#include "base/file_util.h"
#include "base/memory/ref_counted.h"
-#include "chrome/browser/chromeos/login/authenticator.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/policy/proto/cloud_policy.pb.h"
#include "chrome/browser/policy/proto/device_management_local.pb.h"
#include "chrome/browser/policy/user_policy_disk_cache.h"
#include "chrome/browser/policy/user_policy_token_cache.h"
+#include "chrome/common/net/gaia/gaia_auth_util.h"
#include "chromeos/dbus/session_manager_client.h"
#include "content/public/browser/browser_thread.h"
@@ -352,8 +352,7 @@ bool UserCloudPolicyStoreChromeOS::CheckPolicyUsername(
return false;
std::string policy_username =
- chromeos::Authenticator::Canonicalize(
- chromeos::Authenticator::Sanitize(policy.username()));
+ gaia::CanonicalizeEmail(gaia::SanitizeEmail(policy.username()));
const chromeos::User& user = chromeos::UserManager::Get()->GetLoggedInUser();
return user.email() == policy_username;
}
diff --git a/chrome/browser/ui/webui/chromeos/login/enterprise_oauth_enrollment_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/enterprise_oauth_enrollment_screen_handler.cc
index 3ad1a03..b548126 100644
--- a/chrome/browser/ui/webui/chromeos/login/enterprise_oauth_enrollment_screen_handler.cc
+++ b/chrome/browser/ui/webui/chromeos/login/enterprise_oauth_enrollment_screen_handler.cc
@@ -12,13 +12,13 @@
#include "base/metrics/histogram.h"
#include "chrome/browser/browsing_data_helper.h"
#include "chrome/browser/browsing_data_remover.h"
-#include "chrome/browser/chromeos/login/authenticator.h"
#include "chrome/browser/chromeos/login/login_utils.h"
#include "chrome/browser/net/gaia/gaia_oauth_fetcher.h"
#include "chrome/browser/policy/auto_enrollment_client.h"
#include "chrome/browser/policy/enterprise_metrics.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/net/gaia/gaia_auth_util.h"
#include "chrome/common/net/gaia/gaia_constants.h"
#include "chrome/common/net/gaia/gaia_urls.h"
#include "chrome/common/net/gaia/google_service_auth_error.h"
@@ -141,7 +141,7 @@ void EnterpriseOAuthEnrollmentScreenHandler::Show() {
std::string user;
is_auto_enrollment_ = controller_ && controller_->IsAutoEnrollment(&user);
if (is_auto_enrollment_)
- user_ = Authenticator::Sanitize(user);
+ user_ = gaia::SanitizeEmail(user);
enrollment_failed_once_ = false;
DoShow();
@@ -430,7 +430,7 @@ void EnterpriseOAuthEnrollmentScreenHandler::HandleCompleteLogin(
return;
}
- user_ = Authenticator::Sanitize(user);
+ user_ = gaia::SanitizeEmail(user);
EnrollAfterLogin();
}
diff --git a/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc
index adde919..59b6205 100644
--- a/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc
+++ b/chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc
@@ -22,7 +22,6 @@
#include "chrome/browser/chromeos/input_method/input_method_manager.h"
#include "chrome/browser/chromeos/input_method/xkeyboard.h"
#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
-#include "chrome/browser/chromeos/login/authenticator.h"
#include "chrome/browser/chromeos/login/base_login_display_host.h"
#include "chrome/browser/chromeos/login/captive_portal_window_proxy.h"
#include "chrome/browser/chromeos/login/screen_locker.h"
@@ -32,6 +31,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/net/gaia/gaia_auth_util.h"
#include "chrome/common/net/gaia/gaia_urls.h"
#include "chrome/common/url_constants.h"
#include "chromeos/dbus/dbus_thread_manager.h"
@@ -712,7 +712,7 @@ void SigninScreenHandler::HandleCompleteLogin(const base::ListValue* args) {
return;
}
- typed_email = Authenticator::Sanitize(typed_email);
+ typed_email = gaia::SanitizeEmail(typed_email);
delegate_->SetDisplayEmail(typed_email);
delegate_->CompleteLogin(typed_email, password);
}
@@ -729,7 +729,7 @@ void SigninScreenHandler::HandleAuthenticateUser(const base::ListValue* args) {
return;
}
- username = Authenticator::Sanitize(username);
+ username = gaia::SanitizeEmail(username);
delegate_->Login(username, password);
}
diff --git a/chrome/browser/ui/webui/options2/chromeos/accounts_options_handler2.cc b/chrome/browser/ui/webui/options2/chromeos/accounts_options_handler2.cc
index eff8ce73..3a2e950 100644
--- a/chrome/browser/ui/webui/options2/chromeos/accounts_options_handler2.cc
+++ b/chrome/browser/ui/webui/options2/chromeos/accounts_options_handler2.cc
@@ -15,11 +15,11 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/cros_settings.h"
#include "chrome/browser/chromeos/cros_settings_names.h"
-#include "chrome/browser/chromeos/login/authenticator.h"
#include "chrome/browser/chromeos/login/user_manager.h"
-#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/policy/browser_policy_connector.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/ui/webui/chromeos/ui_account_tweaks.h"
+#include "chrome/common/net/gaia/gaia_auth_util.h"
#include "content/public/browser/web_ui.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
@@ -97,7 +97,7 @@ void AccountsOptionsHandler::HandleWhitelistUser(const base::ListValue* args) {
return;
}
- WhitelistUser(Authenticator::Canonicalize(typed_email));
+ WhitelistUser(gaia::CanonicalizeEmail(typed_email));
}
void AccountsOptionsHandler::HandleUnwhitelistUser(
@@ -107,7 +107,7 @@ void AccountsOptionsHandler::HandleUnwhitelistUser(
return;
}
- base::StringValue canonical_email(Authenticator::Canonicalize(email));
+ base::StringValue canonical_email(gaia::CanonicalizeEmail(email));
CrosSettings::Get()->RemoveFromList(kAccountsPrefUsers, &canonical_email);
UserManager::Get()->RemoveUser(email, NULL);
}
diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi
index 5b608c3..efc13e4 100644
--- a/chrome/chrome_common.gypi
+++ b/chrome/chrome_common.gypi
@@ -422,6 +422,8 @@
'common/net/gaia/gaia_auth_consumer.h',
'common/net/gaia/gaia_auth_fetcher.cc',
'common/net/gaia/gaia_auth_fetcher.h',
+ 'common/net/gaia/gaia_auth_util.cc',
+ 'common/net/gaia/gaia_auth_util.h',
'common/net/gaia/gaia_authenticator.cc',
'common/net/gaia/gaia_authenticator.h',
'common/net/gaia/gaia_oauth_client.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 687a53c..f9ec66d 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1120,7 +1120,6 @@
'browser/chromeos/kiosk_mode/kiosk_mode_screensaver_unittest.cc',
'browser/chromeos/kiosk_mode/kiosk_mode_settings_unittest.cc',
'browser/chromeos/language_preferences_unittest.cc',
- 'browser/chromeos/login/authenticator_unittest.cc',
'browser/chromeos/login/mock_auth_attempt_state_resolver.cc',
'browser/chromeos/login/mock_auth_attempt_state_resolver.h',
'browser/chromeos/login/mock_owner_key_utils.cc',
@@ -1936,6 +1935,7 @@
'common/multi_process_lock_unittest.cc',
'common/net/url_util_unittest.cc',
'common/net/gaia/gaia_auth_fetcher_unittest.cc',
+ 'common/net/gaia/gaia_auth_util_unittest.cc',
'common/net/gaia/gaia_authenticator_unittest.cc',
'common/net/gaia/gaia_oauth_client_unittest.cc',
'common/net/gaia/google_service_auth_error_unittest.cc',
diff --git a/chrome/common/net/gaia/gaia_auth_util.cc b/chrome/common/net/gaia/gaia_auth_util.cc
new file mode 100644
index 0000000..ec9f421
--- /dev/null
+++ b/chrome/common/net/gaia/gaia_auth_util.cc
@@ -0,0 +1,61 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/net/gaia/gaia_auth_util.h"
+
+#include <vector>
+
+#include "base/logging.h"
+#include "base/string_split.h"
+#include "base/string_util.h"
+
+namespace gaia {
+
+namespace {
+const char kGmailDomain[] = "gmail.com";
+}
+
+std::string CanonicalizeEmail(const std::string& email_address) {
+ 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();
+ else if (parts[1] == kGmailDomain) // only strip '.' for gmail accounts.
+ RemoveChars(parts[0], ".", &parts[0]);
+ std::string new_email = StringToLowerASCII(JoinString(parts, at));
+ VLOG(1) << "Canonicalized " << email_address << " to " << new_email;
+ return new_email;
+}
+
+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.
+ return StringToLowerASCII(domain);
+}
+
+std::string SanitizeEmail(const std::string& email_address) {
+ std::string sanitized(email_address);
+
+ // Apply a default domain if necessary.
+ if (sanitized.find('@') == std::string::npos) {
+ sanitized += '@';
+ sanitized += kGmailDomain;
+ }
+
+ return sanitized;
+}
+
+std::string ExtractDomainName(const std::string& email_address) {
+ // First canonicalize which will also verify we have proper domain part.
+ std::string email = CanonicalizeEmail(email_address);
+ size_t separator_pos = email.find('@');
+ if (separator_pos != email.npos && separator_pos < email.length() - 1)
+ return email.substr(separator_pos + 1);
+ else
+ NOTREACHED() << "Not a proper email address: " << email;
+ return std::string();
+}
+
+} // namespace gaia
diff --git a/chrome/common/net/gaia/gaia_auth_util.h b/chrome/common/net/gaia/gaia_auth_util.h
new file mode 100644
index 0000000..2d4ab00
--- /dev/null
+++ b/chrome/common/net/gaia/gaia_auth_util.h
@@ -0,0 +1,32 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_NET_GAIA_GAIA_AUTH_UTIL_H_
+#define CHROME_COMMON_NET_GAIA_GAIA_AUTH_UTIL_H_
+#pragma once
+
+#include <string>
+
+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#
+std::string CanonicalizeEmail(const std::string& email_address);
+
+// Returns the canonical form of the given domain.
+std::string CanonicalizeDomain(const std::string& domain);
+
+// Sanitize emails. Currently, it only ensures all emails have a domain by
+// adding gmail.com if no domain is present.
+std::string SanitizeEmail(const std::string& email_address);
+
+// Extract the domain part from the canonical form of the given email.
+std::string ExtractDomainName(const std::string& email);
+
+} // namespace gaia
+
+#endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_UTIL_H_
diff --git a/chrome/common/net/gaia/gaia_auth_util_unittest.cc b/chrome/common/net/gaia/gaia_auth_util_unittest.cc
new file mode 100644
index 0000000..0f7c702
--- /dev/null
+++ b/chrome/common/net/gaia/gaia_auth_util_unittest.cc
@@ -0,0 +1,87 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/net/gaia/gaia_auth_util.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace gaia {
+
+TEST(GaiaAuthUtilTest, EmailAddressNoOp) {
+ const char lower_case[] = "user@what.com";
+ EXPECT_EQ(lower_case, CanonicalizeEmail(lower_case));
+}
+
+TEST(GaiaAuthUtilTest, EmailAddressIgnoreCaps) {
+ EXPECT_EQ(CanonicalizeEmail("user@what.com"),
+ CanonicalizeEmail("UsEr@what.com"));
+}
+
+TEST(GaiaAuthUtilTest, EmailAddressIgnoreDomainCaps) {
+ EXPECT_EQ(CanonicalizeEmail("user@what.com"),
+ CanonicalizeEmail("UsEr@what.COM"));
+}
+
+TEST(GaiaAuthUtilTest, EmailAddressRejectOneUsernameDot) {
+ EXPECT_NE(CanonicalizeEmail("u.ser@what.com"),
+ CanonicalizeEmail("UsEr@what.com"));
+}
+
+TEST(GaiaAuthUtilTest, EmailAddressMatchWithOneUsernameDot) {
+ EXPECT_EQ(CanonicalizeEmail("u.ser@what.com"),
+ CanonicalizeEmail("U.sEr@what.com"));
+}
+
+TEST(GaiaAuthUtilTest, EmailAddressIgnoreOneUsernameDot) {
+ EXPECT_EQ(CanonicalizeEmail("us.er@gmail.com"),
+ CanonicalizeEmail("UsEr@gmail.com"));
+}
+
+TEST(GaiaAuthUtilTest, EmailAddressIgnoreManyUsernameDots) {
+ EXPECT_EQ(CanonicalizeEmail("u.ser@gmail.com"),
+ CanonicalizeEmail("Us.E.r@gmail.com"));
+}
+
+TEST(GaiaAuthUtilTest, EmailAddressIgnoreConsecutiveUsernameDots) {
+ EXPECT_EQ(CanonicalizeEmail("use.r@gmail.com"),
+ CanonicalizeEmail("Us....E.r@gmail.com"));
+}
+
+TEST(GaiaAuthUtilTest, EmailAddressDifferentOnesRejected) {
+ EXPECT_NE(CanonicalizeEmail("who@what.com"),
+ 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, CanonicalizeDomain) {
+ const char domain[] = "example.com";
+ EXPECT_EQ(domain, CanonicalizeDomain("example.com"));
+ EXPECT_EQ(domain, CanonicalizeDomain("EXAMPLE.cOm"));
+}
+
+TEST(GaiaAuthUtilTest, ExtractDomainName) {
+ const char domain[] = "example.com";
+ EXPECT_EQ(domain, ExtractDomainName("who@example.com"));
+ EXPECT_EQ(domain, ExtractDomainName("who@EXAMPLE.cOm"));
+}
+
+TEST(GaiaAuthUtilTest, SanitizeMissingDomain) {
+ EXPECT_EQ("nodomain@gmail.com", SanitizeEmail("nodomain"));
+}
+
+TEST(GaiaAuthUtilTest, SanitizeExistingDomain) {
+ const char existing[] = "test@example.com";
+ EXPECT_EQ(existing, SanitizeEmail(existing));
+}
+
+} // namespace gaia