summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcmasone@chromium.org <cmasone@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-28 04:38:08 +0000
committercmasone@chromium.org <cmasone@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-28 04:38:08 +0000
commitc61f5aac1ffcda0e5a835ed2dd8144b825582a5b (patch)
treef9e781dd3cc079c4b728c4b6e42f12f666b83465
parent3e50e07a989d21dea45745ee0a136a23637d4e68 (diff)
downloadchromium_src-c61f5aac1ffcda0e5a835ed2dd8144b825582a5b.zip
chromium_src-c61f5aac1ffcda0e5a835ed2dd8144b825582a5b.tar.gz
chromium_src-c61f5aac1ffcda0e5a835ed2dd8144b825582a5b.tar.bz2
[Chrome OS] Refactor Canonicalize() method into base class to prepare for new Authenticator subclass
BUG=chromium-os:4929 TEST=unit tests Review URL: http://codereview.chromium.org/3436031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60752 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/login/authenticator.cc37
-rw-r--r--chrome/browser/chromeos/login/authenticator.h14
-rw-r--r--chrome/browser/chromeos/login/authenticator_unittest.cc56
-rw-r--r--chrome/browser/chromeos/login/google_authenticator.cc16
-rw-r--r--chrome/browser/chromeos/login/google_authenticator.h6
-rw-r--r--chrome/browser/chromeos/login/google_authenticator_unittest.cc48
-rw-r--r--chrome/browser/chromeos/login/mock_authenticator.h1
-rw-r--r--chrome/browser/chromeos/login/screen_locker.cc1
-rw-r--r--chrome/browser/chromeos/login/user_image_downloader.cc4
-rw-r--r--chrome/chrome_browser.gypi3
-rw-r--r--chrome/chrome_tests.gypi1
11 files changed, 111 insertions, 76 deletions
diff --git a/chrome/browser/chromeos/login/authenticator.cc b/chrome/browser/chromeos/login/authenticator.cc
new file mode 100644
index 0000000..1ca3378a
--- /dev/null
+++ b/chrome/browser/chromeos/login/authenticator.cc
@@ -0,0 +1,37 @@
+// Copyright (c) 2010 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 <string>
+#include <vector>
+
+#include "base/logging.h"
+#include "base/string_split.h"
+#include "base/string_util.h"
+
+namespace chromeos {
+class LoginStatusConsumer;
+
+Authenticator::Authenticator(LoginStatusConsumer* consumer)
+ : consumer_(consumer) {
+}
+
+Authenticator::~Authenticator() {}
+
+// static
+std::string Authenticator::Canonicalize(const std::string& email_address) {
+ std::vector<std::string> parts;
+ char at = '@';
+ SplitString(email_address, at, &parts);
+ DCHECK_EQ(parts.size(), 2U) << "email_address should have only one @";
+ RemoveChars(parts[0], ".", &parts[0]);
+ if (parts[0].find('+') != std::string::npos)
+ parts[0].erase(parts[0].find('+'));
+ std::string new_email = StringToLowerASCII(JoinString(parts, at));
+ LOG(INFO) << "Canonicalized " << email_address << " to " << new_email;
+ return new_email;
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/authenticator.h b/chrome/browser/chromeos/login/authenticator.h
index 613b7fa..5fba9c3 100644
--- a/chrome/browser/chromeos/login/authenticator.h
+++ b/chrome/browser/chromeos/login/authenticator.h
@@ -8,7 +8,6 @@
#include "base/basictypes.h"
#include "base/ref_counted.h"
-#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/chromeos/login/login_status_consumer.h"
#include "chrome/common/net/gaia/gaia_auth_consumer.h"
@@ -24,10 +23,8 @@ namespace chromeos {
// consumer_->OnPasswordChangeDetected() on the UI thread.
class Authenticator : public base::RefCountedThreadSafe<Authenticator> {
public:
- explicit Authenticator(LoginStatusConsumer* consumer)
- : consumer_(consumer) {
- }
- virtual ~Authenticator() {}
+ explicit Authenticator(LoginStatusConsumer* consumer);
+ virtual ~Authenticator();
// Given a |username| and |password|, this method attempts to authenticate
// to login.
@@ -74,6 +71,13 @@ class Authenticator : public base::RefCountedThreadSafe<Authenticator> {
virtual void ResyncEncryptedData(
const GaiaAuthConsumer::ClientLoginResult& credentials) = 0;
+ // 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);
+
protected:
LoginStatusConsumer* consumer_;
diff --git a/chrome/browser/chromeos/login/authenticator_unittest.cc b/chrome/browser/chromeos/login/authenticator_unittest.cc
new file mode 100644
index 0000000..48ab378
--- /dev/null
+++ b/chrome/browser/chromeos/login/authenticator_unittest.cc
@@ -0,0 +1,56 @@
+// Copyright (c) 2010 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, EmailAddressIgnoreOneUsernameDot) {
+ EXPECT_EQ(Authenticator::Canonicalize("us.er@what.com"),
+ Authenticator::Canonicalize("UsEr@what.com"));
+}
+
+TEST(AuthenticatorTest, EmailAddressIgnoreManyUsernameDots) {
+ EXPECT_EQ(Authenticator::Canonicalize("u.ser@what.com"),
+ Authenticator::Canonicalize("Us.E.r@what.com"));
+}
+
+TEST(AuthenticatorTest, EmailAddressIgnoreConsecutiveUsernameDots) {
+ EXPECT_EQ(Authenticator::Canonicalize("use.r@what.com"),
+ Authenticator::Canonicalize("Us....E.r@what.com"));
+}
+
+TEST(AuthenticatorTest, EmailAddressDifferentOnesRejected) {
+ EXPECT_NE(Authenticator::Canonicalize("who@what.com"),
+ Authenticator::Canonicalize("Us....E.r@what.com"));
+}
+
+TEST(AuthenticatorTest, EmailAddressIgnorePlusSuffix) {
+ EXPECT_EQ(Authenticator::Canonicalize("user+cc@what.com"),
+ Authenticator::Canonicalize("user@what.com"));
+}
+
+TEST(AuthenticatorTest, EmailAddressIgnoreMultiPlusSuffix) {
+ EXPECT_EQ(Authenticator::Canonicalize("user+cc+bcc@what.com"),
+ Authenticator::Canonicalize("user@what.com"));
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/google_authenticator.cc b/chrome/browser/chromeos/login/google_authenticator.cc
index d1b23d5..f6e53b4 100644
--- a/chrome/browser/chromeos/login/google_authenticator.cc
+++ b/chrome/browser/chromeos/login/google_authenticator.cc
@@ -13,7 +13,6 @@
#include "base/logging.h"
#include "base/path_service.h"
#include "base/sha2.h"
-#include "base/string_split.h"
#include "base/string_util.h"
#include "base/third_party/nss/blapi.h"
#include "base/third_party/nss/sha256.h"
@@ -435,19 +434,4 @@ bool GoogleAuthenticator::BinaryToHex(const std::vector<unsigned char>& binary,
return true;
}
-// static
-std::string GoogleAuthenticator::Canonicalize(
- const std::string& email_address) {
- std::vector<std::string> parts;
- char at = '@';
- SplitString(email_address, at, &parts);
- DCHECK_EQ(parts.size(), 2U) << "email_address should have only one @";
- RemoveChars(parts[0], ".", &parts[0]);
- if (parts[0].find('+') != std::string::npos)
- parts[0].erase(parts[0].find('+'));
- std::string new_email = StringToLowerASCII(JoinString(parts, at));
- LOG(INFO) << "Canonicalized " << email_address << " to " << new_email;
- return new_email;
-}
-
} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/google_authenticator.h b/chrome/browser/chromeos/login/google_authenticator.h
index be3662f..7c71952 100644
--- a/chrome/browser/chromeos/login/google_authenticator.h
+++ b/chrome/browser/chromeos/login/google_authenticator.h
@@ -85,12 +85,6 @@ class GoogleAuthenticator : public Authenticator, public GaiaAuthConsumer {
void ResyncEncryptedData(
const GaiaAuthConsumer::ClientLoginResult& credentials);
- // Perform basic canonicalization of |email_address|, taking into account
- // that gmail does not consider '.' or caps inside a username to matter.
- // For example, c.masone@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);
-
// Callbacks from GaiaAuthenticator2
virtual void OnClientLoginFailure(
const GoogleServiceAuthError& error);
diff --git a/chrome/browser/chromeos/login/google_authenticator_unittest.cc b/chrome/browser/chromeos/login/google_authenticator_unittest.cc
index 68877c3..6762f88 100644
--- a/chrome/browser/chromeos/login/google_authenticator_unittest.cc
+++ b/chrome/browser/chromeos/login/google_authenticator_unittest.cc
@@ -2,6 +2,8 @@
// 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/google_authenticator.h"
+
#include <string>
#include <vector>
@@ -16,7 +18,6 @@
#include "chrome/browser/chromeos/cros/mock_cryptohome_library.h"
#include "chrome/browser/chromeos/cros/mock_library_loader.h"
#include "chrome/browser/chromeos/login/client_login_response_handler.h"
-#include "chrome/browser/chromeos/login/google_authenticator.h"
#include "chrome/browser/chromeos/login/issue_response_handler.h"
#include "chrome/browser/chromeos/login/mock_auth_response_handler.h"
#include "chrome/browser/chromeos/login/mock_url_fetchers.h"
@@ -171,51 +172,6 @@ TEST_F(GoogleAuthenticatorTest, SaltToAscii) {
EXPECT_EQ("0a010000000000a0", auth->SaltAsAscii());
}
-TEST_F(GoogleAuthenticatorTest, EmailAddressNoOp) {
- const char lower_case[] = "user@what.com";
- EXPECT_EQ(lower_case, GoogleAuthenticator::Canonicalize(lower_case));
-}
-
-TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreCaps) {
- EXPECT_EQ(GoogleAuthenticator::Canonicalize("user@what.com"),
- GoogleAuthenticator::Canonicalize("UsEr@what.com"));
-}
-
-TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreDomainCaps) {
- EXPECT_EQ(GoogleAuthenticator::Canonicalize("user@what.com"),
- GoogleAuthenticator::Canonicalize("UsEr@what.COM"));
-}
-
-TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreOneUsernameDot) {
- EXPECT_EQ(GoogleAuthenticator::Canonicalize("us.er@what.com"),
- GoogleAuthenticator::Canonicalize("UsEr@what.com"));
-}
-
-TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreManyUsernameDots) {
- EXPECT_EQ(GoogleAuthenticator::Canonicalize("u.ser@what.com"),
- GoogleAuthenticator::Canonicalize("Us.E.r@what.com"));
-}
-
-TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreConsecutiveUsernameDots) {
- EXPECT_EQ(GoogleAuthenticator::Canonicalize("use.r@what.com"),
- GoogleAuthenticator::Canonicalize("Us....E.r@what.com"));
-}
-
-TEST_F(GoogleAuthenticatorTest, EmailAddressDifferentOnesRejected) {
- EXPECT_NE(GoogleAuthenticator::Canonicalize("who@what.com"),
- GoogleAuthenticator::Canonicalize("Us....E.r@what.com"));
-}
-
-TEST_F(GoogleAuthenticatorTest, EmailAddressIgnorePlusSuffix) {
- EXPECT_EQ(GoogleAuthenticator::Canonicalize("user+cc@what.com"),
- GoogleAuthenticator::Canonicalize("user@what.com"));
-}
-
-TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreMultiPlusSuffix) {
- EXPECT_EQ(GoogleAuthenticator::Canonicalize("user+cc+bcc@what.com"),
- GoogleAuthenticator::Canonicalize("user@what.com"));
-}
-
TEST_F(GoogleAuthenticatorTest, ReadLocalaccount) {
FilePath tmp_file_path = FakeLocalaccountFile(bytes_as_ascii_);
diff --git a/chrome/browser/chromeos/login/mock_authenticator.h b/chrome/browser/chromeos/login/mock_authenticator.h
index fa37555..31a8542a 100644
--- a/chrome/browser/chromeos/login/mock_authenticator.h
+++ b/chrome/browser/chromeos/login/mock_authenticator.h
@@ -8,6 +8,7 @@
#include <string>
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/chromeos/login/authenticator.h"
#include "chrome/browser/chromeos/login/login_utils.h"
#include "chrome/common/net/gaia/google_service_auth_error.h"
diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc
index 8e4b8fa..382f854 100644
--- a/chrome/browser/chromeos/login/screen_locker.cc
+++ b/chrome/browser/chromeos/login/screen_locker.cc
@@ -18,6 +18,7 @@
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_window.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/chromeos/cros/input_method_library.h"
#include "chrome/browser/chromeos/cros/keyboard_library.h"
#include "chrome/browser/chromeos/cros/login_library.h"
diff --git a/chrome/browser/chromeos/login/user_image_downloader.cc b/chrome/browser/chromeos/login/user_image_downloader.cc
index 3a90761..3deea71 100644
--- a/chrome/browser/chromeos/login/user_image_downloader.cc
+++ b/chrome/browser/chromeos/login/user_image_downloader.cc
@@ -12,7 +12,7 @@
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_thread.h"
-#include "chrome/browser/chromeos/login/google_authenticator.h"
+#include "chrome/browser/chromeos/login/authenticator.h"
#include "chrome/browser/chromeos/login/image_downloader.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/profile_manager.h"
@@ -158,7 +158,7 @@ bool UserImageDownloader::IsUserEntry(ListValue* email_list) const {
if (!email_dictionary->GetStringASCII("address", &email))
continue;
- if (GoogleAuthenticator::Canonicalize(email) == username_)
+ if (Authenticator::Canonicalize(email) == username_)
return true;
}
return false;
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 7722d25..27f8180 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -489,7 +489,8 @@
'browser/chromeos/login/account_creation_view.h',
'browser/chromeos/login/account_screen.cc',
'browser/chromeos/login/account_screen.h',
- 'browser/chromeos/login/authentication_notification_details.h'
+ 'browser/chromeos/login/authentication_notification_details.h',
+ 'browser/chromeos/login/authenticator.cc',
'browser/chromeos/login/authenticator.h',
'browser/chromeos/login/auth_attempt_state.cc',
'browser/chromeos/login/auth_attempt_state.h',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 2a1fce5..c063b32 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -865,6 +865,7 @@
'browser/chromeos/gview_request_interceptor_unittest.cc',
'browser/chromeos/input_method/input_method_util_unittest.cc',
'browser/chromeos/language_preferences_unittest.cc',
+ 'browser/chromeos/login/authenticator_unittest.cc',
'browser/chromeos/login/cookie_fetcher_unittest.cc',
'browser/chromeos/login/cryptohome_op_unittest.cc',
'browser/chromeos/login/google_authenticator_unittest.cc',