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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 const char kAuthHeaderOAuth[] = "OAuth "; | 64 const char kAuthHeaderOAuth[] = "OAuth "; |
65 | 65 |
66 const char kListAccountsResponseFormat[] = | 66 const char kListAccountsResponseFormat[] = |
67 "[\"gaia.l.a.r\",[[\"gaia.l.a\",1,\"\",\"%s\",\"\",1,1,0,0,1,\"12345\"]]]"; | 67 "[\"gaia.l.a.r\",[[\"gaia.l.a\",1,\"\",\"%s\",\"\",1,1,0,0,1,\"12345\"]]]"; |
68 | 68 |
69 typedef std::map<std::string, std::string> CookieMap; | 69 typedef std::map<std::string, std::string> CookieMap; |
70 | 70 |
71 // Parses cookie name-value map our of |request|. | 71 // Parses cookie name-value map our of |request|. |
72 CookieMap GetRequestCookies(const HttpRequest& request) { | 72 CookieMap GetRequestCookies(const HttpRequest& request) { |
73 CookieMap result; | 73 CookieMap result; |
74 std::map<std::string, std::string>::const_iterator iter = | 74 auto iter = request.headers.find("Cookie"); |
75 request.headers.find("Cookie"); | |
76 if (iter != request.headers.end()) { | 75 if (iter != request.headers.end()) { |
77 std::vector<std::string> cookie_nv_pairs; | 76 for (const std::string& cookie_line : |
78 base::SplitString(iter->second, ' ', &cookie_nv_pairs); | 77 base::SplitString(iter->second, " ", base::TRIM_WHITESPACE, |
79 for(std::vector<std::string>::const_iterator cookie_line = | 78 base::SPLIT_WANT_ALL)) { |
80 cookie_nv_pairs.begin(); | 79 std::vector<std::string> name_value = base::SplitString( |
81 cookie_line != cookie_nv_pairs.end(); | 80 cookie_line, "=", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
82 ++cookie_line) { | |
83 std::vector<std::string> name_value; | |
84 base::SplitString(*cookie_line, '=', &name_value); | |
85 if (name_value.size() != 2) | 81 if (name_value.size() != 2) |
86 continue; | 82 continue; |
87 | 83 |
88 std::string value = name_value[1]; | 84 std::string value = name_value[1]; |
89 if (value.size() && value[value.size() - 1] == ';') | 85 if (value.size() && value[value.size() - 1] == ';') |
90 value = value.substr(0, value.size() -1); | 86 value = value.substr(0, value.size() -1); |
91 | 87 |
92 result.insert(std::make_pair(name_value[0], value)); | 88 result.insert(std::make_pair(name_value[0], value)); |
93 } | 89 } |
94 } | 90 } |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 http_response->set_code(net::HTTP_OK); | 430 http_response->set_code(net::HTTP_OK); |
435 } | 431 } |
436 | 432 |
437 const FakeGaia::AccessTokenInfo* FakeGaia::FindAccessTokenInfo( | 433 const FakeGaia::AccessTokenInfo* FakeGaia::FindAccessTokenInfo( |
438 const std::string& auth_token, | 434 const std::string& auth_token, |
439 const std::string& client_id, | 435 const std::string& client_id, |
440 const std::string& scope_string) const { | 436 const std::string& scope_string) const { |
441 if (auth_token.empty() || client_id.empty()) | 437 if (auth_token.empty() || client_id.empty()) |
442 return NULL; | 438 return NULL; |
443 | 439 |
444 std::vector<std::string> scope_list; | 440 std::vector<std::string> scope_list = base::SplitString( |
445 base::SplitString(scope_string, ' ', &scope_list); | 441 scope_string, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
446 ScopeSet scopes(scope_list.begin(), scope_list.end()); | 442 ScopeSet scopes(scope_list.begin(), scope_list.end()); |
447 | 443 |
448 for (AccessTokenInfoMap::const_iterator entry( | 444 for (AccessTokenInfoMap::const_iterator entry( |
449 access_token_info_map_.lower_bound(auth_token)); | 445 access_token_info_map_.lower_bound(auth_token)); |
450 entry != access_token_info_map_.upper_bound(auth_token); | 446 entry != access_token_info_map_.upper_bound(auth_token); |
451 ++entry) { | 447 ++entry) { |
452 if (entry->second.audience == client_id && | 448 if (entry->second.audience == client_id && |
453 (scope_string.empty() || entry->second.scopes == scopes)) { | 449 (scope_string.empty() || entry->second.scopes == scopes)) { |
454 return &(entry->second); | 450 return &(entry->second); |
455 } | 451 } |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 if (token_info) { | 765 if (token_info) { |
770 base::DictionaryValue response_dict; | 766 base::DictionaryValue response_dict; |
771 response_dict.SetString("id", GetGaiaIdOfEmail(token_info->email)); | 767 response_dict.SetString("id", GetGaiaIdOfEmail(token_info->email)); |
772 response_dict.SetString("email", token_info->email); | 768 response_dict.SetString("email", token_info->email); |
773 response_dict.SetString("verified_email", token_info->email); | 769 response_dict.SetString("verified_email", token_info->email); |
774 FormatJSONResponse(response_dict, http_response); | 770 FormatJSONResponse(response_dict, http_response); |
775 } else { | 771 } else { |
776 http_response->set_code(net::HTTP_BAD_REQUEST); | 772 http_response->set_code(net::HTTP_BAD_REQUEST); |
777 } | 773 } |
778 } | 774 } |
OLD | NEW |