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..1ed171c1034578ba1df58356e6168e414ec90537 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,19 @@ 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) { |
+ DCHECK(!email.empty()); |
+ std::string gaia_id = email_to_gaia_id_map_[email]; |
+ return gaia_id.empty() ? std::string(kDefaultGaiaId) : gaia_id; |
+} |
+ |
void FakeGaia::Initialize() { |
GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); |
// Handles /MergeSession GAIA call. |
@@ -415,8 +430,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 +449,15 @@ 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) { |
bartfab (slow)
2014/10/21 14:47:47
Nit: You could simplify this by rversing the condi
Roger Tawa OOO till Jul 10th
2014/10/21 19:15:31
Done.
|
+ DCHECK(!email.empty()); |
+ http_response->AddCustomHeader("google-accounts-signin", |
bartfab (slow)
2014/10/21 14:47:47
Nit: This should be extracted into a helper method
Roger Tawa OOO till Jul 10th
2014/10/21 19:15:31
Done.
|
+ base::StringPrintf( |
+ "email=\"%s\", obfuscatedid=\"%s\", sessionindex=0", |
+ email.c_str(), GetGaiaIdOfEmail(email).c_str())); |
+ } |
} |
void FakeGaia::HandleSSO(const HttpRequest& request, |
@@ -449,6 +474,14 @@ 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()) { |
+ http_response->AddCustomHeader("google-accounts-signin", |
+ base::StringPrintf( |
+ "email=\"%s\", obfuscatedid=\"%s\", sessionindex=0", |
+ merge_session_params_.email.c_str(), |
+ GetGaiaIdOfEmail(merge_session_params_.email).c_str())); |
+ } |
} |
void FakeGaia::HandleAuthToken(const HttpRequest& request, |