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