summaryrefslogtreecommitdiffstats
path: root/google_apis/gaia
diff options
context:
space:
mode:
authordzhioev <dzhioev@chromium.org>2015-08-07 17:03:57 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-08 00:04:43 +0000
commitd96d99125d87e9b7403b7369e90e68999f8e5712 (patch)
tree100c64144a90674c1594fb94b760b47822a20f84 /google_apis/gaia
parentbd3d4d8a10336091ecbc30f250ce40be5ebdbd57 (diff)
downloadchromium_src-d96d99125d87e9b7403b7369e90e68999f8e5712.zip
chromium_src-d96d99125d87e9b7403b7369e90e68999f8e5712.tar.gz
chromium_src-d96d99125d87e9b7403b7369e90e68999f8e5712.tar.bz2
[cleanup] Removed ClientLogin support from GaiaAuthFetcher.
The last client using ClientLogin was removed in https://codereview.chromium.org/1278483003. BUG=470893 Review URL: https://codereview.chromium.org/1267223002 Cr-Commit-Position: refs/heads/master@{#342486}
Diffstat (limited to 'google_apis/gaia')
-rw-r--r--google_apis/gaia/gaia_auth_fetcher.cc117
-rw-r--r--google_apis/gaia/gaia_auth_fetcher.h41
-rw-r--r--google_apis/gaia/gaia_auth_fetcher_unittest.cc172
3 files changed, 8 insertions, 322 deletions
diff --git a/google_apis/gaia/gaia_auth_fetcher.cc b/google_apis/gaia/gaia_auth_fetcher.cc
index 04ebd6e..254d407 100644
--- a/google_apis/gaia/gaia_auth_fetcher.cc
+++ b/google_apis/gaia/gaia_auth_fetcher.cc
@@ -76,25 +76,6 @@ const char kGetTokenResponseRequested[] = "get_token";
} // namespace
-// TODO(chron): Add sourceless version of this formatter.
-// static
-const char GaiaAuthFetcher::kClientLoginFormat[] =
- "Email=%s&"
- "Passwd=%s&"
- "PersistentCookie=%s&"
- "accountType=%s&"
- "source=%s&"
- "service=%s";
-// static
-const char GaiaAuthFetcher::kClientLoginCaptchaFormat[] =
- "Email=%s&"
- "Passwd=%s&"
- "PersistentCookie=%s&"
- "accountType=%s&"
- "source=%s&"
- "service=%s&"
- "logintoken=%s&"
- "logincaptcha=%s";
// static
const char GaiaAuthFetcher::kIssueAuthTokenFormat[] =
"SID=%s&"
@@ -153,16 +134,6 @@ const char GaiaAuthFetcher::kCaptchaUrlParam[] = "CaptchaUrl";
const char GaiaAuthFetcher::kCaptchaTokenParam[] = "CaptchaToken";
// static
-const char GaiaAuthFetcher::kCookiePersistence[] = "true";
-// static
-// TODO(johnnyg): When hosted accounts are supported by sync,
-// we can always use "HOSTED_OR_GOOGLE"
-const char GaiaAuthFetcher::kAccountTypeHostedOrGoogle[] =
- "HOSTED_OR_GOOGLE";
-const char GaiaAuthFetcher::kAccountTypeGoogle[] =
- "GOOGLE";
-
-// static
const char GaiaAuthFetcher::kSecondFactor[] = "Info=InvalidSecondFactor";
// static
const char GaiaAuthFetcher::kWebLoginRequired[] = "Info=WebLoginRequired";
@@ -195,7 +166,6 @@ GaiaAuthFetcher::GaiaAuthFetcher(GaiaAuthConsumer* consumer,
: consumer_(consumer),
getter_(getter),
source_(source),
- client_login_gurl_(GaiaUrls::GetInstance()->client_login_url()),
issue_auth_token_gurl_(GaiaUrls::GetInstance()->issue_auth_token_url()),
oauth2_token_gurl_(GaiaUrls::GetInstance()->oauth2_token_url()),
oauth2_revoke_gurl_(GaiaUrls::GetInstance()->oauth2_revoke_url()),
@@ -266,47 +236,6 @@ void GaiaAuthFetcher::CreateAndStartGaiaFetcher(const std::string& body,
}
// static
-std::string GaiaAuthFetcher::MakeClientLoginBody(
- const std::string& username,
- const std::string& password,
- const std::string& source,
- const char* service,
- const std::string& login_token,
- const std::string& login_captcha,
- HostedAccountsSetting allow_hosted_accounts) {
- std::string encoded_username = net::EscapeUrlEncodedData(username, true);
- std::string encoded_password = net::EscapeUrlEncodedData(password, true);
- std::string encoded_login_token = net::EscapeUrlEncodedData(login_token,
- true);
- std::string encoded_login_captcha = net::EscapeUrlEncodedData(login_captcha,
- true);
-
- const char* account_type = allow_hosted_accounts == HostedAccountsAllowed ?
- kAccountTypeHostedOrGoogle :
- kAccountTypeGoogle;
-
- if (login_token.empty() || login_captcha.empty()) {
- return base::StringPrintf(kClientLoginFormat,
- encoded_username.c_str(),
- encoded_password.c_str(),
- kCookiePersistence,
- account_type,
- source.c_str(),
- service);
- }
-
- return base::StringPrintf(kClientLoginCaptchaFormat,
- encoded_username.c_str(),
- encoded_password.c_str(),
- kCookiePersistence,
- account_type,
- source.c_str(),
- service,
- encoded_login_token.c_str(),
- encoded_login_captcha.c_str());
-}
-
-// static
std::string GaiaAuthFetcher::MakeIssueAuthTokenBody(
const std::string& sid,
const std::string& lsid,
@@ -562,32 +491,6 @@ bool GaiaAuthFetcher::ParseListIdpSessionsResponse(const std::string& data,
return true;
}
-void GaiaAuthFetcher::StartClientLogin(
- const std::string& username,
- const std::string& password,
- const char* const service,
- const std::string& login_token,
- const std::string& login_captcha,
- HostedAccountsSetting allow_hosted_accounts) {
-
- DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
-
- // This class is thread agnostic, so be sure to call this only on the
- // same thread each time.
- DVLOG(1) << "Starting new ClientLogin fetch for:" << username;
-
- // Must outlive fetcher_.
- request_body_ = MakeClientLoginBody(username,
- password,
- source_,
- service,
- login_token,
- login_captcha,
- allow_hosted_accounts);
- CreateAndStartGaiaFetcher(request_body_, std::string(), client_login_gurl_,
- kLoadFlagsIgnoreCookies);
-}
-
void GaiaAuthFetcher::StartIssueAuthToken(const std::string& sid,
const std::string& lsid,
const char* const service) {
@@ -807,22 +710,6 @@ GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError(
return GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE);
}
-void GaiaAuthFetcher::OnClientLoginFetched(const std::string& data,
- const net::URLRequestStatus& status,
- int response_code) {
- if (status.is_success() && response_code == net::HTTP_OK) {
- DVLOG(1) << "ClientLogin successful!";
- std::string sid;
- std::string lsid;
- std::string token;
- ParseClientLoginResponse(data, &sid, &lsid, &token);
- consumer_->OnClientLoginSuccess(
- GaiaAuthConsumer::ClientLoginResult(sid, lsid, token, data));
- } else {
- consumer_->OnClientLoginFailure(GenerateAuthError(data, status));
- }
-}
-
void GaiaAuthFetcher::OnIssueAuthTokenFetched(
const std::string& data,
const net::URLRequestStatus& status,
@@ -1047,9 +934,7 @@ void GaiaAuthFetcher::DispatchFetchedRequest(
const net::ResponseCookies& cookies,
const net::URLRequestStatus& status,
int response_code) {
- if (url == client_login_gurl_) {
- OnClientLoginFetched(data, status, response_code);
- } else if (url == issue_auth_token_gurl_) {
+ if (url == issue_auth_token_gurl_) {
OnIssueAuthTokenFetched(data, status, response_code);
} else if (base::StartsWith(url.spec(),
client_login_to_oauth2_gurl_.spec(),
diff --git a/google_apis/gaia/gaia_auth_fetcher.h b/google_apis/gaia/gaia_auth_fetcher.h
index 4a9838f..f6e4aa8 100644
--- a/google_apis/gaia/gaia_auth_fetcher.h
+++ b/google_apis/gaia/gaia_auth_fetcher.h
@@ -35,11 +35,6 @@ class URLRequestStatus;
class GaiaAuthFetcher : public net::URLFetcherDelegate {
public:
- enum HostedAccountsSetting {
- HostedAccountsAllowed,
- HostedAccountsNotAllowed
- };
-
// Magic string indicating that, while a second factor is still
// needed to complete authentication, the user provided the right password.
static const char kSecondFactor[];
@@ -55,23 +50,6 @@ class GaiaAuthFetcher : public net::URLFetcherDelegate {
net::URLRequestContextGetter* getter);
~GaiaAuthFetcher() override;
- // Start a request to obtain the SID and LSID cookies for the the account
- // identified by |username| and |password|. If |service| is not null or
- // empty, then also obtains a service token for specified service.
- //
- // If this is a second call because of captcha challenge, then the
- // |login_token| and |login_captcha| arugment should correspond to the
- // solution of the challenge.
- //
- // Either OnClientLoginSuccess or OnClientLoginFailure will be
- // called on the consumer on the original thread.
- void StartClientLogin(const std::string& username,
- const std::string& password,
- const char* const service,
- const std::string& login_token,
- const std::string& login_captcha,
- HostedAccountsSetting allow_hosted_accounts);
-
// Start a request to obtain service token for the the account identified by
// |sid| and |lsid| and the |service|.
//
@@ -251,15 +229,6 @@ class GaiaAuthFetcher : public net::URLFetcherDelegate {
void SetPendingFetch(bool pending_fetch);
private:
- // ClientLogin body constants that don't change
- static const char kCookiePersistence[];
- static const char kAccountTypeHostedOrGoogle[];
- static const char kAccountTypeGoogle[];
-
- // The format of the POST body for ClientLogin.
- static const char kClientLoginFormat[];
- // The format of said POST body when CAPTCHA token & answer are specified.
- static const char kClientLoginCaptchaFormat[];
// The format of the POST body for IssueAuthToken.
static const char kIssueAuthTokenFormat[];
// The format of the query string to get OAuth2 auth code from auth token.
@@ -397,15 +366,6 @@ class GaiaAuthFetcher : public net::URLFetcherDelegate {
// Is this a special case Gaia error for Less Secure Apps?
static bool IsWebLoginRequiredSuccess(const std::string& alleged_error);
- // Given parameters, create a ClientLogin request body.
- static std::string MakeClientLoginBody(
- const std::string& username,
- const std::string& password,
- const std::string& source,
- const char* const service,
- const std::string& login_token,
- const std::string& login_captcha,
- HostedAccountsSetting allow_hosted_accounts);
// Supply the sid / lsid returned from ClientLogin in order to
// request a long lived auth token for a service.
static std::string MakeIssueAuthTokenBody(const std::string& sid,
@@ -450,7 +410,6 @@ class GaiaAuthFetcher : public net::URLFetcherDelegate {
GaiaAuthConsumer* const consumer_;
net::URLRequestContextGetter* const getter_;
std::string source_;
- const GURL client_login_gurl_;
const GURL issue_auth_token_gurl_;
const GURL oauth2_token_gurl_;
const GURL oauth2_revoke_gurl_;
diff --git a/google_apis/gaia/gaia_auth_fetcher_unittest.cc b/google_apis/gaia/gaia_auth_fetcher_unittest.cc
index 042decd..307a2bc 100644
--- a/google_apis/gaia/gaia_auth_fetcher_unittest.cc
+++ b/google_apis/gaia/gaia_auth_fetcher_unittest.cc
@@ -90,17 +90,16 @@ void MockFetcher::Start() {
class GaiaAuthFetcherTest : public testing::Test {
protected:
GaiaAuthFetcherTest()
- : client_login_source_(GaiaUrls::GetInstance()->client_login_url()),
- issue_auth_token_source_(
- GaiaUrls::GetInstance()->issue_auth_token_url()),
- client_login_to_oauth2_source_(
- GaiaUrls::GetInstance()->client_login_to_oauth2_url()),
+ : issue_auth_token_source_(GaiaUrls::GetInstance()
+ ->issue_auth_token_url()),
+ client_login_to_oauth2_source_(GaiaUrls::GetInstance()
+ ->client_login_to_oauth2_url()),
oauth2_token_source_(GaiaUrls::GetInstance()->oauth2_token_url()),
token_auth_source_(GaiaUrls::GetInstance()->token_auth_url()),
merge_session_source_(GaiaUrls::GetInstance()->merge_session_url()),
- uberauth_token_source_(
- GaiaUrls::GetInstance()->oauth1_login_url().Resolve(
- "?source=&issueuberauth=1")),
+ uberauth_token_source_(GaiaUrls::GetInstance()
+ ->oauth1_login_url()
+ .Resolve("?source=&issueuberauth=1")),
oauth_login_gurl_(GaiaUrls::GetInstance()->oauth1_login_url()) {}
void RunParsingTest(const std::string& data,
@@ -142,7 +141,6 @@ class GaiaAuthFetcherTest : public testing::Test {
}
net::ResponseCookies cookies_;
- GURL client_login_source_;
GURL issue_auth_token_source_;
GURL client_login_to_oauth2_source_;
GURL oauth2_token_source_;
@@ -223,25 +221,6 @@ TEST_F(GaiaAuthFetcherTest, MAYBE_ErrorComparator) {
EXPECT_TRUE(expected_error == matching_error);
}
-TEST_F(GaiaAuthFetcherTest, LoginNetFailure) {
- int error_no = net::ERR_CONNECTION_RESET;
- net::URLRequestStatus status(net::URLRequestStatus::FAILED, error_no);
-
- GoogleServiceAuthError expected_error =
- GoogleServiceAuthError::FromConnectionError(error_no);
-
- MockGaiaConsumer consumer;
- EXPECT_CALL(consumer, OnClientLoginFailure(expected_error))
- .Times(1);
-
- GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
-
- MockFetcher mock_fetcher(
- client_login_source_, status, 0, net::ResponseCookies(), std::string(),
- net::URLFetcher::GET, &auth);
- auth.OnURLFetchComplete(&mock_fetcher);
-}
-
TEST_F(GaiaAuthFetcherTest, TokenNetFailure) {
int error_no = net::ERR_CONNECTION_RESET;
net::URLRequestStatus status(net::URLRequestStatus::FAILED, error_no);
@@ -262,25 +241,6 @@ TEST_F(GaiaAuthFetcherTest, TokenNetFailure) {
}
-TEST_F(GaiaAuthFetcherTest, LoginDenied) {
- std::string data("Error=BadAuthentication");
- net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
-
- GoogleServiceAuthError expected_error(
- GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
-
- MockGaiaConsumer consumer;
- EXPECT_CALL(consumer, OnClientLoginFailure(expected_error))
- .Times(1);
-
- GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
-
- MockFetcher mock_fetcher(
- client_login_source_, status, net::HTTP_FORBIDDEN, cookies_, data,
- net::URLFetcher::GET, &auth);
- auth.OnURLFetchComplete(&mock_fetcher);
-}
-
TEST_F(GaiaAuthFetcherTest, ParseRequest) {
RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth\n", "sid", "lsid", "auth");
RunParsingTest("LSID=lsid\nSID=sid\nAuth=auth\n", "sid", "lsid", "auth");
@@ -306,28 +266,6 @@ TEST_F(GaiaAuthFetcherTest, ParseErrorRequest) {
"CaptchaUrl=C\n", "E", "U", "C", "T");
}
-
-TEST_F(GaiaAuthFetcherTest, OnlineLogin) {
- std::string data("SID=sid\nLSID=lsid\nAuth=auth\n");
-
- GaiaAuthConsumer::ClientLoginResult result;
- result.lsid = "lsid";
- result.sid = "sid";
- result.token = "auth";
- result.data = data;
-
- MockGaiaConsumer consumer;
- EXPECT_CALL(consumer, OnClientLoginSuccess(result))
- .Times(1);
-
- GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
- net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
- MockFetcher mock_fetcher(
- client_login_source_, status, net::HTTP_OK, cookies_, data,
- net::URLFetcher::GET, &auth);
- auth.OnURLFetchComplete(&mock_fetcher);
-}
-
TEST_F(GaiaAuthFetcherTest, WorkingIssueAuthToken) {
MockGaiaConsumer consumer;
EXPECT_CALL(consumer, OnIssueAuthTokenSuccess(_, "token"))
@@ -353,44 +291,6 @@ TEST_F(GaiaAuthFetcherTest, CheckNormalErrorCode) {
EXPECT_FALSE(GaiaAuthFetcher::IsSecondFactorSuccess(response));
}
-TEST_F(GaiaAuthFetcherTest, TwoFactorLogin) {
- std::string response = base::StringPrintf("Error=BadAuthentication\n%s\n",
- GaiaAuthFetcher::kSecondFactor);
-
- GoogleServiceAuthError error =
- GoogleServiceAuthError(GoogleServiceAuthError::TWO_FACTOR);
-
- MockGaiaConsumer consumer;
- EXPECT_CALL(consumer, OnClientLoginFailure(error))
- .Times(1);
-
- GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
- net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
- MockFetcher mock_fetcher(
- client_login_source_, status, net::HTTP_FORBIDDEN, cookies_, response,
- net::URLFetcher::GET, &auth);
- auth.OnURLFetchComplete(&mock_fetcher);
-}
-
-TEST_F(GaiaAuthFetcherTest, WebLoginRequired) {
- std::string response = base::StringPrintf("Error=BadAuthentication\n%s\n",
- GaiaAuthFetcher::kWebLoginRequired);
-
- GoogleServiceAuthError error =
- GoogleServiceAuthError(GoogleServiceAuthError::WEB_LOGIN_REQUIRED);
-
- MockGaiaConsumer consumer;
- EXPECT_CALL(consumer, OnClientLoginFailure(error))
- .Times(1);
-
- GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
- net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
- MockFetcher mock_fetcher(
- client_login_source_, status, net::HTTP_FORBIDDEN, cookies_, response,
- net::URLFetcher::GET, &auth);
- auth.OnURLFetchComplete(&mock_fetcher);
-}
-
TEST_F(GaiaAuthFetcherTest, CaptchaParse) {
net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
std::string data = "Url=http://www.google.com/login/captcha\n"
@@ -450,64 +350,6 @@ TEST_F(GaiaAuthFetcherTest, ServiceUnavailableError) {
EXPECT_EQ(error.state(), GoogleServiceAuthError::SERVICE_UNAVAILABLE);
}
-TEST_F(GaiaAuthFetcherTest, FullLogin) {
- MockGaiaConsumer consumer;
- EXPECT_CALL(consumer, OnClientLoginSuccess(_))
- .Times(1);
-
- MockURLFetcherFactory<MockFetcher> factory;
-
- GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
- auth.StartClientLogin("username",
- "password",
- "service",
- std::string(),
- std::string(),
- GaiaAuthFetcher::HostedAccountsAllowed);
-}
-
-TEST_F(GaiaAuthFetcherTest, FullLoginFailure) {
- MockGaiaConsumer consumer;
- EXPECT_CALL(consumer, OnClientLoginFailure(_))
- .Times(1);
-
- MockURLFetcherFactory<MockFetcher> factory;
- factory.set_success(false);
-
- GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
- auth.StartClientLogin("username",
- "password",
- "service",
- std::string(),
- std::string(),
- GaiaAuthFetcher::HostedAccountsAllowed);
-}
-
-TEST_F(GaiaAuthFetcherTest, ClientFetchPending) {
- MockGaiaConsumer consumer;
- EXPECT_CALL(consumer, OnClientLoginSuccess(_))
- .Times(1);
-
- net::TestURLFetcherFactory factory;
-
- GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
- auth.StartClientLogin("username",
- "password",
- "service",
- std::string(),
- std::string(),
- GaiaAuthFetcher::HostedAccountsAllowed);
-
- EXPECT_TRUE(auth.HasPendingFetch());
- MockFetcher mock_fetcher(
- client_login_source_,
- net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
- net::HTTP_OK, cookies_, "SID=sid\nLSID=lsid\nAuth=auth\n",
- net::URLFetcher::GET, &auth);
- auth.OnURLFetchComplete(&mock_fetcher);
- EXPECT_FALSE(auth.HasPendingFetch());
-}
-
TEST_F(GaiaAuthFetcherTest, FullTokenSuccess) {
MockGaiaConsumer consumer;
EXPECT_CALL(consumer, OnIssueAuthTokenSuccess("service", "token"))