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> |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 // Uber token response from /OAuthLogin call. | 67 // Uber token response from /OAuthLogin call. |
68 std::string gaia_uber_token; | 68 std::string gaia_uber_token; |
69 | 69 |
70 // Values of SID and LSID cookie generated from /MergeSession call. | 70 // Values of SID and LSID cookie generated from /MergeSession call. |
71 std::string session_sid_cookie; | 71 std::string session_sid_cookie; |
72 std::string session_lsid_cookie; | 72 std::string session_lsid_cookie; |
73 }; | 73 }; |
74 | 74 |
75 FakeGaia(); | 75 FakeGaia(); |
76 ~FakeGaia(); | 76 virtual ~FakeGaia(); |
77 | 77 |
78 // Sets the initial value of tokens and cookies. | 78 // Sets the initial value of tokens and cookies. |
79 void SetMergeSessionParams(const MergeSessionParams& params); | 79 void SetMergeSessionParams(const MergeSessionParams& params); |
80 | 80 |
81 // Initializes HTTP request handlers. Should be called after switches | 81 // Initializes HTTP request handlers. Should be called after switches |
82 // for tweaking GaiaUrls are in place. | 82 // for tweaking GaiaUrls are in place. |
83 void Initialize(); | 83 void Initialize(); |
84 | 84 |
85 // Handles a request and returns a response if the request was recognized as a | 85 // Handles a request and returns a response if the request was recognized as a |
86 // GAIA request. Note that this respects the switches::kGaiaUrl and friends so | 86 // GAIA request. Note that this respects the switches::kGaiaUrl and friends so |
(...skipping 11 matching lines...) Expand all Loading... |
98 // Associates an account id with a SAML IdP redirect endpoint. When a | 98 // Associates an account id with a SAML IdP redirect endpoint. When a |
99 // /ServiceLoginAuth request comes in for that user, it will be redirected | 99 // /ServiceLoginAuth request comes in for that user, it will be redirected |
100 // to the associated redirect endpoint. | 100 // to the associated redirect endpoint. |
101 void RegisterSamlUser(const std::string& account_id, const GURL& saml_idp); | 101 void RegisterSamlUser(const std::string& account_id, const GURL& saml_idp); |
102 | 102 |
103 // Extracts the parameter named |key| from |query| and places it in |value|. | 103 // Extracts the parameter named |key| from |query| and places it in |value|. |
104 // Returns false if no parameter is found. | 104 // Returns false if no parameter is found. |
105 static bool GetQueryParameter(const std::string& query, | 105 static bool GetQueryParameter(const std::string& query, |
106 const std::string& key, | 106 const std::string& key, |
107 std::string* value); | 107 std::string* value); |
| 108 protected: |
| 109 // HTTP handler for /MergeSession. |
| 110 virtual void HandleMergeSession( |
| 111 const net::test_server::HttpRequest& request, |
| 112 net::test_server::BasicHttpResponse* http_response); |
108 | 113 |
109 private: | 114 private: |
110 typedef std::multimap<std::string, AccessTokenInfo> AccessTokenInfoMap; | 115 typedef std::multimap<std::string, AccessTokenInfo> AccessTokenInfoMap; |
111 typedef std::map<std::string, GURL> SamlAccountIdpMap; | 116 typedef std::map<std::string, GURL> SamlAccountIdpMap; |
112 | 117 |
113 // Formats a JSON response with the data in |response_dict|. | 118 // Formats a JSON response with the data in |response_dict|. |
114 void FormatJSONResponse(const base::DictionaryValue& response_dict, | 119 void FormatJSONResponse(const base::DictionaryValue& response_dict, |
115 net::test_server::BasicHttpResponse* http_response); | 120 net::test_server::BasicHttpResponse* http_response); |
116 | 121 |
117 typedef base::Callback<void( | 122 typedef base::Callback<void( |
118 const net::test_server::HttpRequest& request, | 123 const net::test_server::HttpRequest& request, |
119 net::test_server::BasicHttpResponse* http_response)> | 124 net::test_server::BasicHttpResponse* http_response)> |
120 HttpRequestHandlerCallback; | 125 HttpRequestHandlerCallback; |
121 typedef std::map<std::string, HttpRequestHandlerCallback> RequestHandlerMap; | 126 typedef std::map<std::string, HttpRequestHandlerCallback> RequestHandlerMap; |
122 | 127 |
123 // HTTP request handlers. | 128 // HTTP request handlers. |
124 void HandleProgramaticAuth( | 129 void HandleProgramaticAuth( |
125 const net::test_server::HttpRequest& request, | 130 const net::test_server::HttpRequest& request, |
126 net::test_server::BasicHttpResponse* http_response); | 131 net::test_server::BasicHttpResponse* http_response); |
127 void HandleServiceLogin(const net::test_server::HttpRequest& request, | 132 void HandleServiceLogin(const net::test_server::HttpRequest& request, |
128 net::test_server::BasicHttpResponse* http_response); | 133 net::test_server::BasicHttpResponse* http_response); |
129 void HandleOAuthLogin(const net::test_server::HttpRequest& request, | 134 void HandleOAuthLogin(const net::test_server::HttpRequest& request, |
130 net::test_server::BasicHttpResponse* http_response); | 135 net::test_server::BasicHttpResponse* http_response); |
131 void HandleSSO(const net::test_server::HttpRequest& request, | 136 void HandleSSO(const net::test_server::HttpRequest& request, |
132 net::test_server::BasicHttpResponse* http_response); | 137 net::test_server::BasicHttpResponse* http_response); |
133 void HandleMergeSession(const net::test_server::HttpRequest& request, | |
134 net::test_server::BasicHttpResponse* http_response); | |
135 void HandleServiceLoginAuth( | 138 void HandleServiceLoginAuth( |
136 const net::test_server::HttpRequest& request, | 139 const net::test_server::HttpRequest& request, |
137 net::test_server::BasicHttpResponse* http_response); | 140 net::test_server::BasicHttpResponse* http_response); |
138 void HandleAuthToken(const net::test_server::HttpRequest& request, | 141 void HandleAuthToken(const net::test_server::HttpRequest& request, |
139 net::test_server::BasicHttpResponse* http_response); | 142 net::test_server::BasicHttpResponse* http_response); |
140 void HandleTokenInfo(const net::test_server::HttpRequest& request, | 143 void HandleTokenInfo(const net::test_server::HttpRequest& request, |
141 net::test_server::BasicHttpResponse* http_response); | 144 net::test_server::BasicHttpResponse* http_response); |
142 void HandleIssueToken(const net::test_server::HttpRequest& request, | 145 void HandleIssueToken(const net::test_server::HttpRequest& request, |
143 net::test_server::BasicHttpResponse* http_response); | 146 net::test_server::BasicHttpResponse* http_response); |
144 | 147 |
145 // Returns the access token associated with |auth_token| that matches the | 148 // Returns the access token associated with |auth_token| that matches the |
146 // given |client_id| and |scope_string|. If |scope_string| is empty, the first | 149 // given |client_id| and |scope_string|. If |scope_string| is empty, the first |
147 // token satisfying the other criteria is returned. Returns NULL if no token | 150 // token satisfying the other criteria is returned. Returns NULL if no token |
148 // matches. | 151 // matches. |
149 const AccessTokenInfo* FindAccessTokenInfo(const std::string& auth_token, | 152 const AccessTokenInfo* FindAccessTokenInfo(const std::string& auth_token, |
150 const std::string& client_id, | 153 const std::string& client_id, |
151 const std::string& scope_string) | 154 const std::string& scope_string) |
152 const; | 155 const; |
153 | 156 |
154 MergeSessionParams merge_session_params_; | 157 MergeSessionParams merge_session_params_; |
155 AccessTokenInfoMap access_token_info_map_; | 158 AccessTokenInfoMap access_token_info_map_; |
156 RequestHandlerMap request_handlers_; | 159 RequestHandlerMap request_handlers_; |
157 std::string service_login_response_; | 160 std::string service_login_response_; |
158 SamlAccountIdpMap saml_account_idp_map_; | 161 SamlAccountIdpMap saml_account_idp_map_; |
159 | 162 |
160 DISALLOW_COPY_AND_ASSIGN(FakeGaia); | 163 DISALLOW_COPY_AND_ASSIGN(FakeGaia); |
161 }; | 164 }; |
162 | 165 |
163 #endif // GOOGLE_APIS_GAIA_FAKE_GAIA_H_ | 166 #endif // GOOGLE_APIS_GAIA_FAKE_GAIA_H_ |
OLD | NEW |