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");
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.
// Handles /ListAccounts GAIA call.
REGISTER_RESPONSE_HANDLER(
- gaia_urls->list_accounts_url(), HandleListAccounts);
+ gaia_urls->ListAccountsURLWithSource(std::string()), HandleListAccounts);
// Handles /GetUserInfo GAIA call.
REGISTER_RESPONSE_HANDLER(
return scoped_ptr<HttpResponse>(); // Request not understood.
}
- return http_response.PassAs<HttpResponse>();
+ return http_response.Pass();
}
void FakeGaia::IssueOAuthToken(const std::string& auth_token,
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);
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;
+
+ AddGoogleAccountsSigninHeader(http_response, email);
}
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,
merge_session_params_.email.c_str()));
http_response->set_code(net::HTTP_OK);
}
+