| 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 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 const base::FilePath::CharType kServiceLogin[] = | 43 const base::FilePath::CharType kServiceLogin[] = |
| 44 FILE_PATH_LITERAL("google_apis/test/service_login.html"); | 44 FILE_PATH_LITERAL("google_apis/test/service_login.html"); |
| 45 | 45 |
| 46 // OAuth2 Authentication header value prefix. | 46 // OAuth2 Authentication header value prefix. |
| 47 const char kAuthHeaderBearer[] = "Bearer "; | 47 const char kAuthHeaderBearer[] = "Bearer "; |
| 48 const char kAuthHeaderOAuth[] = "OAuth "; | 48 const char kAuthHeaderOAuth[] = "OAuth "; |
| 49 | 49 |
| 50 const char kListAccountsResponseFormat[] = |
| 51 "[\"gaia.l.a.r\",[[\"gaia.l.a\",1,\"\",\"%s\",\"\",1,1,0]]]"; |
| 52 |
| 50 typedef std::map<std::string, std::string> CookieMap; | 53 typedef std::map<std::string, std::string> CookieMap; |
| 51 | 54 |
| 52 // Parses cookie name-value map our of |request|. | 55 // Parses cookie name-value map our of |request|. |
| 53 CookieMap GetRequestCookies(const HttpRequest& request) { | 56 CookieMap GetRequestCookies(const HttpRequest& request) { |
| 54 CookieMap result; | 57 CookieMap result; |
| 55 std::map<std::string, std::string>::const_iterator iter = | 58 std::map<std::string, std::string>::const_iterator iter = |
| 56 request.headers.find("Cookie"); | 59 request.headers.find("Cookie"); |
| 57 if (iter != request.headers.end()) { | 60 if (iter != request.headers.end()) { |
| 58 std::vector<std::string> cookie_nv_pairs; | 61 std::vector<std::string> cookie_nv_pairs; |
| 59 base::SplitString(iter->second, ' ', &cookie_nv_pairs); | 62 base::SplitString(iter->second, ' ', &cookie_nv_pairs); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 gaia_urls->oauth2_token_url(), HandleAuthToken); | 165 gaia_urls->oauth2_token_url(), HandleAuthToken); |
| 163 | 166 |
| 164 // Handles /oauth2/v2/tokeninfo GAIA call. | 167 // Handles /oauth2/v2/tokeninfo GAIA call. |
| 165 REGISTER_RESPONSE_HANDLER( | 168 REGISTER_RESPONSE_HANDLER( |
| 166 gaia_urls->oauth2_token_info_url(), HandleTokenInfo); | 169 gaia_urls->oauth2_token_info_url(), HandleTokenInfo); |
| 167 | 170 |
| 168 // Handles /oauth2/v2/IssueToken GAIA call. | 171 // Handles /oauth2/v2/IssueToken GAIA call. |
| 169 REGISTER_RESPONSE_HANDLER( | 172 REGISTER_RESPONSE_HANDLER( |
| 170 gaia_urls->oauth2_issue_token_url(), HandleIssueToken); | 173 gaia_urls->oauth2_issue_token_url(), HandleIssueToken); |
| 171 | 174 |
| 172 // Handles /GetUserInfo GAIA call. | 175 // Handles /ListAccounts GAIA call. |
| 173 REGISTER_RESPONSE_HANDLER( | 176 REGISTER_RESPONSE_HANDLER( |
| 174 gaia_urls->get_user_info_url(), HandleGetUserInfo); | 177 gaia_urls->list_accounts_url(), HandleListAccounts); |
| 175 } | 178 } |
| 176 | 179 |
| 177 scoped_ptr<HttpResponse> FakeGaia::HandleRequest(const HttpRequest& request) { | 180 scoped_ptr<HttpResponse> FakeGaia::HandleRequest(const HttpRequest& request) { |
| 178 // The scheme and host of the URL is actually not important but required to | 181 // The scheme and host of the URL is actually not important but required to |
| 179 // get a valid GURL in order to parse |request.relative_url|. | 182 // get a valid GURL in order to parse |request.relative_url|. |
| 180 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); | 183 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); |
| 181 std::string request_path = request_url.path(); | 184 std::string request_path = request_url.path(); |
| 182 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); | 185 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); |
| 183 RequestHandlerMap::iterator iter = request_handlers_.find(request_path); | 186 RequestHandlerMap::iterator iter = request_handlers_.find(request_path); |
| 184 if (iter != request_handlers_.end()) { | 187 if (iter != request_handlers_.end()) { |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 response_dict.SetString("issueAdvice", "auto"); | 515 response_dict.SetString("issueAdvice", "auto"); |
| 513 response_dict.SetString("expiresIn", | 516 response_dict.SetString("expiresIn", |
| 514 base::IntToString(token_info->expires_in)); | 517 base::IntToString(token_info->expires_in)); |
| 515 response_dict.SetString("token", token_info->token); | 518 response_dict.SetString("token", token_info->token); |
| 516 FormatJSONResponse(response_dict, http_response); | 519 FormatJSONResponse(response_dict, http_response); |
| 517 } else { | 520 } else { |
| 518 http_response->set_code(net::HTTP_BAD_REQUEST); | 521 http_response->set_code(net::HTTP_BAD_REQUEST); |
| 519 } | 522 } |
| 520 } | 523 } |
| 521 | 524 |
| 522 void FakeGaia::HandleGetUserInfo(const HttpRequest& request, | 525 void FakeGaia::HandleListAccounts(const HttpRequest& request, |
| 523 BasicHttpResponse* http_response) { | 526 BasicHttpResponse* http_response) { |
| 524 std::string lsid; | |
| 525 if (!GetQueryParameter(request.content, "LSID", &lsid)) { | |
| 526 http_response->set_code(net::HTTP_BAD_REQUEST); | |
| 527 LOG(ERROR) << "/GetUserInfo missing LSID"; | |
| 528 return; | |
| 529 } | |
| 530 if (lsid != merge_session_params_.auth_lsid_cookie) { | |
| 531 http_response->set_code(net::HTTP_BAD_REQUEST); | |
| 532 LOG(ERROR) << "/GetUserInfo contains unknown LSID"; | |
| 533 return; | |
| 534 } | |
| 535 http_response->set_content(base::StringPrintf( | 527 http_response->set_content(base::StringPrintf( |
| 536 "email=%s", merge_session_params_.email.c_str())); | 528 kListAccountsResponseFormat, merge_session_params_.email.c_str())); |
| 537 http_response->set_code(net::HTTP_OK); | 529 http_response->set_code(net::HTTP_OK); |
| 538 } | 530 } |
| OLD | NEW |