Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(428)

Side by Side Diff: google_apis/gaia/fake_gaia.cc

Issue 418043002: Add test for showing confirmation dialog for unsecure signin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: trybot errors fixed Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 23 matching lines...) Expand all
34 url.path(), base::Bind(&FakeGaia::method, base::Unretained(this)))) 34 url.path(), base::Bind(&FakeGaia::method, base::Unretained(this))))
35 35
36 #define REGISTER_PATH_RESPONSE_HANDLER(path, method) \ 36 #define REGISTER_PATH_RESPONSE_HANDLER(path, method) \
37 request_handlers_.insert(std::make_pair( \ 37 request_handlers_.insert(std::make_pair( \
38 path, base::Bind(&FakeGaia::method, base::Unretained(this)))) 38 path, base::Bind(&FakeGaia::method, base::Unretained(this))))
39 39
40 using namespace net::test_server; 40 using namespace net::test_server;
41 41
42 namespace { 42 namespace {
43 43
44 const char kTestAuthCode[] = "fake-auth-code";
45 const char kTestGaiaUberToken[] = "fake-uber-token";
46 const char kTestAuthLoginAccessToken[] = "fake-access-token";
47 const char kTestRefreshToken[] = "fake-refresh-token";
48 const char kTestSessionSIDCookie[] = "fake-session-SID-cookie";
49 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie";
50 const char kTestOAuthLoginSID[] = "fake-oauth-SID-cookie";
51 const char kTestOAuthLoginLSID[] = "fake-oauth-LSID-cookie";
52 const char kTestOAuthLoginAuthCode[] = "fake-oauth-auth-code";
53
44 const base::FilePath::CharType kServiceLogin[] = 54 const base::FilePath::CharType kServiceLogin[] =
45 FILE_PATH_LITERAL("google_apis/test/service_login.html"); 55 FILE_PATH_LITERAL("google_apis/test/service_login.html");
46 56
47 // OAuth2 Authentication header value prefix. 57 // OAuth2 Authentication header value prefix.
48 const char kAuthHeaderBearer[] = "Bearer "; 58 const char kAuthHeaderBearer[] = "Bearer ";
49 const char kAuthHeaderOAuth[] = "OAuth ";
50 59
51 const char kListAccountsResponseFormat[] = 60 const char kListAccountsResponseFormat[] =
52 "[\"gaia.l.a.r\",[[\"gaia.l.a\",1,\"\",\"%s\",\"\",1,1,0]]]"; 61 "[\"gaia.l.a.r\",[[\"gaia.l.a\",1,\"\",\"%s\",\"\",1,1,0]]]";
53 62
54 typedef std::map<std::string, std::string> CookieMap; 63 typedef std::map<std::string, std::string> CookieMap;
55 64
56 // Parses cookie name-value map our of |request|. 65 // Parses cookie name-value map our of |request|.
57 CookieMap GetRequestCookies(const HttpRequest& request) { 66 CookieMap GetRequestCookies(const HttpRequest& request) {
58 CookieMap result; 67 CookieMap result;
59 std::map<std::string, std::string>::const_iterator iter = 68 std::map<std::string, std::string>::const_iterator iter =
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 FakeGaia::FakeGaia() { 133 FakeGaia::FakeGaia() {
125 base::FilePath source_root_dir; 134 base::FilePath source_root_dir;
126 PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir); 135 PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir);
127 CHECK(base::ReadFileToString( 136 CHECK(base::ReadFileToString(
128 source_root_dir.Append(base::FilePath(kServiceLogin)), 137 source_root_dir.Append(base::FilePath(kServiceLogin)),
129 &service_login_response_)); 138 &service_login_response_));
130 } 139 }
131 140
132 FakeGaia::~FakeGaia() {} 141 FakeGaia::~FakeGaia() {}
133 142
143 void FakeGaia::SetFakeMergeSessionParams(
144 const std::string& email,
145 const std::string& auth_sid_cookie,
146 const std::string& auth_lsid_cookie) {
147 FakeGaia::MergeSessionParams params;
148 params.auth_sid_cookie = auth_sid_cookie;
149 params.auth_lsid_cookie = auth_lsid_cookie;
150 params.auth_code = kTestAuthCode;
151 params.refresh_token = kTestRefreshToken;
152 params.access_token = kTestAuthLoginAccessToken;
153 params.gaia_uber_token = kTestGaiaUberToken;
154 params.session_sid_cookie = kTestSessionSIDCookie;
155 params.session_lsid_cookie = kTestSessionLSIDCookie;
156 params.email = email;
157 SetMergeSessionParams(params);
158 }
159
134 void FakeGaia::SetMergeSessionParams( 160 void FakeGaia::SetMergeSessionParams(
135 const MergeSessionParams& params) { 161 const MergeSessionParams& params) {
136 merge_session_params_ = params; 162 merge_session_params_ = params;
137 } 163 }
138 164
139 void FakeGaia::Initialize() { 165 void FakeGaia::Initialize() {
140 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 166 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
141 // Handles /MergeSession GAIA call. 167 // Handles /MergeSession GAIA call.
142 REGISTER_RESPONSE_HANDLER( 168 REGISTER_RESPONSE_HANDLER(
143 gaia_urls->merge_session_url(), HandleMergeSession); 169 gaia_urls->merge_session_url(), HandleMergeSession);
(...skipping 25 matching lines...) Expand all
169 REGISTER_RESPONSE_HANDLER( 195 REGISTER_RESPONSE_HANDLER(
170 gaia_urls->oauth2_token_info_url(), HandleTokenInfo); 196 gaia_urls->oauth2_token_info_url(), HandleTokenInfo);
171 197
172 // Handles /oauth2/v2/IssueToken GAIA call. 198 // Handles /oauth2/v2/IssueToken GAIA call.
173 REGISTER_RESPONSE_HANDLER( 199 REGISTER_RESPONSE_HANDLER(
174 gaia_urls->oauth2_issue_token_url(), HandleIssueToken); 200 gaia_urls->oauth2_issue_token_url(), HandleIssueToken);
175 201
176 // Handles /ListAccounts GAIA call. 202 // Handles /ListAccounts GAIA call.
177 REGISTER_RESPONSE_HANDLER( 203 REGISTER_RESPONSE_HANDLER(
178 gaia_urls->list_accounts_url(), HandleListAccounts); 204 gaia_urls->list_accounts_url(), HandleListAccounts);
205
206 // Handles /GetUserInfo GAIA call.
207 REGISTER_RESPONSE_HANDLER(
208 gaia_urls->get_user_info_url(), HandleGetUserInfo);
179 } 209 }
180 210
181 scoped_ptr<HttpResponse> FakeGaia::HandleRequest(const HttpRequest& request) { 211 scoped_ptr<HttpResponse> FakeGaia::HandleRequest(const HttpRequest& request) {
182 // The scheme and host of the URL is actually not important but required to 212 // The scheme and host of the URL is actually not important but required to
183 // get a valid GURL in order to parse |request.relative_url|. 213 // get a valid GURL in order to parse |request.relative_url|.
184 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); 214 GURL request_url = GURL("http://localhost").Resolve(request.relative_url);
185 std::string request_path = request_url.path(); 215 std::string request_path = request_url.path();
186 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); 216 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse());
187 RequestHandlerMap::iterator iter = request_handlers_.find(request_path); 217 RequestHandlerMap::iterator iter = request_handlers_.find(request_path);
188 if (iter != request_handlers_.end()) { 218 if (iter != request_handlers_.end()) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 368
339 void FakeGaia::HandleOAuthLogin(const HttpRequest& request, 369 void FakeGaia::HandleOAuthLogin(const HttpRequest& request,
340 BasicHttpResponse* http_response) { 370 BasicHttpResponse* http_response) {
341 http_response->set_code(net::HTTP_UNAUTHORIZED); 371 http_response->set_code(net::HTTP_UNAUTHORIZED);
342 if (merge_session_params_.gaia_uber_token.empty()) { 372 if (merge_session_params_.gaia_uber_token.empty()) {
343 http_response->set_code(net::HTTP_FORBIDDEN); 373 http_response->set_code(net::HTTP_FORBIDDEN);
344 return; 374 return;
345 } 375 }
346 376
347 std::string access_token; 377 std::string access_token;
348 if (!GetAccessToken(request, kAuthHeaderOAuth, &access_token)) { 378 if (!GetAccessToken(request, kAuthHeaderBearer, &access_token)) {
349 LOG(ERROR) << "/OAuthLogin missing access token in the header"; 379 LOG(ERROR) << "/OAuthLogin missing access token in the header";
350 return; 380 return;
351 } 381 }
352 382
353 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); 383 GURL request_url = GURL("http://localhost").Resolve(request.relative_url);
354 std::string request_query = request_url.query(); 384 std::string request_query = request_url.query();
355 385
356 std::string source; 386 std::string source;
357 if (!GetQueryParameter(request_query, "source", &source)) { 387 if (!GetQueryParameter(request_query, "source", &source) &&
388 !GetQueryParameter(request.content, "source", &source)) {
358 LOG(ERROR) << "Missing 'source' param in /OAuthLogin call"; 389 LOG(ERROR) << "Missing 'source' param in /OAuthLogin call";
359 return; 390 return;
360 } 391 }
361 392
362 std::string issue_uberauth; 393 std::string issue_uberauth;
363 if (GetQueryParameter(request_query, "issueuberauth", &issue_uberauth) && 394 if (GetQueryParameter(request_query, "issueuberauth", &issue_uberauth) &&
364 issue_uberauth == "1") { 395 issue_uberauth == "1") {
365 http_response->set_content(merge_session_params_.gaia_uber_token); 396 http_response->set_content(merge_session_params_.gaia_uber_token);
366 http_response->set_code(net::HTTP_OK); 397 http_response->set_code(net::HTTP_OK);
367 // Issue GAIA uber token. 398 // Issue GAIA uber token.
368 } else { 399 } else {
369 LOG(FATAL) << "/OAuthLogin for SID/LSID is not supported"; 400 http_response->set_content(base::StringPrintf(
401 "SID=%s\nLSID=%s\nAuth=%s",
402 kTestOAuthLoginSID, kTestOAuthLoginLSID, kTestOAuthLoginAuthCode));
403 http_response->set_code(net::HTTP_OK);
370 } 404 }
371 } 405 }
372 406
373 void FakeGaia::HandleServiceLoginAuth(const HttpRequest& request, 407 void FakeGaia::HandleServiceLoginAuth(const HttpRequest& request,
374 BasicHttpResponse* http_response) { 408 BasicHttpResponse* http_response) {
375 std::string continue_url = 409 std::string continue_url =
376 GaiaUrls::GetInstance()->service_login_url().spec(); 410 GaiaUrls::GetInstance()->service_login_url().spec();
377 GetQueryParameter(request.content, "continue", &continue_url); 411 GetQueryParameter(request.content, "continue", &continue_url);
378 412
379 std::string redirect_url = continue_url; 413 std::string redirect_url = continue_url;
380 414
381 std::string email; 415 std::string email;
382 if (GetQueryParameter(request.content, "Email", &email) && 416 if (GetQueryParameter(request.content, "Email", &email) &&
383 saml_account_idp_map_.find(email) != saml_account_idp_map_.end()) { 417 saml_account_idp_map_.find(email) != saml_account_idp_map_.end()) {
384 GURL url(saml_account_idp_map_[email]); 418 GURL url(saml_account_idp_map_[email]);
385 url = net::AppendQueryParameter(url, "SAMLRequest", "fake_request"); 419 url = net::AppendQueryParameter(url, "SAMLRequest", "fake_request");
386 url = net::AppendQueryParameter(url, "RelayState", continue_url); 420 url = net::AppendQueryParameter(url, "RelayState", continue_url);
387 redirect_url = url.spec(); 421 redirect_url = url.spec();
388 http_response->AddCustomHeader("Google-Accounts-SAML", "Start"); 422 http_response->AddCustomHeader("Google-Accounts-SAML", "Start");
389 } else if (!merge_session_params_.auth_sid_cookie.empty() && 423 } else if (!merge_session_params_.auth_sid_cookie.empty() &&
390 !merge_session_params_.auth_lsid_cookie.empty()) { 424 !merge_session_params_.auth_lsid_cookie.empty()) {
391 SetCookies(http_response, 425 SetCookies(http_response,
392 merge_session_params_.auth_sid_cookie, 426 merge_session_params_.auth_sid_cookie,
393 merge_session_params_.auth_lsid_cookie); 427 merge_session_params_.auth_lsid_cookie);
394 } 428 }
395 429
396 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); 430 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT);
397 http_response->AddCustomHeader("Location", redirect_url); 431 http_response->AddCustomHeader("Location", redirect_url);
432 http_response->AddCustomHeader("google-accounts-signin",
433 base::StringPrintf("email=\"%s\", sessionindex=0", email.c_str()));
398 } 434 }
399 435
400 void FakeGaia::HandleSSO(const HttpRequest& request, 436 void FakeGaia::HandleSSO(const HttpRequest& request,
401 BasicHttpResponse* http_response) { 437 BasicHttpResponse* http_response) {
402 if (!merge_session_params_.auth_sid_cookie.empty() && 438 if (!merge_session_params_.auth_sid_cookie.empty() &&
403 !merge_session_params_.auth_lsid_cookie.empty()) { 439 !merge_session_params_.auth_lsid_cookie.empty()) {
404 SetCookies(http_response, 440 SetCookies(http_response,
405 merge_session_params_.auth_sid_cookie, 441 merge_session_params_.auth_sid_cookie,
406 merge_session_params_.auth_lsid_cookie); 442 merge_session_params_.auth_lsid_cookie);
407 } 443 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 base::IntToString(token_info->expires_in)); 557 base::IntToString(token_info->expires_in));
522 response_dict.SetString("token", token_info->token); 558 response_dict.SetString("token", token_info->token);
523 FormatJSONResponse(response_dict, http_response); 559 FormatJSONResponse(response_dict, http_response);
524 return; 560 return;
525 } 561 }
526 } 562 }
527 http_response->set_code(net::HTTP_BAD_REQUEST); 563 http_response->set_code(net::HTTP_BAD_REQUEST);
528 } 564 }
529 565
530 void FakeGaia::HandleListAccounts(const HttpRequest& request, 566 void FakeGaia::HandleListAccounts(const HttpRequest& request,
531 BasicHttpResponse* http_response) { 567 BasicHttpResponse* http_response) {
532 http_response->set_content(base::StringPrintf( 568 http_response->set_content(base::StringPrintf(
533 kListAccountsResponseFormat, merge_session_params_.email.c_str())); 569 kListAccountsResponseFormat, merge_session_params_.email.c_str()));
534 http_response->set_code(net::HTTP_OK); 570 http_response->set_code(net::HTTP_OK);
535 } 571 }
572
573 void FakeGaia::HandleGetUserInfo(const HttpRequest& request,
574 BasicHttpResponse* http_response) {
575 http_response->set_content(base::StringPrintf(
576 "email=%s\ndisplayEmail=%s",
577 merge_session_params_.email.c_str(),
578 merge_session_params_.email.c_str()));
579 http_response->set_code(net::HTTP_OK);
580 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698