| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "google_apis/gaia/gaia_constants.h" | 24 #include "google_apis/gaia/gaia_constants.h" |
| 25 #include "google_apis/gaia/gaia_urls.h" | 25 #include "google_apis/gaia/gaia_urls.h" |
| 26 #include "net/base/url_util.h" | 26 #include "net/base/url_util.h" |
| 27 #include "net/cookies/parsed_cookie.h" | 27 #include "net/cookies/parsed_cookie.h" |
| 28 #include "net/http/http_status_code.h" | 28 #include "net/http/http_status_code.h" |
| 29 #include "net/test/embedded_test_server/http_request.h" | 29 #include "net/test/embedded_test_server/http_request.h" |
| 30 #include "net/test/embedded_test_server/http_response.h" | 30 #include "net/test/embedded_test_server/http_response.h" |
| 31 #include "url/third_party/mozilla/url_parse.h" | 31 #include "url/third_party/mozilla/url_parse.h" |
| 32 | 32 |
| 33 #define REGISTER_RESPONSE_HANDLER(url, method) \ | 33 #define REGISTER_RESPONSE_HANDLER(url, method) \ |
| 34 request_handlers_.insert(std::make_pair( \ | 34 request_handlers_.insert( \ |
| 35 url.path(), base::Bind(&FakeGaia::method, base::Unretained(this)))) | 35 std::make_pair(url.path().as_string(), \ |
| 36 base::Bind(&FakeGaia::method, base::Unretained(this)))) |
| 36 | 37 |
| 37 #define REGISTER_PATH_RESPONSE_HANDLER(path, method) \ | 38 #define REGISTER_PATH_RESPONSE_HANDLER(path, method) \ |
| 38 request_handlers_.insert(std::make_pair( \ | 39 request_handlers_.insert(std::make_pair( \ |
| 39 path, base::Bind(&FakeGaia::method, base::Unretained(this)))) | 40 path, base::Bind(&FakeGaia::method, base::Unretained(this)))) |
| 40 | 41 |
| 41 using namespace net::test_server; | 42 using namespace net::test_server; |
| 42 | 43 |
| 43 namespace { | 44 namespace { |
| 44 | 45 |
| 45 const char kTestAuthCode[] = "fake-auth-code"; | 46 const char kTestAuthCode[] = "fake-auth-code"; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 // Handles /oauth2/v1/userinfo call. | 299 // Handles /oauth2/v1/userinfo call. |
| 299 REGISTER_RESPONSE_HANDLER( | 300 REGISTER_RESPONSE_HANDLER( |
| 300 gaia_urls->oauth_user_info_url(), HandleOAuthUserInfo); | 301 gaia_urls->oauth_user_info_url(), HandleOAuthUserInfo); |
| 301 } | 302 } |
| 302 | 303 |
| 303 std::unique_ptr<HttpResponse> FakeGaia::HandleRequest( | 304 std::unique_ptr<HttpResponse> FakeGaia::HandleRequest( |
| 304 const HttpRequest& request) { | 305 const HttpRequest& request) { |
| 305 // The scheme and host of the URL is actually not important but required to | 306 // The scheme and host of the URL is actually not important but required to |
| 306 // get a valid GURL in order to parse |request.relative_url|. | 307 // get a valid GURL in order to parse |request.relative_url|. |
| 307 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); | 308 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); |
| 308 std::string request_path = request_url.path(); | 309 base::StringPiece request_path = request_url.path(); |
| 309 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); | 310 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); |
| 310 RequestHandlerMap::iterator iter = request_handlers_.find(request_path); | 311 RequestHandlerMap::iterator iter = |
| 312 request_handlers_.find(request_path.as_string()); |
| 311 if (iter != request_handlers_.end()) { | 313 if (iter != request_handlers_.end()) { |
| 312 LOG(WARNING) << "Serving request " << request_path; | 314 LOG(WARNING) << "Serving request " << request_path; |
| 313 iter->second.Run(request, http_response.get()); | 315 iter->second.Run(request, http_response.get()); |
| 314 } else { | 316 } else { |
| 315 LOG(ERROR) << "Unhandled request " << request_path; | 317 LOG(ERROR) << "Unhandled request " << request_path; |
| 316 return std::unique_ptr<HttpResponse>(); // Request not understood. | 318 return std::unique_ptr<HttpResponse>(); // Request not understood. |
| 317 } | 319 } |
| 318 | 320 |
| 319 return std::move(http_response); | 321 return std::move(http_response); |
| 320 } | 322 } |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 url = net::AppendQueryParameter(url, "RelayState", | 835 url = net::AppendQueryParameter(url, "RelayState", |
| 834 GaiaUrls::GetInstance() | 836 GaiaUrls::GetInstance() |
| 835 ->gaia_url() | 837 ->gaia_url() |
| 836 .Resolve(kDummySAMLContinuePath) | 838 .Resolve(kDummySAMLContinuePath) |
| 837 .spec()); | 839 .spec()); |
| 838 std::string redirect_url = url.spec(); | 840 std::string redirect_url = url.spec(); |
| 839 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); | 841 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); |
| 840 http_response->AddCustomHeader("Google-Accounts-SAML", "Start"); | 842 http_response->AddCustomHeader("Google-Accounts-SAML", "Start"); |
| 841 http_response->AddCustomHeader("Location", redirect_url); | 843 http_response->AddCustomHeader("Location", redirect_url); |
| 842 } | 844 } |
| OLD | NEW |