Chromium Code Reviews| Index: google_apis/gaia/fake_gaia.cc |
| diff --git a/google_apis/gaia/fake_gaia.cc b/google_apis/gaia/fake_gaia.cc |
| index 9c4836f5e2b46f694694805281b1d3522e0d132d..b1a3942c1c505efa1484134650d8793abf03841b 100644 |
| --- a/google_apis/gaia/fake_gaia.cc |
| +++ b/google_apis/gaia/fake_gaia.cc |
| @@ -51,6 +51,8 @@ const char kTestOAuthLoginSID[] = "fake-oauth-SID-cookie"; |
| const char kTestOAuthLoginLSID[] = "fake-oauth-LSID-cookie"; |
| const char kTestOAuthLoginAuthCode[] = "fake-oauth-auth-code"; |
| +const char kDefaultGaiaId[] ="12345"; |
| + |
| const base::FilePath::CharType kServiceLogin[] = |
| FILE_PATH_LITERAL("google_apis/test/service_login.html"); |
| @@ -163,6 +165,30 @@ void FakeGaia::SetMergeSessionParams( |
| merge_session_params_ = params; |
| } |
| +void FakeGaia::MapEmailToGaiaId(const std::string& email, |
| + const std::string& gaia_id) { |
| + DCHECK(!email.empty()); |
| + DCHECK(!gaia_id.empty()); |
| + email_to_gaia_id_map_[email] = gaia_id; |
| +} |
| + |
| +std::string FakeGaia::GetGaiaIdOfEmail(const std::string& email) const { |
| + DCHECK(!email.empty()); |
| + auto it = email_to_gaia_id_map_.find(email); |
| + return it == email_to_gaia_id_map_.end() ? std::string(kDefaultGaiaId) : |
| + it->second; |
| +} |
| + |
| +void FakeGaia::AddGoogleAccountsSigninHeader( |
| + net::test_server::BasicHttpResponse* http_response, |
| + const std::string& email) const { |
| + DCHECK(!email.empty()); |
| + http_response->AddCustomHeader("google-accounts-signin", |
| + base::StringPrintf( |
| + "email=\"%s\", obfuscatedid=\"%s\", sessionindex=0", |
| + email.c_str(), GetGaiaIdOfEmail(email).c_str())); |
| +} |
| + |
| void FakeGaia::Initialize() { |
| GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); |
| // Handles /MergeSession GAIA call. |
| @@ -415,8 +441,11 @@ void FakeGaia::HandleServiceLoginAuth(const HttpRequest& request, |
| std::string redirect_url = continue_url; |
| std::string email; |
| - if (GetQueryParameter(request.content, "Email", &email) && |
| - saml_account_idp_map_.find(email) != saml_account_idp_map_.end()) { |
| + const bool is_saml = |
| + GetQueryParameter(request.content, "Email", &email) && |
| + saml_account_idp_map_.find(email) != saml_account_idp_map_.end(); |
| + |
| + if (is_saml) { |
| GURL url(saml_account_idp_map_[email]); |
| url = net::AppendQueryParameter(url, "SAMLRequest", "fake_request"); |
| url = net::AppendQueryParameter(url, "RelayState", continue_url); |
| @@ -431,8 +460,12 @@ void FakeGaia::HandleServiceLoginAuth(const HttpRequest& request, |
| http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); |
| http_response->AddCustomHeader("Location", redirect_url); |
| - http_response->AddCustomHeader("google-accounts-signin", |
| - base::StringPrintf("email=\"%s\", sessionindex=0", email.c_str())); |
| + |
| + // SAML sign-ins complete in HandleSSO(). |
| + if (is_saml) |
| + return; |
|
bartfab (slow)
2014/10/22 08:31:32
Nit: Now the early return no longer simplifies any
|
| + |
| + AddGoogleAccountsSigninHeader(http_response, email); |
| } |
| void FakeGaia::HandleSSO(const HttpRequest& request, |
| @@ -449,6 +482,9 @@ void FakeGaia::HandleSSO(const HttpRequest& request, |
| http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); |
| http_response->AddCustomHeader("Location", redirect_url); |
| http_response->AddCustomHeader("Google-Accounts-SAML", "End"); |
| + |
| + if (!merge_session_params_.email.empty()) |
| + AddGoogleAccountsSigninHeader(http_response, merge_session_params_.email); |
| } |
| void FakeGaia::HandleAuthToken(const HttpRequest& request, |
| @@ -580,3 +616,4 @@ void FakeGaia::HandleGetUserInfo(const HttpRequest& request, |
| merge_session_params_.email.c_str())); |
| http_response->set_code(net::HTTP_OK); |
| } |
| + |