0

Add helper function to test that a given URL is a valid Gaia sign in URL.

BUG=137118
TEST=See unit tests, not called in any code yet


Review URL: https://chromiumcodereview.appspot.com/11091048

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161282 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
rogerta@chromium.org
2012-10-11 03:20:27 +00:00
parent 770d3f4a9e
commit 80b396182d
3 changed files with 31 additions and 0 deletions

@ -9,6 +9,8 @@
#include "base/logging.h"
#include "base/string_split.h"
#include "base/string_util.h"
#include "google_apis/gaia/gaia_urls.h"
#include "googleurl/src/gurl.h"
namespace gaia {
@ -58,4 +60,13 @@ std::string ExtractDomainName(const std::string& email_address) {
return std::string();
}
bool IsGaiaSignonRealm(const GURL& url) {
if (!url.SchemeIsSecure())
return false;
// Also check "https://www.google.com" to support old style dasher logins.
return url == GURL(GaiaUrls::GetInstance()->gaia_origin_url()) ||
url == GURL("https://www.google.com/");
}
} // namespace gaia

@ -7,6 +7,8 @@
#include <string>
class GURL;
namespace gaia {
// Perform basic canonicalization of |email_address|, taking into account that
@ -26,6 +28,8 @@ 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);
bool IsGaiaSignonRealm(const GURL& url);
} // namespace gaia
#endif // GOOGLE_APIS_GAIA_GAIA_AUTH_UTIL_H_

@ -4,6 +4,7 @@
#include "google_apis/gaia/gaia_auth_util.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace gaia {
@ -84,4 +85,19 @@ TEST(GaiaAuthUtilTest, SanitizeExistingDomain) {
EXPECT_EQ(existing, SanitizeEmail(existing));
}
TEST(GaiaAuthUtilTest, IsGaiaSignonRealm) {
// Only https versions of Gaia URLs should be considered valid.
EXPECT_TRUE(IsGaiaSignonRealm(GURL("https://accounts.google.com/")));
EXPECT_TRUE(IsGaiaSignonRealm(GURL("https://www.google.com/")));
EXPECT_FALSE(IsGaiaSignonRealm(GURL("http://accounts.google.com/")));
EXPECT_FALSE(IsGaiaSignonRealm(GURL("http://www.google.com/")));
// Other Google URLs are not valid.
EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://google.com/")));
EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://mail.google.com/")));
// Other https URLs are not valid.
EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.example.com/")));
}
} // namespace gaia