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 #ifndef GOOGLE_APIS_GAIA_FAKE_GAIA_H_ | 5 #ifndef GOOGLE_APIS_GAIA_FAKE_GAIA_H_ |
6 #define GOOGLE_APIS_GAIA_FAKE_GAIA_H_ | 6 #define GOOGLE_APIS_GAIA_FAKE_GAIA_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 class DictionaryValue; | 18 class DictionaryValue; |
18 } | 19 } |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 namespace test_server { | 22 namespace test_server { |
22 class BasicHttpResponse; | 23 class BasicHttpResponse; |
(...skipping 19 matching lines...) Expand all Loading... |
42 std::string audience; | 43 std::string audience; |
43 std::string user_id; | 44 std::string user_id; |
44 ScopeSet scopes; | 45 ScopeSet scopes; |
45 int expires_in; | 46 int expires_in; |
46 std::string email; | 47 std::string email; |
47 }; | 48 }; |
48 | 49 |
49 FakeGaia(); | 50 FakeGaia(); |
50 ~FakeGaia(); | 51 ~FakeGaia(); |
51 | 52 |
| 53 // Sets the initial value of tokens and cookies. |
| 54 void SetAuthTokens(const std::string& auth_code, |
| 55 const std::string& refresh_token, |
| 56 const std::string& access_token, |
| 57 const std::string& gaia_uber_token, |
| 58 const std::string& session_sid_cookie, |
| 59 const std::string& session_lsid_cookie); |
| 60 |
| 61 // Initializes HTTP request handlers. Should be called after switches |
| 62 // for tweaking GaiaUrls are in place. |
| 63 void Initialize(); |
| 64 |
52 // Handles a request and returns a response if the request was recognized as a | 65 // Handles a request and returns a response if the request was recognized as a |
53 // GAIA request. Note that this respects the switches::kGaiaUrl and friends so | 66 // GAIA request. Note that this respects the switches::kGaiaUrl and friends so |
54 // that this can used with EmbeddedTestServer::RegisterRequestHandler(). | 67 // that this can used with EmbeddedTestServer::RegisterRequestHandler(). |
55 scoped_ptr<net::test_server::HttpResponse> HandleRequest( | 68 scoped_ptr<net::test_server::HttpResponse> HandleRequest( |
56 const net::test_server::HttpRequest& request); | 69 const net::test_server::HttpRequest& request); |
57 | 70 |
58 // Configures an OAuth2 token that'll be returned when a client requests an | 71 // Configures an OAuth2 token that'll be returned when a client requests an |
59 // access token for the given auth token, which can be a refresh token or an | 72 // access token for the given auth token, which can be a refresh token or an |
60 // login-scoped access token for the token minting endpoint. Note that the | 73 // login-scoped access token for the token minting endpoint. Note that the |
61 // scope and audience requested by the client need to match the token_info. | 74 // scope and audience requested by the client need to match the token_info. |
(...skipping 12 matching lines...) Expand all Loading... |
74 std::string* value); | 87 std::string* value); |
75 | 88 |
76 private: | 89 private: |
77 typedef std::multimap<std::string, AccessTokenInfo> AccessTokenInfoMap; | 90 typedef std::multimap<std::string, AccessTokenInfo> AccessTokenInfoMap; |
78 typedef std::map<std::string, GURL> SamlAccountIdpMap; | 91 typedef std::map<std::string, GURL> SamlAccountIdpMap; |
79 | 92 |
80 // Formats a JSON response with the data in |response_dict|. | 93 // Formats a JSON response with the data in |response_dict|. |
81 void FormatJSONResponse(const base::DictionaryValue& response_dict, | 94 void FormatJSONResponse(const base::DictionaryValue& response_dict, |
82 net::test_server::BasicHttpResponse* http_response); | 95 net::test_server::BasicHttpResponse* http_response); |
83 | 96 |
| 97 typedef base::Callback<void( |
| 98 const net::test_server::HttpRequest& request, |
| 99 net::test_server::BasicHttpResponse* http_response)> |
| 100 HttpRequestHandlerCallback; |
| 101 typedef std::map<std::string, HttpRequestHandlerCallback> RequestHandlerMap; |
| 102 |
| 103 // HTTP request handlers. |
| 104 void HandleProgramaticAuth( |
| 105 const net::test_server::HttpRequest& request, |
| 106 net::test_server::BasicHttpResponse* http_response); |
| 107 void HandleServiceLogin(const net::test_server::HttpRequest& request, |
| 108 net::test_server::BasicHttpResponse* http_response); |
| 109 void HandleOAuthLogin(const net::test_server::HttpRequest& request, |
| 110 net::test_server::BasicHttpResponse* http_response); |
| 111 void HandleSSO(const net::test_server::HttpRequest& request, |
| 112 net::test_server::BasicHttpResponse* http_response); |
| 113 void HandleMergeSession(const net::test_server::HttpRequest& request, |
| 114 net::test_server::BasicHttpResponse* http_response); |
| 115 void HandleServiceLoginAuth( |
| 116 const net::test_server::HttpRequest& request, |
| 117 net::test_server::BasicHttpResponse* http_response); |
| 118 void HandleAuthToken(const net::test_server::HttpRequest& request, |
| 119 net::test_server::BasicHttpResponse* http_response); |
| 120 void HandleTokenInfo(const net::test_server::HttpRequest& request, |
| 121 net::test_server::BasicHttpResponse* http_response); |
| 122 void HandleIssueToken(const net::test_server::HttpRequest& request, |
| 123 net::test_server::BasicHttpResponse* http_response); |
| 124 |
84 // Returns the access token associated with |auth_token| that matches the | 125 // Returns the access token associated with |auth_token| that matches the |
85 // given |client_id| and |scope_string|. If |scope_string| is empty, the first | 126 // given |client_id| and |scope_string|. If |scope_string| is empty, the first |
86 // token satisfying the other criteria is returned. Returns NULL if no token | 127 // token satisfying the other criteria is returned. Returns NULL if no token |
87 // matches. | 128 // matches. |
88 const AccessTokenInfo* GetAccessTokenInfo(const std::string& auth_token, | 129 const AccessTokenInfo* FindAccessTokenInfo(const std::string& auth_token, |
89 const std::string& client_id, | 130 const std::string& client_id, |
90 const std::string& scope_string) | 131 const std::string& scope_string) |
91 const; | 132 const; |
92 | 133 |
| 134 // Extracts the |access_token| from authorization header of |request|. |
| 135 static bool GetAccessToken(const net::test_server::HttpRequest& request, |
| 136 const char* auth_token_prefix, |
| 137 std::string* access_token); |
| 138 |
| 139 // auth_code cookie value response for /o/oauth2/programmatic_auth call. |
| 140 std::string fake_auth_code_; |
| 141 |
| 142 // refresh_token field value response for the initial /o/oauth2/token call |
| 143 // with ...&grant_type=authorization_code. |
| 144 std::string fake_refresh_token_; |
| 145 std::string fake_access_token_; |
| 146 std::string fake_gaia_uber_token_; |
| 147 std::string fake_session_sid_cookie_; |
| 148 std::string fake_session_lsid_cookie_; |
| 149 |
93 AccessTokenInfoMap access_token_info_map_; | 150 AccessTokenInfoMap access_token_info_map_; |
| 151 RequestHandlerMap request_handlers_; |
94 std::string service_login_response_; | 152 std::string service_login_response_; |
95 SamlAccountIdpMap saml_account_idp_map_; | 153 SamlAccountIdpMap saml_account_idp_map_; |
96 | 154 |
97 DISALLOW_COPY_AND_ASSIGN(FakeGaia); | 155 DISALLOW_COPY_AND_ASSIGN(FakeGaia); |
98 }; | 156 }; |
99 | 157 |
100 #endif // GOOGLE_APIS_GAIA_FAKE_GAIA_H_ | 158 #endif // GOOGLE_APIS_GAIA_FAKE_GAIA_H_ |
OLD | NEW |