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

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: fix isolate dependency Created 6 years, 3 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
« no previous file with comments | « google_apis/gaia/fake_gaia.h ('k') | net/test/embedded_test_server/embedded_test_server.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "; 59 const char kAuthHeaderOAuth[] = "OAuth ";
50 60
51 const char kListAccountsResponseFormat[] = 61 const char kListAccountsResponseFormat[] =
52 "[\"gaia.l.a.r\",[[\"gaia.l.a\",1,\"\",\"%s\",\"\",1,1,0]]]"; 62 "[\"gaia.l.a.r\",[[\"gaia.l.a\",1,\"\",\"%s\",\"\",1,1,0]]]";
53 63
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 FakeGaia::FakeGaia() { 134 FakeGaia::FakeGaia() {
125 base::FilePath source_root_dir; 135 base::FilePath source_root_dir;
126 PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir); 136 PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir);
127 CHECK(base::ReadFileToString( 137 CHECK(base::ReadFileToString(
128 source_root_dir.Append(base::FilePath(kServiceLogin)), 138 source_root_dir.Append(base::FilePath(kServiceLogin)),
129 &service_login_response_)); 139 &service_login_response_));
130 } 140 }
131 141
132 FakeGaia::~FakeGaia() {} 142 FakeGaia::~FakeGaia() {}
133 143
144 void FakeGaia::SetFakeMergeSessionParams(
145 const std::string& email,
146 const std::string& auth_sid_cookie,
147 const std::string& auth_lsid_cookie) {
148 FakeGaia::MergeSessionParams params;
149 params.auth_sid_cookie = auth_sid_cookie;
150 params.auth_lsid_cookie = auth_lsid_cookie;
151 params.auth_code = kTestAuthCode;
152 params.refresh_token = kTestRefreshToken;
153 params.access_token = kTestAuthLoginAccessToken;
154 params.gaia_uber_token = kTestGaiaUberToken;
155 params.session_sid_cookie = kTestSessionSIDCookie;
156 params.session_lsid_cookie = kTestSessionLSIDCookie;
157 params.email = email;
158 SetMergeSessionParams(params);
159 }
160
134 void FakeGaia::SetMergeSessionParams( 161 void FakeGaia::SetMergeSessionParams(
135 const MergeSessionParams& params) { 162 const MergeSessionParams& params) {
136 merge_session_params_ = params; 163 merge_session_params_ = params;
137 } 164 }
138 165
139 void FakeGaia::Initialize() { 166 void FakeGaia::Initialize() {
140 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 167 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
141 // Handles /MergeSession GAIA call. 168 // Handles /MergeSession GAIA call.
142 REGISTER_RESPONSE_HANDLER( 169 REGISTER_RESPONSE_HANDLER(
143 gaia_urls->merge_session_url(), HandleMergeSession); 170 gaia_urls->merge_session_url(), HandleMergeSession);
(...skipping 25 matching lines...) Expand all
169 REGISTER_RESPONSE_HANDLER( 196 REGISTER_RESPONSE_HANDLER(
170 gaia_urls->oauth2_token_info_url(), HandleTokenInfo); 197 gaia_urls->oauth2_token_info_url(), HandleTokenInfo);
171 198
172 // Handles /oauth2/v2/IssueToken GAIA call. 199 // Handles /oauth2/v2/IssueToken GAIA call.
173 REGISTER_RESPONSE_HANDLER( 200 REGISTER_RESPONSE_HANDLER(
174 gaia_urls->oauth2_issue_token_url(), HandleIssueToken); 201 gaia_urls->oauth2_issue_token_url(), HandleIssueToken);
175 202
176 // Handles /ListAccounts GAIA call. 203 // Handles /ListAccounts GAIA call.
177 REGISTER_RESPONSE_HANDLER( 204 REGISTER_RESPONSE_HANDLER(
178 gaia_urls->list_accounts_url(), HandleListAccounts); 205 gaia_urls->list_accounts_url(), HandleListAccounts);
206
207 // Handles /GetUserInfo GAIA call.
208 REGISTER_RESPONSE_HANDLER(
209 gaia_urls->get_user_info_url(), HandleGetUserInfo);
179 } 210 }
180 211
181 scoped_ptr<HttpResponse> FakeGaia::HandleRequest(const HttpRequest& request) { 212 scoped_ptr<HttpResponse> FakeGaia::HandleRequest(const HttpRequest& request) {
182 // The scheme and host of the URL is actually not important but required to 213 // 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|. 214 // get a valid GURL in order to parse |request.relative_url|.
184 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); 215 GURL request_url = GURL("http://localhost").Resolve(request.relative_url);
185 std::string request_path = request_url.path(); 216 std::string request_path = request_url.path();
186 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); 217 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse());
187 RequestHandlerMap::iterator iter = request_handlers_.find(request_path); 218 RequestHandlerMap::iterator iter = request_handlers_.find(request_path);
188 if (iter != request_handlers_.end()) { 219 if (iter != request_handlers_.end()) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 369
339 void FakeGaia::HandleOAuthLogin(const HttpRequest& request, 370 void FakeGaia::HandleOAuthLogin(const HttpRequest& request,
340 BasicHttpResponse* http_response) { 371 BasicHttpResponse* http_response) {
341 http_response->set_code(net::HTTP_UNAUTHORIZED); 372 http_response->set_code(net::HTTP_UNAUTHORIZED);
342 if (merge_session_params_.gaia_uber_token.empty()) { 373 if (merge_session_params_.gaia_uber_token.empty()) {
343 http_response->set_code(net::HTTP_FORBIDDEN); 374 http_response->set_code(net::HTTP_FORBIDDEN);
344 return; 375 return;
345 } 376 }
346 377
347 std::string access_token; 378 std::string access_token;
348 if (!GetAccessToken(request, kAuthHeaderOAuth, &access_token)) { 379 if (!GetAccessToken(request, kAuthHeaderBearer, &access_token) &&
380 !GetAccessToken(request, kAuthHeaderOAuth, &access_token)) {
349 LOG(ERROR) << "/OAuthLogin missing access token in the header"; 381 LOG(ERROR) << "/OAuthLogin missing access token in the header";
350 return; 382 return;
351 } 383 }
352 384
353 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); 385 GURL request_url = GURL("http://localhost").Resolve(request.relative_url);
354 std::string request_query = request_url.query(); 386 std::string request_query = request_url.query();
355 387
356 std::string source; 388 std::string source;
357 if (!GetQueryParameter(request_query, "source", &source)) { 389 if (!GetQueryParameter(request_query, "source", &source) &&
390 !GetQueryParameter(request.content, "source", &source)) {
358 LOG(ERROR) << "Missing 'source' param in /OAuthLogin call"; 391 LOG(ERROR) << "Missing 'source' param in /OAuthLogin call";
359 return; 392 return;
360 } 393 }
361 394
362 std::string issue_uberauth; 395 std::string issue_uberauth;
363 if (GetQueryParameter(request_query, "issueuberauth", &issue_uberauth) && 396 if (GetQueryParameter(request_query, "issueuberauth", &issue_uberauth) &&
364 issue_uberauth == "1") { 397 issue_uberauth == "1") {
365 http_response->set_content(merge_session_params_.gaia_uber_token); 398 http_response->set_content(merge_session_params_.gaia_uber_token);
366 http_response->set_code(net::HTTP_OK); 399 http_response->set_code(net::HTTP_OK);
367 // Issue GAIA uber token. 400 // Issue GAIA uber token.
368 } else { 401 } else {
369 LOG(FATAL) << "/OAuthLogin for SID/LSID is not supported"; 402 http_response->set_content(base::StringPrintf(
403 "SID=%s\nLSID=%s\nAuth=%s",
404 kTestOAuthLoginSID, kTestOAuthLoginLSID, kTestOAuthLoginAuthCode));
405 http_response->set_code(net::HTTP_OK);
370 } 406 }
371 } 407 }
372 408
373 void FakeGaia::HandleServiceLoginAuth(const HttpRequest& request, 409 void FakeGaia::HandleServiceLoginAuth(const HttpRequest& request,
374 BasicHttpResponse* http_response) { 410 BasicHttpResponse* http_response) {
375 std::string continue_url = 411 std::string continue_url =
376 GaiaUrls::GetInstance()->service_login_url().spec(); 412 GaiaUrls::GetInstance()->service_login_url().spec();
377 GetQueryParameter(request.content, "continue", &continue_url); 413 GetQueryParameter(request.content, "continue", &continue_url);
378 414
379 std::string redirect_url = continue_url; 415 std::string redirect_url = continue_url;
380 416
381 std::string email; 417 std::string email;
382 if (GetQueryParameter(request.content, "Email", &email) && 418 if (GetQueryParameter(request.content, "Email", &email) &&
383 saml_account_idp_map_.find(email) != saml_account_idp_map_.end()) { 419 saml_account_idp_map_.find(email) != saml_account_idp_map_.end()) {
384 GURL url(saml_account_idp_map_[email]); 420 GURL url(saml_account_idp_map_[email]);
385 url = net::AppendQueryParameter(url, "SAMLRequest", "fake_request"); 421 url = net::AppendQueryParameter(url, "SAMLRequest", "fake_request");
386 url = net::AppendQueryParameter(url, "RelayState", continue_url); 422 url = net::AppendQueryParameter(url, "RelayState", continue_url);
387 redirect_url = url.spec(); 423 redirect_url = url.spec();
388 http_response->AddCustomHeader("Google-Accounts-SAML", "Start"); 424 http_response->AddCustomHeader("Google-Accounts-SAML", "Start");
389 } else if (!merge_session_params_.auth_sid_cookie.empty() && 425 } else if (!merge_session_params_.auth_sid_cookie.empty() &&
390 !merge_session_params_.auth_lsid_cookie.empty()) { 426 !merge_session_params_.auth_lsid_cookie.empty()) {
391 SetCookies(http_response, 427 SetCookies(http_response,
392 merge_session_params_.auth_sid_cookie, 428 merge_session_params_.auth_sid_cookie,
393 merge_session_params_.auth_lsid_cookie); 429 merge_session_params_.auth_lsid_cookie);
394 } 430 }
395 431
396 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); 432 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT);
397 http_response->AddCustomHeader("Location", redirect_url); 433 http_response->AddCustomHeader("Location", redirect_url);
434 http_response->AddCustomHeader("google-accounts-signin",
435 base::StringPrintf("email=\"%s\", sessionindex=0", email.c_str()));
398 } 436 }
399 437
400 void FakeGaia::HandleSSO(const HttpRequest& request, 438 void FakeGaia::HandleSSO(const HttpRequest& request,
401 BasicHttpResponse* http_response) { 439 BasicHttpResponse* http_response) {
402 if (!merge_session_params_.auth_sid_cookie.empty() && 440 if (!merge_session_params_.auth_sid_cookie.empty() &&
403 !merge_session_params_.auth_lsid_cookie.empty()) { 441 !merge_session_params_.auth_lsid_cookie.empty()) {
404 SetCookies(http_response, 442 SetCookies(http_response,
405 merge_session_params_.auth_sid_cookie, 443 merge_session_params_.auth_sid_cookie,
406 merge_session_params_.auth_lsid_cookie); 444 merge_session_params_.auth_lsid_cookie);
407 } 445 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 base::IntToString(token_info->expires_in)); 559 base::IntToString(token_info->expires_in));
522 response_dict.SetString("token", token_info->token); 560 response_dict.SetString("token", token_info->token);
523 FormatJSONResponse(response_dict, http_response); 561 FormatJSONResponse(response_dict, http_response);
524 return; 562 return;
525 } 563 }
526 } 564 }
527 http_response->set_code(net::HTTP_BAD_REQUEST); 565 http_response->set_code(net::HTTP_BAD_REQUEST);
528 } 566 }
529 567
530 void FakeGaia::HandleListAccounts(const HttpRequest& request, 568 void FakeGaia::HandleListAccounts(const HttpRequest& request,
531 BasicHttpResponse* http_response) { 569 BasicHttpResponse* http_response) {
532 http_response->set_content(base::StringPrintf( 570 http_response->set_content(base::StringPrintf(
533 kListAccountsResponseFormat, merge_session_params_.email.c_str())); 571 kListAccountsResponseFormat, merge_session_params_.email.c_str()));
534 http_response->set_code(net::HTTP_OK); 572 http_response->set_code(net::HTTP_OK);
535 } 573 }
574
575 void FakeGaia::HandleGetUserInfo(const HttpRequest& request,
576 BasicHttpResponse* http_response) {
577 http_response->set_content(base::StringPrintf(
578 "email=%s\ndisplayEmail=%s",
579 merge_session_params_.email.c_str(),
580 merge_session_params_.email.c_str()));
581 http_response->set_code(net::HTTP_OK);
582 }
OLDNEW
« no previous file with comments | « google_apis/gaia/fake_gaia.h ('k') | net/test/embedded_test_server/embedded_test_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698