diff options
author | dzhioev <dzhioev@chromium.org> | 2015-05-28 11:43:40 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-28 18:44:00 +0000 |
commit | 1e76fed394f8a90b049ce2c06ca06f677c899024 (patch) | |
tree | e143c7c3245af22e9dab44d8f88ad5e9a84b2911 /google_apis | |
parent | d2adf1e487ba54a15d92947ce29fbe18b8edd686 (diff) | |
download | chromium_src-1e76fed394f8a90b049ce2c06ca06f677c899024.zip chromium_src-1e76fed394f8a90b049ce2c06ca06f677c899024.tar.gz chromium_src-1e76fed394f8a90b049ce2c06ca06f677c899024.tar.bz2 |
Browser tests for the new way of handling device ID in Chrome OS.
BUG=486044,486136
TEST=browser_tests --gtest_filter=DeviceIDTest.*
Review URL: https://codereview.chromium.org/1141163002
Cr-Commit-Position: refs/heads/master@{#331828}
Diffstat (limited to 'google_apis')
-rw-r--r-- | google_apis/gaia/fake_gaia.cc | 55 | ||||
-rw-r--r-- | google_apis/gaia/fake_gaia.h | 21 |
2 files changed, 74 insertions, 2 deletions
diff --git a/google_apis/gaia/fake_gaia.cc b/google_apis/gaia/fake_gaia.cc index 02fccd1..88fb274 100644 --- a/google_apis/gaia/fake_gaia.cc +++ b/google_apis/gaia/fake_gaia.cc @@ -136,6 +136,25 @@ FakeGaia::MergeSessionParams::MergeSessionParams() { FakeGaia::MergeSessionParams::~MergeSessionParams() { } +void FakeGaia::MergeSessionParams::Update(const MergeSessionParams& update) { + // This lambda uses a pointer to data member to merge attributes. + auto maybe_update_field = + [this, &update](std::string MergeSessionParams::* field_ptr) { + if (!(update.*field_ptr).empty()) + this->*field_ptr = update.*field_ptr; + }; + + maybe_update_field(&MergeSessionParams::auth_sid_cookie); + maybe_update_field(&MergeSessionParams::auth_lsid_cookie); + maybe_update_field(&MergeSessionParams::auth_code); + maybe_update_field(&MergeSessionParams::refresh_token); + maybe_update_field(&MergeSessionParams::access_token); + maybe_update_field(&MergeSessionParams::gaia_uber_token); + maybe_update_field(&MergeSessionParams::session_sid_cookie); + maybe_update_field(&MergeSessionParams::session_lsid_cookie); + maybe_update_field(&MergeSessionParams::email); +} + FakeGaia::FakeGaia() : issue_oauth_code_cookie_(false) { base::FilePath source_root_dir; PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir); @@ -171,6 +190,10 @@ void FakeGaia::SetMergeSessionParams( merge_session_params_ = params; } +void FakeGaia::UpdateMergeSessionParams(const MergeSessionParams& params) { + merge_session_params_.Update(params); +} + void FakeGaia::MapEmailToGaiaId(const std::string& email, const std::string& gaia_id) { DCHECK(!email.empty()); @@ -180,7 +203,7 @@ void FakeGaia::MapEmailToGaiaId(const std::string& email, std::string FakeGaia::GetGaiaIdOfEmail(const std::string& email) const { DCHECK(!email.empty()); - auto it = email_to_gaia_id_map_.find(email); + const auto it = email_to_gaia_id_map_.find(email); return it == email_to_gaia_id_map_.end() ? std::string(kDefaultGaiaId) : it->second; } @@ -306,6 +329,18 @@ bool FakeGaia::GetQueryParameter(const std::string& query, return net::GetValueForKeyInQuery(query_url, key, value); } +std::string FakeGaia::GetDeviceIdByRefreshToken( + const std::string& refresh_token) const { + auto it = refresh_token_to_device_id_map_.find(refresh_token); + return it != refresh_token_to_device_id_map_.end() ? it->second + : std::string(); +} + +void FakeGaia::SetRefreshTokenToDeviceIdMap( + const RefreshTokenToDeviceIdMap& refresh_token_to_device_id_map) { + refresh_token_to_device_id_map_ = refresh_token_to_device_id_map; +} + void FakeGaia::HandleMergeSession(const HttpRequest& request, BasicHttpResponse* http_response) { http_response->set_code(net::HTTP_UNAUTHORIZED); @@ -602,9 +637,27 @@ void FakeGaia::HandleAuthToken(const HttpRequest& request, return; } + std::string device_id; + if (GetQueryParameter(request.content, "device_id", &device_id)) { + std::string device_type; + if (!GetQueryParameter(request.content, "device_type", &device_type)) { + http_response->set_code(net::HTTP_BAD_REQUEST); + LOG(ERROR) << "'device_type' should be set if 'device_id' is set."; + return; + } + if (device_type != "chrome") { + http_response->set_code(net::HTTP_BAD_REQUEST); + LOG(ERROR) << "'device_type' is not 'chrome'."; + return; + } + } + base::DictionaryValue response_dict; response_dict.SetString("refresh_token", merge_session_params_.refresh_token); + if (!device_id.empty()) + refresh_token_to_device_id_map_[merge_session_params_.refresh_token] = + device_id; response_dict.SetString("access_token", merge_session_params_.access_token); response_dict.SetInteger("expires_in", 3600); diff --git a/google_apis/gaia/fake_gaia.h b/google_apis/gaia/fake_gaia.h index e50b7cb..1f1a3ef 100644 --- a/google_apis/gaia/fake_gaia.h +++ b/google_apis/gaia/fake_gaia.h @@ -31,7 +31,8 @@ class HttpResponse; // be registered as an additional request handler. class FakeGaia { public: - typedef std::set<std::string> ScopeSet; + using ScopeSet = std::set<std::string>; + using RefreshTokenToDeviceIdMap = std::map<std::string, std::string>; // Access token details used for token minting and the token info endpoint. struct AccessTokenInfo { @@ -52,6 +53,9 @@ class FakeGaia { MergeSessionParams(); ~MergeSessionParams(); + // Updates params with non-empty values from |params|. + void Update(const MergeSessionParams& params); + // 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; @@ -86,6 +90,9 @@ class FakeGaia { // Sets the initial value of tokens and cookies. void SetMergeSessionParams(const MergeSessionParams& params); + // Updates various params with non-empty values from |params|. + void UpdateMergeSessionParams(const MergeSessionParams& params); + // Sets the specified |gaia_id| as corresponding to the given |email| // address when setting GAIA response headers. If no mapping is given for // an email address, a default GAIA Id is used. @@ -122,6 +129,17 @@ class FakeGaia { static bool GetQueryParameter(const std::string& query, const std::string& key, std::string* value); + + // Returns a device ID associated with a given |refresh_token|. + std::string GetDeviceIdByRefreshToken(const std::string& refresh_token) const; + + void SetRefreshTokenToDeviceIdMap( + const RefreshTokenToDeviceIdMap& refresh_token_to_device_id_map); + + const RefreshTokenToDeviceIdMap& refresh_token_to_device_id_map() const { + return refresh_token_to_device_id_map_; + } + protected: // HTTP handler for /MergeSession. virtual void HandleMergeSession( @@ -210,6 +228,7 @@ class FakeGaia { std::string embedded_setup_chromeos_response_; SamlAccountIdpMap saml_account_idp_map_; bool issue_oauth_code_cookie_; + RefreshTokenToDeviceIdMap refresh_token_to_device_id_map_; DISALLOW_COPY_AND_ASSIGN(FakeGaia); }; |