diff options
Diffstat (limited to 'chromium/google_apis/gaia/fake_gaia.h')
-rw-r--r-- | chromium/google_apis/gaia/fake_gaia.h | 102 |
1 files changed, 92 insertions, 10 deletions
diff --git a/chromium/google_apis/gaia/fake_gaia.h b/chromium/google_apis/gaia/fake_gaia.h index de4201f7337..13a63e6b228 100644 --- a/chromium/google_apis/gaia/fake_gaia.h +++ b/chromium/google_apis/gaia/fake_gaia.h @@ -10,7 +10,9 @@ #include <string> #include "base/basictypes.h" +#include "base/callback.h" #include "base/memory/scoped_ptr.h" +#include "url/gurl.h" namespace base { class DictionaryValue; @@ -45,8 +47,44 @@ class FakeGaia { std::string email; }; + // Cookies and tokens for /MergeSession call seqeunce. + struct MergeSessionParams { + MergeSessionParams(); + ~MergeSessionParams(); + + // Values of SID and LSID cookie that are set by /ServiceLoginAuth or its + // equivalent at the end of the SAML login flow. + std::string auth_sid_cookie; + std::string auth_lsid_cookie; + + // auth_code cookie value response for /o/oauth2/programmatic_auth call. + std::string auth_code; + + // OAuth2 refresh and access token generated by /o/oauth2/token call + // with "...&grant_type=authorization_code". + std::string refresh_token; + std::string access_token; + + // Uber token response from /OAuthLogin call. + std::string gaia_uber_token; + + // Values of SID and LSID cookie generated from /MergeSession call. + std::string session_sid_cookie; + std::string session_lsid_cookie; + + // The e-mail address returned by /ListAccounts. + std::string email; + }; + FakeGaia(); - ~FakeGaia(); + virtual ~FakeGaia(); + + // Sets the initial value of tokens and cookies. + void SetMergeSessionParams(const MergeSessionParams& params); + + // Initializes HTTP request handlers. Should be called after switches + // for tweaking GaiaUrls are in place. + void Initialize(); // Handles a request and returns a response if the request was recognized as a // GAIA request. Note that this respects the switches::kGaiaUrl and friends so @@ -61,30 +99,74 @@ class FakeGaia { void IssueOAuthToken(const std::string& auth_token, const AccessTokenInfo& token_info); + // Associates an account id with a SAML IdP redirect endpoint. When a + // /ServiceLoginAuth request comes in for that user, it will be redirected + // to the associated redirect endpoint. + void RegisterSamlUser(const std::string& account_id, const GURL& saml_idp); + + // Extracts the parameter named |key| from |query| and places it in |value|. + // Returns false if no parameter is found. + static bool GetQueryParameter(const std::string& query, + const std::string& key, + std::string* value); + protected: + // HTTP handler for /MergeSession. + virtual void HandleMergeSession( + const net::test_server::HttpRequest& request, + net::test_server::BasicHttpResponse* http_response); + private: typedef std::multimap<std::string, AccessTokenInfo> AccessTokenInfoMap; + typedef std::map<std::string, GURL> SamlAccountIdpMap; // Formats a JSON response with the data in |response_dict|. void FormatJSONResponse(const base::DictionaryValue& response_dict, net::test_server::BasicHttpResponse* http_response); + typedef base::Callback<void( + const net::test_server::HttpRequest& request, + net::test_server::BasicHttpResponse* http_response)> + HttpRequestHandlerCallback; + typedef std::map<std::string, HttpRequestHandlerCallback> RequestHandlerMap; + + // HTTP request handlers. + void HandleProgramaticAuth( + const net::test_server::HttpRequest& request, + net::test_server::BasicHttpResponse* http_response); + void HandleServiceLogin(const net::test_server::HttpRequest& request, + net::test_server::BasicHttpResponse* http_response); + void HandleOAuthLogin(const net::test_server::HttpRequest& request, + net::test_server::BasicHttpResponse* http_response); + void HandleServiceLoginAuth( + const net::test_server::HttpRequest& request, + net::test_server::BasicHttpResponse* http_response); + void HandleSSO(const net::test_server::HttpRequest& request, + net::test_server::BasicHttpResponse* http_response); + void HandleAuthToken(const net::test_server::HttpRequest& request, + net::test_server::BasicHttpResponse* http_response); + void HandleTokenInfo(const net::test_server::HttpRequest& request, + net::test_server::BasicHttpResponse* http_response); + void HandleIssueToken(const net::test_server::HttpRequest& request, + net::test_server::BasicHttpResponse* http_response); + void HandleListAccounts(const net::test_server::HttpRequest& request, + net::test_server::BasicHttpResponse* http_response); + void HandlePeopleGet(const net::test_server::HttpRequest& request, + net::test_server::BasicHttpResponse* http_response); + // Returns the access token associated with |auth_token| that matches the // given |client_id| and |scope_string|. If |scope_string| is empty, the first // token satisfying the other criteria is returned. Returns NULL if no token // matches. - const AccessTokenInfo* GetAccessTokenInfo(const std::string& auth_token, - const std::string& client_id, - const std::string& scope_string) + const AccessTokenInfo* FindAccessTokenInfo(const std::string& auth_token, + const std::string& client_id, + const std::string& scope_string) const; - // Extracts the parameter named |key| from |query| and places it in |value|. - // Returns false if no parameter is found. - static bool GetQueryParameter(const std::string& query, - const std::string& key, - std::string* value); - + MergeSessionParams merge_session_params_; AccessTokenInfoMap access_token_info_map_; + RequestHandlerMap request_handlers_; std::string service_login_response_; + SamlAccountIdpMap saml_account_idp_map_; DISALLOW_COPY_AND_ASSIGN(FakeGaia); }; |