Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "google_apis/gaia/fake_gaia.h" | 5 #include "google_apis/gaia/fake_gaia.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie"; | 49 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie"; |
| 50 const char kTestOAuthLoginSID[] = "fake-oauth-SID-cookie"; | 50 const char kTestOAuthLoginSID[] = "fake-oauth-SID-cookie"; |
| 51 const char kTestOAuthLoginLSID[] = "fake-oauth-LSID-cookie"; | 51 const char kTestOAuthLoginLSID[] = "fake-oauth-LSID-cookie"; |
| 52 const char kTestOAuthLoginAuthCode[] = "fake-oauth-auth-code"; | 52 const char kTestOAuthLoginAuthCode[] = "fake-oauth-auth-code"; |
| 53 | 53 |
| 54 const char kDefaultGaiaId[] ="12345"; | 54 const char kDefaultGaiaId[] ="12345"; |
| 55 | 55 |
| 56 const base::FilePath::CharType kServiceLogin[] = | 56 const base::FilePath::CharType kServiceLogin[] = |
| 57 FILE_PATH_LITERAL("google_apis/test/service_login.html"); | 57 FILE_PATH_LITERAL("google_apis/test/service_login.html"); |
| 58 | 58 |
| 59 const base::FilePath::CharType kEmbeddedSetupChromeos[] = | |
| 60 FILE_PATH_LITERAL("google_apis/test/embedded_setup_chromeos.html"); | |
| 61 | |
| 59 // OAuth2 Authentication header value prefix. | 62 // OAuth2 Authentication header value prefix. |
| 60 const char kAuthHeaderBearer[] = "Bearer "; | 63 const char kAuthHeaderBearer[] = "Bearer "; |
| 61 const char kAuthHeaderOAuth[] = "OAuth "; | 64 const char kAuthHeaderOAuth[] = "OAuth "; |
| 62 | 65 |
| 63 const char kListAccountsResponseFormat[] = | 66 const char kListAccountsResponseFormat[] = |
| 64 "[\"gaia.l.a.r\",[[\"gaia.l.a\",1,\"\",\"%s\",\"\",1,1,0]]]"; | 67 "[\"gaia.l.a.r\",[[\"gaia.l.a\",1,\"\",\"%s\",\"\",1,1,0]]]"; |
| 65 | 68 |
| 66 typedef std::map<std::string, std::string> CookieMap; | 69 typedef std::map<std::string, std::string> CookieMap; |
| 67 | 70 |
| 68 // Parses cookie name-value map our of |request|. | 71 // Parses cookie name-value map our of |request|. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 | 135 |
| 133 FakeGaia::MergeSessionParams::~MergeSessionParams() { | 136 FakeGaia::MergeSessionParams::~MergeSessionParams() { |
| 134 } | 137 } |
| 135 | 138 |
| 136 FakeGaia::FakeGaia() : issue_oauth_code_cookie_(false) { | 139 FakeGaia::FakeGaia() : issue_oauth_code_cookie_(false) { |
| 137 base::FilePath source_root_dir; | 140 base::FilePath source_root_dir; |
| 138 PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir); | 141 PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir); |
| 139 CHECK(base::ReadFileToString( | 142 CHECK(base::ReadFileToString( |
| 140 source_root_dir.Append(base::FilePath(kServiceLogin)), | 143 source_root_dir.Append(base::FilePath(kServiceLogin)), |
| 141 &service_login_response_)); | 144 &service_login_response_)); |
| 145 CHECK(base::ReadFileToString( | |
| 146 source_root_dir.Append(base::FilePath(kEmbeddedSetupChromeos)), | |
| 147 &embedded_setup_chromeos_response_)); | |
| 142 } | 148 } |
| 143 | 149 |
| 144 FakeGaia::~FakeGaia() {} | 150 FakeGaia::~FakeGaia() {} |
| 145 | 151 |
| 146 void FakeGaia::SetFakeMergeSessionParams( | 152 void FakeGaia::SetFakeMergeSessionParams( |
| 147 const std::string& email, | 153 const std::string& email, |
| 148 const std::string& auth_sid_cookie, | 154 const std::string& auth_sid_cookie, |
| 149 const std::string& auth_lsid_cookie) { | 155 const std::string& auth_lsid_cookie) { |
| 150 FakeGaia::MergeSessionParams params; | 156 FakeGaia::MergeSessionParams params; |
| 151 params.auth_sid_cookie = auth_sid_cookie; | 157 params.auth_sid_cookie = auth_sid_cookie; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 | 212 |
| 207 // Handles /o/oauth2/programmatic_auth GAIA call. | 213 // Handles /o/oauth2/programmatic_auth GAIA call. |
| 208 REGISTER_RESPONSE_HANDLER( | 214 REGISTER_RESPONSE_HANDLER( |
| 209 gaia_urls->client_login_to_oauth2_url(), HandleProgramaticAuth); | 215 gaia_urls->client_login_to_oauth2_url(), HandleProgramaticAuth); |
| 210 | 216 |
| 211 // Handles /ServiceLogin GAIA call. | 217 // Handles /ServiceLogin GAIA call. |
| 212 REGISTER_RESPONSE_HANDLER( | 218 REGISTER_RESPONSE_HANDLER( |
| 213 gaia_urls->service_login_url(), HandleServiceLogin); | 219 gaia_urls->service_login_url(), HandleServiceLogin); |
| 214 | 220 |
| 215 // Handles /embedded/setup/chromeos GAIA call. | 221 // Handles /embedded/setup/chromeos GAIA call. |
| 216 // Same handler as for /ServiceLogin is used for now. | 222 REGISTER_RESPONSE_HANDLER(gaia_urls->embedded_setup_chromeos_url(), |
| 217 REGISTER_RESPONSE_HANDLER( | 223 HandleEmbeddedSetupChromeos); |
| 218 gaia_urls->embedded_setup_chromeos_url(), HandleServiceLogin); | |
| 219 | 224 |
| 220 // Handles /OAuthLogin GAIA call. | 225 // Handles /OAuthLogin GAIA call. |
| 221 REGISTER_RESPONSE_HANDLER( | 226 REGISTER_RESPONSE_HANDLER( |
| 222 gaia_urls->oauth1_login_url(), HandleOAuthLogin); | 227 gaia_urls->oauth1_login_url(), HandleOAuthLogin); |
| 223 | 228 |
| 224 // Handles /ServiceLoginAuth GAIA call. | 229 // Handles /ServiceLoginAuth GAIA call. |
| 225 REGISTER_RESPONSE_HANDLER( | 230 REGISTER_RESPONSE_HANDLER( |
| 226 gaia_urls->service_login_auth_url(), HandleServiceLoginAuth); | 231 gaia_urls->service_login_auth_url(), HandleServiceLoginAuth); |
| 227 | 232 |
| 233 // Handles /_/embedded/signin/challenge for /embedded/setup/chromeos | |
|
Nikita (slow)
2015/04/07 12:37:48
embedded/lookup/accountlookup
Dmitry Polukhin
2015/04/07 13:24:40
Done.
| |
| 234 // authentication request. | |
| 235 REGISTER_PATH_RESPONSE_HANDLER("/_/embedded/lookup/accountlookup", | |
| 236 HandleEmbeddedLookupAccountLookup); | |
| 237 | |
| 238 // Handles /_/embedded/signin/challenge for /embedded/setup/chromeos | |
| 239 // authentication request. | |
| 240 REGISTER_PATH_RESPONSE_HANDLER("/_/embedded/signin/challenge", | |
| 241 HandleEmbeddedSigninChallenge); | |
| 242 | |
| 228 // Handles /SSO GAIA call (not GAIA, made up for SAML tests). | 243 // Handles /SSO GAIA call (not GAIA, made up for SAML tests). |
| 229 REGISTER_PATH_RESPONSE_HANDLER("/SSO", HandleSSO); | 244 REGISTER_PATH_RESPONSE_HANDLER("/SSO", HandleSSO); |
| 230 | 245 |
| 231 // Handles /o/oauth2/token GAIA call. | 246 // Handles /o/oauth2/token GAIA call. |
| 232 REGISTER_RESPONSE_HANDLER( | 247 REGISTER_RESPONSE_HANDLER( |
| 233 gaia_urls->oauth2_token_url(), HandleAuthToken); | 248 gaia_urls->oauth2_token_url(), HandleAuthToken); |
| 234 | 249 |
| 235 // Handles /oauth2/v2/tokeninfo GAIA call. | 250 // Handles /oauth2/v2/tokeninfo GAIA call. |
| 236 REGISTER_RESPONSE_HANDLER( | 251 REGISTER_RESPONSE_HANDLER( |
| 237 gaia_urls->oauth2_token_info_url(), HandleTokenInfo); | 252 gaia_urls->oauth2_token_info_url(), HandleTokenInfo); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 return NULL; | 432 return NULL; |
| 418 } | 433 } |
| 419 | 434 |
| 420 void FakeGaia::HandleServiceLogin(const HttpRequest& request, | 435 void FakeGaia::HandleServiceLogin(const HttpRequest& request, |
| 421 BasicHttpResponse* http_response) { | 436 BasicHttpResponse* http_response) { |
| 422 http_response->set_code(net::HTTP_OK); | 437 http_response->set_code(net::HTTP_OK); |
| 423 http_response->set_content(service_login_response_); | 438 http_response->set_content(service_login_response_); |
| 424 http_response->set_content_type("text/html"); | 439 http_response->set_content_type("text/html"); |
| 425 } | 440 } |
| 426 | 441 |
| 442 void FakeGaia::HandleEmbeddedSetupChromeos(const HttpRequest& request, | |
| 443 BasicHttpResponse* http_response) { | |
| 444 http_response->set_code(net::HTTP_OK); | |
| 445 http_response->set_content(embedded_setup_chromeos_response_); | |
| 446 http_response->set_content_type("text/html"); | |
| 447 } | |
| 448 | |
| 427 void FakeGaia::HandleOAuthLogin(const HttpRequest& request, | 449 void FakeGaia::HandleOAuthLogin(const HttpRequest& request, |
| 428 BasicHttpResponse* http_response) { | 450 BasicHttpResponse* http_response) { |
| 429 http_response->set_code(net::HTTP_UNAUTHORIZED); | 451 http_response->set_code(net::HTTP_UNAUTHORIZED); |
| 430 if (merge_session_params_.gaia_uber_token.empty()) { | 452 if (merge_session_params_.gaia_uber_token.empty()) { |
| 431 http_response->set_code(net::HTTP_FORBIDDEN); | 453 http_response->set_code(net::HTTP_FORBIDDEN); |
| 432 return; | 454 return; |
| 433 } | 455 } |
| 434 | 456 |
| 435 std::string access_token; | 457 std::string access_token; |
| 436 if (!GetAccessToken(request, kAuthHeaderBearer, &access_token) && | 458 if (!GetAccessToken(request, kAuthHeaderBearer, &access_token) && |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 | 516 |
| 495 // SAML sign-ins complete in HandleSSO(). | 517 // SAML sign-ins complete in HandleSSO(). |
| 496 if (is_saml) | 518 if (is_saml) |
| 497 return; | 519 return; |
| 498 | 520 |
| 499 AddGoogleAccountsSigninHeader(http_response, email); | 521 AddGoogleAccountsSigninHeader(http_response, email); |
| 500 if (issue_oauth_code_cookie_) | 522 if (issue_oauth_code_cookie_) |
| 501 SetOAuthCodeCookie(http_response); | 523 SetOAuthCodeCookie(http_response); |
| 502 } | 524 } |
| 503 | 525 |
| 526 void FakeGaia::HandleEmbeddedLookupAccountLookup( | |
| 527 const net::test_server::HttpRequest& request, | |
| 528 net::test_server::BasicHttpResponse* http_response) { | |
| 529 std::string email; | |
| 530 const bool is_saml = | |
| 531 GetQueryParameter(request.content, "identifier", &email) && | |
| 532 saml_account_idp_map_.find(email) != saml_account_idp_map_.end(); | |
| 533 | |
| 534 if (!is_saml) | |
| 535 return; | |
| 536 | |
| 537 GURL url(saml_account_idp_map_[email]); | |
| 538 url = net::AppendQueryParameter(url, "SAMLRequest", "fake_request"); | |
| 539 url = net::AppendQueryParameter( | |
| 540 url, "RelayState", | |
| 541 "chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik/success.html"); | |
| 542 std::string redirect_url = url.spec(); | |
| 543 http_response->AddCustomHeader("Google-Accounts-SAML", "Start"); | |
| 544 | |
| 545 http_response->AddCustomHeader("continue", redirect_url); | |
| 546 } | |
| 547 | |
| 548 void FakeGaia::HandleEmbeddedSigninChallenge(const HttpRequest& request, | |
| 549 BasicHttpResponse* http_response) { | |
| 550 std::string email; | |
| 551 GetQueryParameter(request.content, "identifier", &email); | |
| 552 | |
| 553 if (!merge_session_params_.auth_sid_cookie.empty() && | |
| 554 !merge_session_params_.auth_lsid_cookie.empty()) { | |
| 555 SetCookies(http_response, merge_session_params_.auth_sid_cookie, | |
| 556 merge_session_params_.auth_lsid_cookie); | |
| 557 } | |
| 558 | |
| 559 AddGoogleAccountsSigninHeader(http_response, email); | |
| 560 | |
| 561 if (issue_oauth_code_cookie_) | |
| 562 SetOAuthCodeCookie(http_response); | |
| 563 } | |
| 564 | |
| 504 void FakeGaia::HandleSSO(const HttpRequest& request, | 565 void FakeGaia::HandleSSO(const HttpRequest& request, |
| 505 BasicHttpResponse* http_response) { | 566 BasicHttpResponse* http_response) { |
| 506 if (!merge_session_params_.auth_sid_cookie.empty() && | 567 if (!merge_session_params_.auth_sid_cookie.empty() && |
| 507 !merge_session_params_.auth_lsid_cookie.empty()) { | 568 !merge_session_params_.auth_lsid_cookie.empty()) { |
| 508 SetCookies(http_response, | 569 SetCookies(http_response, |
| 509 merge_session_params_.auth_sid_cookie, | 570 merge_session_params_.auth_sid_cookie, |
| 510 merge_session_params_.auth_lsid_cookie); | 571 merge_session_params_.auth_lsid_cookie); |
| 511 } | 572 } |
| 512 std::string relay_state; | 573 std::string relay_state; |
| 513 GetQueryParameter(request.content, "RelayState", &relay_state); | 574 GetQueryParameter(request.content, "RelayState", &relay_state); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 if (token_info) { | 712 if (token_info) { |
| 652 base::DictionaryValue response_dict; | 713 base::DictionaryValue response_dict; |
| 653 response_dict.SetString("id", GetGaiaIdOfEmail(token_info->email)); | 714 response_dict.SetString("id", GetGaiaIdOfEmail(token_info->email)); |
| 654 response_dict.SetString("email", token_info->email); | 715 response_dict.SetString("email", token_info->email); |
| 655 response_dict.SetString("verified_email", token_info->email); | 716 response_dict.SetString("verified_email", token_info->email); |
| 656 FormatJSONResponse(response_dict, http_response); | 717 FormatJSONResponse(response_dict, http_response); |
| 657 } else { | 718 } else { |
| 658 http_response->set_code(net::HTTP_BAD_REQUEST); | 719 http_response->set_code(net::HTTP_BAD_REQUEST); |
| 659 } | 720 } |
| 660 } | 721 } |
| OLD | NEW |