diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/google_apis | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/google_apis')
21 files changed, 765 insertions, 105 deletions
diff --git a/chromium/google_apis/BUILD.gn b/chromium/google_apis/BUILD.gn index 09b612271f6..605d4ec4fad 100644 --- a/chromium/google_apis/BUILD.gn +++ b/chromium/google_apis/BUILD.gn @@ -213,6 +213,7 @@ test("google_apis_unittests") { "gaia/gaia_auth_fetcher_unittest.cc", "gaia/gaia_auth_util_unittest.cc", "gaia/gaia_oauth_client_unittest.cc", + "gaia/gaia_urls_unittest.cc", "gaia/google_service_auth_error_unittest.cc", "gaia/oauth2_access_token_fetcher_impl_unittest.cc", "gaia/oauth2_access_token_manager_unittest.cc", @@ -225,8 +226,6 @@ test("google_apis_unittests") { "google_api_keys_unittest.h", ] - data = [ "test/" ] - configs += [ ":key_defines" ] deps = [ @@ -241,6 +240,12 @@ test("google_apis_unittests") { "//testing/gtest", ] + if (is_ios) { + deps += [ ":google_apis_unittest_bundle_data" ] + } else { + data = [ "test/" ] + } + if (enable_extensions) { deps += [ "//google_apis/drive:drive_unittests" ] } @@ -253,3 +258,19 @@ test("google_apis_unittests") { deps += [ "//third_party/ocmock" ] } } + +bundle_data("google_apis_unittest_bundle_data") { + testonly = true + sources = [ + "test/data/gaia/all_base_urls.json", + "test/data/gaia/all_urls.json", + "test/data/gaia/bad_url.json", + "test/data/gaia/bad_url_key.json", + "test/data/gaia/bad_urls_key.json", + "test/data/gaia/not_a_json.txt", + "test/data/gaia/one_base_url.json", + "test/data/gaia/one_url.json", + ] + outputs = [ "{{bundle_resources_dir}}/" + + "{{source_root_relative_dir}}/{{source_file_part}}" ] +} diff --git a/chromium/google_apis/build/OWNERS b/chromium/google_apis/build/OWNERS deleted file mode 100644 index ab5f1ae7220..00000000000 --- a/chromium/google_apis/build/OWNERS +++ /dev/null @@ -1 +0,0 @@ -# COMPONENT: Build diff --git a/chromium/google_apis/drive/base_requests.cc b/chromium/google_apis/drive/base_requests.cc index 5523b8afb5b..f71d9233ce5 100644 --- a/chromium/google_apis/drive/base_requests.cc +++ b/chromium/google_apis/drive/base_requests.cc @@ -175,13 +175,9 @@ void CloseFile(base::File file) {} namespace google_apis { std::unique_ptr<base::Value> ParseJson(const std::string& json) { - int error_code = -1; - std::string error_message; - std::unique_ptr<base::Value> value = - base::JSONReader::ReadAndReturnErrorDeprecated( - json, base::JSON_PARSE_RFC, &error_code, &error_message); - - if (!value.get()) { + base::JSONReader::ValueWithError parsed_json = + base::JSONReader::ReadAndReturnValueWithError(json); + if (!parsed_json.value) { std::string trimmed_json; if (json.size() < 80) { trimmed_json = json; @@ -192,10 +188,12 @@ std::unique_ptr<base::Value> ParseJson(const std::string& json) { base::NumberToString(json.size() - 60).c_str(), json.substr(json.size() - 10).c_str()); } - LOG(WARNING) << "Error while parsing entry response: " << error_message - << ", code: " << error_code << ", json:\n" << trimmed_json; + LOG(WARNING) << "Error while parsing entry response: " + << parsed_json.error_message << ", json:\n" + << trimmed_json; + return nullptr; } - return value; + return base::Value::ToUniquePtrValue(std::move(*parsed_json.value)); } void GenerateMultipartBody(MultipartType multipart_type, diff --git a/chromium/google_apis/gaia/gaia_auth_fetcher.cc b/chromium/google_apis/gaia/gaia_auth_fetcher.cc index 15752eb9c45..3131c0581f8 100644 --- a/chromium/google_apis/gaia/gaia_auth_fetcher.cc +++ b/chromium/google_apis/gaia/gaia_auth_fetcher.cc @@ -803,7 +803,7 @@ void GaiaAuthFetcher::StartOAuthMultilogin( std::string source_string = net::EscapeUrlEncodedData(source_, true); std::string parameters = base::StringPrintf( - "?source=%s&mlreuse=%i", source_string.c_str(), + "?source=%s&reuseCookies=%i", source_string.c_str(), mode == gaia::MultiloginMode::MULTILOGIN_PRESERVE_COOKIE_ACCOUNTS_ORDER ? 1 : 0); diff --git a/chromium/google_apis/gaia/gaia_auth_fetcher_unittest.cc b/chromium/google_apis/gaia/gaia_auth_fetcher_unittest.cc index 8b1c0139975..1b6d6d9a0b9 100644 --- a/chromium/google_apis/gaia/gaia_auth_fetcher_unittest.cc +++ b/chromium/google_apis/gaia/gaia_auth_fetcher_unittest.cc @@ -355,7 +355,7 @@ TEST_F(GaiaAuthFetcherTest, MultiloginRequestFormat) { std::string header; request0.headers.GetHeader("Authorization", &header); EXPECT_EQ("MultiBearer id1:token1,id2:token2", header); - EXPECT_EQ("source=ChromiumBrowser&mlreuse=0&externalCcResult=cc_result", + EXPECT_EQ("source=ChromiumBrowser&reuseCookies=0&externalCcResult=cc_result", request0.url.query()); auth.TestOnURLLoadCompleteInternal(net::OK, net::HTTP_OK, std::string()); @@ -367,7 +367,7 @@ TEST_F(GaiaAuthFetcherTest, MultiloginRequestFormat) { ASSERT_TRUE(auth.HasPendingFetch()); const network::ResourceRequest& request1 = received_requests_.at(1); - EXPECT_EQ("source=ChromiumBrowser&mlreuse=1&externalCcResult=cc_result", + EXPECT_EQ("source=ChromiumBrowser&reuseCookies=1&externalCcResult=cc_result", request1.url.query()); } diff --git a/chromium/google_apis/gaia/gaia_constants.cc b/chromium/google_apis/gaia/gaia_constants.cc index 5e8847a2dba..01c25d1d479 100644 --- a/chromium/google_apis/gaia/gaia_constants.cc +++ b/chromium/google_apis/gaia/gaia_constants.cc @@ -79,6 +79,9 @@ const char kClearCutOAuth2Scope[] = "https://www.googleapis.com/auth/cclog"; const char kFCMOAuthScope[] = "https://www.googleapis.com/auth/firebase.messaging"; +// OAuth scope for access to Tachyon api. +const char kTachyonOAuthScope[] = "https://www.googleapis.com/auth/tachyon"; + // Used to mint uber auth tokens when needed. const char kGaiaSid[] = "sid"; const char kGaiaLsid[] = "lsid"; diff --git a/chromium/google_apis/gaia/gaia_constants.h b/chromium/google_apis/gaia/gaia_constants.h index c6ee1bf1494..b225cfed6ac 100644 --- a/chromium/google_apis/gaia/gaia_constants.h +++ b/chromium/google_apis/gaia/gaia_constants.h @@ -39,6 +39,7 @@ extern const char kAccountsReauthOAuth2Scope[]; extern const char kAuditRecordingOAuth2Scope[]; extern const char kClearCutOAuth2Scope[]; extern const char kFCMOAuthScope[]; +extern const char kTachyonOAuthScope[]; // Used with uber auth tokens when needed. extern const char kGaiaSid[]; diff --git a/chromium/google_apis/gaia/gaia_switches.cc b/chromium/google_apis/gaia/gaia_switches.cc index a376a0f8629..95faee35bb1 100644 --- a/chromium/google_apis/gaia/gaia_switches.cc +++ b/chromium/google_apis/gaia/gaia_switches.cc @@ -6,6 +6,7 @@ namespace switches { +const char kGaiaConfig[] = "gaia-config"; const char kGoogleUrl[] = "google-url"; const char kGaiaUrl[] = "gaia-url"; const char kGoogleApisUrl[] = "google-apis-url"; diff --git a/chromium/google_apis/gaia/gaia_switches.h b/chromium/google_apis/gaia/gaia_switches.h index 697387945d4..3ce1e3e64c5 100644 --- a/chromium/google_apis/gaia/gaia_switches.h +++ b/chromium/google_apis/gaia/gaia_switches.h @@ -7,6 +7,10 @@ namespace switches { +// Specifies the path to a config file containing GAIA urls. +// See "google_apis/test/data/gaia/all_urls.json" for a format example. +extern const char kGaiaConfig[]; + // Specifies the domain of the SAPISID cookie. The default value is // "http://.google.com". extern const char kGoogleUrl[]; diff --git a/chromium/google_apis/gaia/gaia_urls.cc b/chromium/google_apis/gaia/gaia_urls.cc index c3526692b92..a36389dec87 100644 --- a/chromium/google_apis/gaia/gaia_urls.cc +++ b/chromium/google_apis/gaia/gaia_urls.cc @@ -5,14 +5,23 @@ #include "google_apis/gaia/gaia_urls.h" #include "base/command_line.h" +#include "base/files/file_path.h" +#include "base/files/file_util.h" +#include "base/json/json_reader.h" #include "base/logging.h" +#include "base/strings/string_piece.h" #include "base/strings/stringprintf.h" +#include "base/values.h" #include "build/build_config.h" #include "google_apis/gaia/gaia_switches.h" #include "google_apis/google_api_keys.h" #include "url/url_canon.h" #include "url/url_constants.h" +#define CONCAT_HIDDEN(a, b) a##b +#define CONCAT(a, b) CONCAT_HIDDEN(a, b) +#define URL_KEY_AND_PTR(name) #name, &CONCAT(name, _) + namespace { // Gaia service constants @@ -73,19 +82,19 @@ const char kReAuthApiUrlSuffix[] = "reauth/v1beta/users/"; // API calls from oauthaccountmanager.googleapis.com const char kOAuth2IssueTokenUrlSuffix[] = "v1/issuetoken"; -void GetSwitchValueWithDefault(const char* switch_value, - const char* default_value, +void GetSwitchValueWithDefault(base::StringPiece switch_value, + base::StringPiece default_value, std::string* output_value) { base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); if (command_line->HasSwitch(switch_value)) { *output_value = command_line->GetSwitchValueASCII(switch_value); } else { - *output_value = default_value; + *output_value = default_value.as_string(); } } -GURL GetURLSwitchValueWithDefault(const char* switch_value, - const char* default_value) { +GURL GetURLSwitchValueWithDefault(base::StringPiece switch_value, + base::StringPiece default_value) { std::string string_value; GetSwitchValueWithDefault(switch_value, default_value, &string_value); const GURL result(string_value); @@ -97,6 +106,45 @@ GURL GetURLSwitchValueWithDefault(const char* switch_value, return GURL(default_value); } +void SetDefaultURLIfInvalid(GURL* url_to_set, + base::StringPiece switch_value, + base::StringPiece default_value) { + if (!url_to_set->is_valid()) { + *url_to_set = GetURLSwitchValueWithDefault(switch_value, default_value); + } +} + +void ResolveURLIfInvalid(GURL* url_to_set, + const GURL& base_url, + base::StringPiece suffix) { + if (!url_to_set->is_valid()) { + *url_to_set = base_url.Resolve(suffix); + } +} + +void InitializeUrlFromConfig(const base::Value& urls, + base::StringPiece key, + GURL* out_value) { + const base::Value* url_config = urls.FindDictKey(key); + if (!url_config) + return; + + const std::string* url_string = url_config->FindStringKey("url"); + if (!url_string) { + LOG(ERROR) << "Incorrect format of \"" << key + << "\" gaia config key. A key should contain {\"url\": " + "\"https://...\"} dictionary."; + return; + } + + GURL url = GURL(*url_string); + if (!url.is_valid()) { + LOG(ERROR) << "Invalid URL at \"" << key << "\" URL key"; + return; + } + + *out_value = url; +} } // namespace @@ -105,80 +153,19 @@ GaiaUrls* GaiaUrls::GetInstance() { } GaiaUrls::GaiaUrls() { - google_url_ = GetURLSwitchValueWithDefault(switches::kGoogleUrl, - kDefaultGoogleUrl); - url::Replacements<char> scheme_replacement; - scheme_replacement.SetScheme(url::kHttpsScheme, - url::Component(0, strlen(url::kHttpsScheme))); - secure_google_url_ = google_url_.ReplaceComponents(scheme_replacement); - gaia_url_ = GetURLSwitchValueWithDefault(switches::kGaiaUrl, kDefaultGaiaUrl); - GURL lso_origin_url = - GetURLSwitchValueWithDefault(switches::kLsoUrl, kDefaultGaiaUrl); - GURL google_apis_origin_url = GetURLSwitchValueWithDefault( - switches::kGoogleApisUrl, kDefaultGoogleApisBaseUrl); - GURL oauth_account_manager_origin_url = GetURLSwitchValueWithDefault( - switches::kOAuthAccountManagerUrl, kDefaultOAuthAccountManagerBaseUrl); - - captcha_base_url_ = - GURL("http://" + gaia_url_.host() + - (gaia_url_.has_port() ? ":" + gaia_url_.port() : "")); - - oauth2_chrome_client_id_ = - google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN); - oauth2_chrome_client_secret_ = - google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN); + // Initialize all urls from a config first. + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kGaiaConfig)) { + InitializeFromConfig( + command_line->GetSwitchValuePath(switches::kGaiaConfig)); + } - // URLs from accounts.google.com. - client_login_url_ = gaia_url_.Resolve(kClientLoginUrlSuffix); - service_login_url_ = gaia_url_.Resolve(kServiceLoginUrlSuffix); - embedded_setup_chromeos_url_v2_ = - gaia_url_.Resolve(kEmbeddedSetupChromeOsUrlSuffixV2); - embedded_setup_windows_url_ = - gaia_url_.Resolve(kEmbeddedSetupWindowsUrlSuffix); - signin_chrome_sync_dice_ = gaia_url_.Resolve(kSigninChromeSyncDice); - signin_chrome_sync_keys_url_ = gaia_url_.Resolve(kSigninChromeSyncKeysUrl); - service_login_auth_url_ = gaia_url_.Resolve(kServiceLoginAuthUrlSuffix); - service_logout_url_ = gaia_url_.Resolve(kServiceLogoutUrlSuffix); - continue_url_for_logout_ = gaia_url_.Resolve(kContinueUrlForLogoutSuffix); - get_user_info_url_ = gaia_url_.Resolve(kGetUserInfoUrlSuffix); - token_auth_url_ = gaia_url_.Resolve(kTokenAuthUrlSuffix); - merge_session_url_ = gaia_url_.Resolve(kMergeSessionUrlSuffix); - oauth_multilogin_url_ = gaia_url_.Resolve(kOAuthMultiloginSuffix); - oauth_get_access_token_url_ = - gaia_url_.Resolve(kOAuthGetAccessTokenUrlSuffix); - oauth_wrap_bridge_url_ = gaia_url_.Resolve(kOAuthWrapBridgeUrlSuffix); - oauth_revoke_token_url_ = gaia_url_.Resolve(kOAuthRevokeTokenUrlSuffix); - oauth1_login_url_ = gaia_url_.Resolve(kOAuth1LoginUrlSuffix); - list_accounts_url_ = gaia_url_.Resolve(kListAccountsSuffix); - embedded_signin_url_ = gaia_url_.Resolve(kEmbeddedSigninSuffix); - add_account_url_ = gaia_url_.Resolve(kAddAccountSuffix); - reauth_url_ = gaia_url_.Resolve(kReauthSuffix); - get_check_connection_info_url_ = - gaia_url_.Resolve(kGetCheckConnectionInfoSuffix); - - // URLs from accounts.google.com (LSO). - get_oauth_token_url_ = lso_origin_url.Resolve(kGetOAuthTokenUrlSuffix); - oauth2_auth_url_ = lso_origin_url.Resolve(kOAuth2AuthUrlSuffix); - oauth2_revoke_url_ = lso_origin_url.Resolve(kOAuth2RevokeUrlSuffix); - - // URLs from www.googleapis.com. - oauth2_token_url_ = google_apis_origin_url.Resolve(kOAuth2TokenUrlSuffix); - oauth2_token_info_url_ = - google_apis_origin_url.Resolve(kOAuth2TokenInfoUrlSuffix); - oauth_user_info_url_ = - google_apis_origin_url.Resolve(kOAuthUserInfoUrlSuffix); - reauth_api_url_ = google_apis_origin_url.Resolve(kReAuthApiUrlSuffix); - - // URLs from oauthaccountmanager.googleapis.com/v1/issuetoken - oauth2_issue_token_url_ = - oauth_account_manager_origin_url.Resolve(kOAuth2IssueTokenUrlSuffix); - - gaia_login_form_realm_ = gaia_url_; -} - -GaiaUrls::~GaiaUrls() { + // Set a default value for all urls not set by the config. + InitializeDefault(); } +GaiaUrls::~GaiaUrls() = default; + const GURL& GaiaUrls::google_url() const { return google_url_; } @@ -321,10 +308,8 @@ GURL GaiaUrls::ListAccountsURLWithSource(const std::string& source) { return list_accounts_url_; } else { std::string query = list_accounts_url_.query(); - return list_accounts_url_.Resolve( - base::StringPrintf("?gpsia=1&source=%s&%s", - source.c_str(), - query.c_str())); + return list_accounts_url_.Resolve(base::StringPrintf( + "?gpsia=1&source=%s&%s", source.c_str(), query.c_str())); } } @@ -339,8 +324,162 @@ GURL GaiaUrls::LogOutURLWithSource(const std::string& source) { } GURL GaiaUrls::GetCheckConnectionInfoURLWithSource(const std::string& source) { - return source.empty() - ? get_check_connection_info_url_ - : get_check_connection_info_url_.Resolve( - base::StringPrintf("?source=%s", source.c_str())); + return source.empty() ? get_check_connection_info_url_ + : get_check_connection_info_url_.Resolve( + base::StringPrintf("?source=%s", source.c_str())); +} + +void GaiaUrls::InitializeDefault() { + SetDefaultURLIfInvalid(&google_url_, switches::kGoogleUrl, kDefaultGoogleUrl); + SetDefaultURLIfInvalid(&gaia_url_, switches::kGaiaUrl, kDefaultGaiaUrl); + SetDefaultURLIfInvalid(&lso_origin_url_, switches::kLsoUrl, kDefaultGaiaUrl); + SetDefaultURLIfInvalid(&google_apis_origin_url_, switches::kGoogleApisUrl, + kDefaultGoogleApisBaseUrl); + SetDefaultURLIfInvalid(&oauth_account_manager_origin_url_, + switches::kOAuthAccountManagerUrl, + kDefaultOAuthAccountManagerBaseUrl); + if (!secure_google_url_.is_valid()) { + url::Replacements<char> scheme_replacement; + scheme_replacement.SetScheme(url::kHttpsScheme, + url::Component(0, strlen(url::kHttpsScheme))); + secure_google_url_ = google_url_.ReplaceComponents(scheme_replacement); + } + if (!captcha_base_url_.is_valid()) { + captcha_base_url_ = + GURL("http://" + gaia_url_.host() + + (gaia_url_.has_port() ? ":" + gaia_url_.port() : "")); + } + + oauth2_chrome_client_id_ = + google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN); + oauth2_chrome_client_secret_ = + google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN); + + // URLs from |gaia_url_|. + ResolveURLIfInvalid(&client_login_url_, gaia_url_, kClientLoginUrlSuffix); + ResolveURLIfInvalid(&service_login_url_, gaia_url_, kServiceLoginUrlSuffix); + ResolveURLIfInvalid(&embedded_setup_chromeos_url_v2_, gaia_url_, + kEmbeddedSetupChromeOsUrlSuffixV2); + ResolveURLIfInvalid(&embedded_setup_windows_url_, gaia_url_, + kEmbeddedSetupWindowsUrlSuffix); + ResolveURLIfInvalid(&signin_chrome_sync_dice_, gaia_url_, + kSigninChromeSyncDice); + ResolveURLIfInvalid(&signin_chrome_sync_keys_url_, gaia_url_, + kSigninChromeSyncKeysUrl); + ResolveURLIfInvalid(&service_login_auth_url_, gaia_url_, + kServiceLoginAuthUrlSuffix); + ResolveURLIfInvalid(&service_logout_url_, gaia_url_, kServiceLogoutUrlSuffix); + ResolveURLIfInvalid(&continue_url_for_logout_, gaia_url_, + kContinueUrlForLogoutSuffix); + ResolveURLIfInvalid(&get_user_info_url_, gaia_url_, kGetUserInfoUrlSuffix); + ResolveURLIfInvalid(&token_auth_url_, gaia_url_, kTokenAuthUrlSuffix); + ResolveURLIfInvalid(&merge_session_url_, gaia_url_, kMergeSessionUrlSuffix); + ResolveURLIfInvalid(&oauth_multilogin_url_, gaia_url_, + kOAuthMultiloginSuffix); + ResolveURLIfInvalid(&oauth_get_access_token_url_, gaia_url_, + kOAuthGetAccessTokenUrlSuffix); + ResolveURLIfInvalid(&oauth_wrap_bridge_url_, gaia_url_, + kOAuthWrapBridgeUrlSuffix); + ResolveURLIfInvalid(&oauth_revoke_token_url_, gaia_url_, + kOAuthRevokeTokenUrlSuffix); + ResolveURLIfInvalid(&oauth1_login_url_, gaia_url_, kOAuth1LoginUrlSuffix); + ResolveURLIfInvalid(&list_accounts_url_, gaia_url_, kListAccountsSuffix); + ResolveURLIfInvalid(&embedded_signin_url_, gaia_url_, kEmbeddedSigninSuffix); + ResolveURLIfInvalid(&add_account_url_, gaia_url_, kAddAccountSuffix); + ResolveURLIfInvalid(&reauth_url_, gaia_url_, kReauthSuffix); + ResolveURLIfInvalid(&get_check_connection_info_url_, gaia_url_, + kGetCheckConnectionInfoSuffix); + if (!gaia_login_form_realm_.is_valid()) { + gaia_login_form_realm_ = gaia_url_; + } + + // URLs from |lso_origin_url_|. + ResolveURLIfInvalid(&get_oauth_token_url_, lso_origin_url_, + kGetOAuthTokenUrlSuffix); + ResolveURLIfInvalid(&oauth2_auth_url_, lso_origin_url_, kOAuth2AuthUrlSuffix); + ResolveURLIfInvalid(&oauth2_revoke_url_, lso_origin_url_, + kOAuth2RevokeUrlSuffix); + + // URLs from |google_apis_origin_url_|. + ResolveURLIfInvalid(&oauth2_token_url_, google_apis_origin_url_, + kOAuth2TokenUrlSuffix); + ResolveURLIfInvalid(&oauth2_token_info_url_, google_apis_origin_url_, + kOAuth2TokenInfoUrlSuffix); + ResolveURLIfInvalid(&oauth_user_info_url_, google_apis_origin_url_, + kOAuthUserInfoUrlSuffix); + ResolveURLIfInvalid(&reauth_api_url_, google_apis_origin_url_, + kReAuthApiUrlSuffix); + + // URLs from |oauth_account_manager_origin_url_|. + ResolveURLIfInvalid(&oauth2_issue_token_url_, + oauth_account_manager_origin_url_, + kOAuth2IssueTokenUrlSuffix); +} + +void GaiaUrls::InitializeFromConfig(const base::FilePath& config_path) { + std::string config_contents; + if (!base::ReadFileToString(config_path, &config_contents)) { + LOG(ERROR) << "Couldn't read gaia config file " << config_path; + return; + } + + base::Optional<base::Value> dict = base::JSONReader::Read(config_contents); + if (!dict || !dict->is_dict()) { + LOG(ERROR) << "Couldn't parse gaia config file " << config_path; + return; + } + + const base::Value* url_dict = dict->FindDictKey("urls"); + if (!url_dict) { + LOG(ERROR) << "Incorrect format of gaia config file. A config should " + "contain {\"urls\": {...}} dictionary."; + return; + } + + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(google_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(secure_google_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(gaia_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(lso_origin_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(google_apis_origin_url)); + InitializeUrlFromConfig(*url_dict, + URL_KEY_AND_PTR(oauth_account_manager_origin_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(captcha_base_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(client_login_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(service_login_url)); + InitializeUrlFromConfig(*url_dict, + URL_KEY_AND_PTR(embedded_setup_chromeos_url_v2)); + InitializeUrlFromConfig(*url_dict, + URL_KEY_AND_PTR(embedded_setup_windows_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(signin_chrome_sync_dice)); + InitializeUrlFromConfig(*url_dict, + URL_KEY_AND_PTR(signin_chrome_sync_keys_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(service_login_auth_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(service_logout_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(continue_url_for_logout)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(get_user_info_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(token_auth_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(merge_session_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(get_oauth_token_url)); + InitializeUrlFromConfig(*url_dict, + URL_KEY_AND_PTR(oauth_get_access_token_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(oauth_wrap_bridge_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(oauth_multilogin_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(oauth_user_info_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(oauth_revoke_token_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(oauth1_login_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(list_accounts_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(embedded_signin_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(add_account_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(reauth_url)); + InitializeUrlFromConfig(*url_dict, + URL_KEY_AND_PTR(get_check_connection_info_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(oauth2_auth_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(oauth2_token_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(oauth2_issue_token_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(oauth2_token_info_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(oauth2_revoke_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(reauth_api_url)); + InitializeUrlFromConfig(*url_dict, URL_KEY_AND_PTR(gaia_login_form_realm)); + + // TODO(crbug.com/1072731): add OAuth Client ID and secret. } diff --git a/chromium/google_apis/gaia/gaia_urls.h b/chromium/google_apis/gaia/gaia_urls.h index df83e08caf3..eedd350feb1 100644 --- a/chromium/google_apis/gaia/gaia_urls.h +++ b/chromium/google_apis/gaia/gaia_urls.h @@ -11,7 +11,13 @@ #include "base/memory/singleton.h" #include "url/gurl.h" +namespace base { +class FilePath; +} // namespace base + // A signleton that provides all the URLs that are used for connecting to GAIA. +// +// Please update InitializeFromConfig() when adding new URLs. class GaiaUrls { public: static GaiaUrls* GetInstance(); @@ -63,12 +69,20 @@ class GaiaUrls { ~GaiaUrls(); friend struct base::DefaultSingletonTraits<GaiaUrls>; + friend class GaiaUrlsTest; + + void InitializeDefault(); + void InitializeFromConfig(const base::FilePath& config_path); GURL google_url_; GURL secure_google_url_; GURL gaia_url_; GURL captcha_base_url_; + GURL lso_origin_url_; + GURL google_apis_origin_url_; + GURL oauth_account_manager_origin_url_; + GURL client_login_url_; GURL service_login_url_; GURL embedded_setup_chromeos_url_v2_; diff --git a/chromium/google_apis/gaia/gaia_urls_unittest.cc b/chromium/google_apis/gaia/gaia_urls_unittest.cc new file mode 100644 index 00000000000..12545ef5990 --- /dev/null +++ b/chromium/google_apis/gaia/gaia_urls_unittest.cc @@ -0,0 +1,455 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "google_apis/gaia/gaia_urls.h" + +#include "base/base_paths.h" +#include "base/command_line.h" +#include "base/files/file_path.h" +#include "base/memory/ptr_util.h" +#include "base/path_service.h" +#include "base/test/scoped_command_line.h" +#include "build/build_config.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" + +namespace { +#if defined(OS_ANDROID) +const char kSigninChromeSyncKeysPlatformSuffix[] = "android"; +#elif defined(OS_IOS) +const char kSigninChromeSyncKeysPlatformSuffix[] = "ios"; +#elif defined(OS_CHROMEOS) +const char kSigninChromeSyncKeysPlatformSuffix[] = "chromeos"; +#else +const char kSigninChromeSyncKeysPlatformSuffix[] = "desktop"; +#endif + +base::FilePath GetTestFilePath(const std::string& relative_path) { + base::FilePath path; + if (!base::PathService::Get(base::DIR_SOURCE_ROOT, &path)) + return base::FilePath(); + return path.AppendASCII("google_apis") + .AppendASCII("test") + .AppendASCII("data") + .AppendASCII("gaia") + .AppendASCII(relative_path); +} +} // namespace + +class GaiaUrlsTest : public ::testing::Test { + public: + GaiaUrlsTest() = default; + ~GaiaUrlsTest() override { delete gaia_urls_; } + + // Lazily constructs |gaia_urls_|. + GaiaUrls* gaia_urls() { + if (!gaia_urls_) + gaia_urls_ = new GaiaUrls(); + return gaia_urls_; + } + + private: + // GaiaUrls must be constructed after command line parameters are overridden. + // GaiaUrls cannot be put into std::unique_ptr<> because ~GaiaUrls() is + // private. Thus, the owning raw pointer is used. + GaiaUrls* gaia_urls_ = nullptr; +}; + +TEST_F(GaiaUrlsTest, InitializeDefault_AllUrls) { + EXPECT_EQ(gaia_urls()->google_url().spec(), "http://google.com/"); + EXPECT_EQ(gaia_urls()->secure_google_url().spec(), "https://google.com/"); + EXPECT_EQ(gaia_urls()->gaia_url().spec(), "https://accounts.google.com/"); + EXPECT_EQ(gaia_urls()->captcha_base_url().spec(), + "http://accounts.google.com/"); + EXPECT_EQ(gaia_urls()->client_login_url().spec(), + "https://accounts.google.com/ClientLogin"); + EXPECT_EQ(gaia_urls()->service_login_url().spec(), + "https://accounts.google.com/ServiceLogin"); + EXPECT_EQ(gaia_urls()->embedded_setup_chromeos_url(2U).spec(), + "https://accounts.google.com/embedded/setup/v2/chromeos"); + EXPECT_EQ(gaia_urls()->embedded_setup_windows_url().spec(), + "https://accounts.google.com/embedded/setup/windows"); + EXPECT_EQ(gaia_urls()->signin_chrome_sync_dice().spec(), + "https://accounts.google.com/signin/chrome/sync?ssp=1"); + EXPECT_EQ(gaia_urls()->signin_chrome_sync_keys_url().spec(), + std::string("https://accounts.google.com/encryption/unlock/") + + kSigninChromeSyncKeysPlatformSuffix); + EXPECT_EQ(gaia_urls()->service_login_auth_url().spec(), + "https://accounts.google.com/ServiceLoginAuth"); + EXPECT_EQ(gaia_urls()->service_logout_url().spec(), + "https://accounts.google.com/Logout"); + EXPECT_EQ(gaia_urls()->LogOutURLWithSource("").spec(), + "https://accounts.google.com/Logout?continue=https://" + "accounts.google.com/chrome/blank.html"); + EXPECT_EQ(gaia_urls()->get_user_info_url().spec(), + "https://accounts.google.com/GetUserInfo"); + EXPECT_EQ(gaia_urls()->token_auth_url().spec(), + "https://accounts.google.com/TokenAuth"); + EXPECT_EQ(gaia_urls()->merge_session_url().spec(), + "https://accounts.google.com/MergeSession"); + EXPECT_EQ(gaia_urls()->get_oauth_token_url().spec(), + "https://accounts.google.com/o/oauth/GetOAuthToken/"); + EXPECT_EQ(gaia_urls()->oauth_get_access_token_url().spec(), + "https://accounts.google.com/OAuthGetAccessToken"); + EXPECT_EQ(gaia_urls()->oauth_wrap_bridge_url().spec(), + "https://accounts.google.com/OAuthWrapBridge"); + EXPECT_EQ(gaia_urls()->oauth_multilogin_url().spec(), + "https://accounts.google.com/oauth/multilogin"); + EXPECT_EQ(gaia_urls()->oauth_user_info_url().spec(), + "https://www.googleapis.com/oauth2/v1/userinfo"); + EXPECT_EQ(gaia_urls()->oauth_revoke_token_url().spec(), + "https://accounts.google.com/AuthSubRevokeToken"); + EXPECT_EQ(gaia_urls()->oauth1_login_url().spec(), + "https://accounts.google.com/OAuthLogin"); + EXPECT_EQ(gaia_urls()->ListAccountsURLWithSource("").spec(), + "https://accounts.google.com/ListAccounts?json=standard"); + EXPECT_EQ(gaia_urls()->embedded_signin_url().spec(), + "https://accounts.google.com/embedded/setup/chrome/usermenu"); + EXPECT_EQ(gaia_urls()->add_account_url().spec(), + "https://accounts.google.com/AddSession"); + EXPECT_EQ(gaia_urls()->reauth_url().spec(), + "https://accounts.google.com/embedded/xreauth/chrome"); + EXPECT_EQ(gaia_urls()->GetCheckConnectionInfoURLWithSource("").spec(), + "https://accounts.google.com/GetCheckConnectionInfo"); + EXPECT_EQ(gaia_urls()->oauth2_auth_url().spec(), + "https://accounts.google.com/o/oauth2/auth"); + EXPECT_EQ(gaia_urls()->oauth2_token_url().spec(), + "https://www.googleapis.com/oauth2/v4/token"); + EXPECT_EQ(gaia_urls()->oauth2_issue_token_url().spec(), + "https://oauthaccountmanager.googleapis.com/v1/issuetoken"); + EXPECT_EQ(gaia_urls()->oauth2_token_info_url().spec(), + "https://www.googleapis.com/oauth2/v2/tokeninfo"); + EXPECT_EQ(gaia_urls()->oauth2_revoke_url().spec(), + "https://accounts.google.com/o/oauth2/revoke"); + EXPECT_EQ(gaia_urls()->reauth_api_url().spec(), + "https://www.googleapis.com/reauth/v1beta/users/"); + EXPECT_EQ(gaia_urls()->gaia_login_form_realm().spec(), + "https://accounts.google.com/"); +} + +TEST_F(GaiaUrlsTest, InitializeDefault_URLSwitches) { + base::test::ScopedCommandLine command_line; + command_line.GetProcessCommandLine()->AppendSwitchASCII( + "google-url", "http://test-google.com"); + command_line.GetProcessCommandLine()->AppendSwitchASCII( + "gaia-url", "https://test-gaia.com"); + command_line.GetProcessCommandLine()->AppendSwitchASCII( + "google-apis-url", "https://test-googleapis.com"); + command_line.GetProcessCommandLine()->AppendSwitchASCII( + "lso-url", "https://test-lso.com"); + command_line.GetProcessCommandLine()->AppendSwitchASCII( + "oauth-account-manager-url", "https://test-oauthaccountmanager.com"); + + EXPECT_EQ(gaia_urls()->google_url().spec(), "http://test-google.com/"); + EXPECT_EQ(gaia_urls()->secure_google_url().spec(), + "https://test-google.com/"); + EXPECT_EQ(gaia_urls()->gaia_url().spec(), "https://test-gaia.com/"); + EXPECT_EQ(gaia_urls()->captcha_base_url().spec(), "http://test-gaia.com/"); + EXPECT_EQ(gaia_urls()->client_login_url().spec(), + "https://test-gaia.com/ClientLogin"); + EXPECT_EQ(gaia_urls()->service_login_url().spec(), + "https://test-gaia.com/ServiceLogin"); + EXPECT_EQ(gaia_urls()->embedded_setup_chromeos_url(2U).spec(), + "https://test-gaia.com/embedded/setup/v2/chromeos"); + EXPECT_EQ(gaia_urls()->embedded_setup_windows_url().spec(), + "https://test-gaia.com/embedded/setup/windows"); + EXPECT_EQ(gaia_urls()->signin_chrome_sync_dice().spec(), + "https://test-gaia.com/signin/chrome/sync?ssp=1"); + EXPECT_EQ(gaia_urls()->signin_chrome_sync_keys_url().spec(), + std::string("https://test-gaia.com/encryption/unlock/") + + kSigninChromeSyncKeysPlatformSuffix); + EXPECT_EQ(gaia_urls()->service_login_auth_url().spec(), + "https://test-gaia.com/ServiceLoginAuth"); + EXPECT_EQ(gaia_urls()->service_logout_url().spec(), + "https://test-gaia.com/Logout"); + EXPECT_EQ(gaia_urls()->LogOutURLWithSource("").spec(), + "https://test-gaia.com/Logout?continue=https://" + "test-gaia.com/chrome/blank.html"); + EXPECT_EQ(gaia_urls()->get_user_info_url().spec(), + "https://test-gaia.com/GetUserInfo"); + EXPECT_EQ(gaia_urls()->token_auth_url().spec(), + "https://test-gaia.com/TokenAuth"); + EXPECT_EQ(gaia_urls()->merge_session_url().spec(), + "https://test-gaia.com/MergeSession"); + EXPECT_EQ(gaia_urls()->get_oauth_token_url().spec(), + "https://test-lso.com/o/oauth/GetOAuthToken/"); + EXPECT_EQ(gaia_urls()->oauth_get_access_token_url().spec(), + "https://test-gaia.com/OAuthGetAccessToken"); + EXPECT_EQ(gaia_urls()->oauth_wrap_bridge_url().spec(), + "https://test-gaia.com/OAuthWrapBridge"); + EXPECT_EQ(gaia_urls()->oauth_multilogin_url().spec(), + "https://test-gaia.com/oauth/multilogin"); + EXPECT_EQ(gaia_urls()->oauth_user_info_url().spec(), + "https://test-googleapis.com/oauth2/v1/userinfo"); + EXPECT_EQ(gaia_urls()->oauth_revoke_token_url().spec(), + "https://test-gaia.com/AuthSubRevokeToken"); + EXPECT_EQ(gaia_urls()->oauth1_login_url().spec(), + "https://test-gaia.com/OAuthLogin"); + EXPECT_EQ(gaia_urls()->ListAccountsURLWithSource("").spec(), + "https://test-gaia.com/ListAccounts?json=standard"); + EXPECT_EQ(gaia_urls()->embedded_signin_url().spec(), + "https://test-gaia.com/embedded/setup/chrome/usermenu"); + EXPECT_EQ(gaia_urls()->add_account_url().spec(), + "https://test-gaia.com/AddSession"); + EXPECT_EQ(gaia_urls()->reauth_url().spec(), + "https://test-gaia.com/embedded/xreauth/chrome"); + EXPECT_EQ(gaia_urls()->GetCheckConnectionInfoURLWithSource("").spec(), + "https://test-gaia.com/GetCheckConnectionInfo"); + EXPECT_EQ(gaia_urls()->oauth2_auth_url().spec(), + "https://test-lso.com/o/oauth2/auth"); + EXPECT_EQ(gaia_urls()->oauth2_token_url().spec(), + "https://test-googleapis.com/oauth2/v4/token"); + EXPECT_EQ(gaia_urls()->oauth2_issue_token_url().spec(), + "https://test-oauthaccountmanager.com/v1/issuetoken"); + EXPECT_EQ(gaia_urls()->oauth2_token_info_url().spec(), + "https://test-googleapis.com/oauth2/v2/tokeninfo"); + EXPECT_EQ(gaia_urls()->oauth2_revoke_url().spec(), + "https://test-lso.com/o/oauth2/revoke"); + EXPECT_EQ(gaia_urls()->reauth_api_url().spec(), + "https://test-googleapis.com/reauth/v1beta/users/"); + EXPECT_EQ(gaia_urls()->gaia_login_form_realm().spec(), + "https://test-gaia.com/"); +} + +TEST_F(GaiaUrlsTest, InitializeFromConfig_OneUrl) { + base::test::ScopedCommandLine command_line; + command_line.GetProcessCommandLine()->AppendSwitchPath( + "gaia-config", GetTestFilePath("one_url.json")); + + // A URL present in config should be set. + EXPECT_EQ(gaia_urls()->client_login_url().spec(), + "https://accounts.example.com/ExampleClientLogin"); + // All other URLs should have default values. + EXPECT_EQ(gaia_urls()->service_login_url().spec(), + "https://accounts.google.com/ServiceLogin"); +} + +TEST_F(GaiaUrlsTest, InitializeFromConfig_OneBaseUrl) { + base::test::ScopedCommandLine command_line; + command_line.GetProcessCommandLine()->AppendSwitchPath( + "gaia-config", GetTestFilePath("one_base_url.json")); + + // A base URL present in config should be set and should be use to compute all + // derived URLs with default suffixes. + EXPECT_EQ(gaia_urls()->gaia_url().spec(), "https://accounts.example.com/"); + EXPECT_EQ(gaia_urls()->client_login_url().spec(), + "https://accounts.example.com/ClientLogin"); + EXPECT_EQ(gaia_urls()->service_login_url().spec(), + "https://accounts.example.com/ServiceLogin"); + // All other URLs should have default values. + EXPECT_EQ(gaia_urls()->get_oauth_token_url().spec(), + "https://accounts.google.com/o/oauth/GetOAuthToken/"); +} + +TEST_F(GaiaUrlsTest, InitializeFromConfig_PrecedenceOverSwitches) { + base::test::ScopedCommandLine command_line; + command_line.GetProcessCommandLine()->AppendSwitchPath( + "gaia-config", GetTestFilePath("one_url.json")); + command_line.GetProcessCommandLine()->AppendSwitchASCII( + "gaia-url", "https://myaccounts.com"); + + // A URL present in config should be overridden. + EXPECT_EQ(gaia_urls()->client_login_url().spec(), + "https://accounts.example.com/ExampleClientLogin"); + // All other URLs should be computed according command line flags. + EXPECT_EQ(gaia_urls()->gaia_url().spec(), "https://myaccounts.com/"); + EXPECT_EQ(gaia_urls()->service_login_url().spec(), + "https://myaccounts.com/ServiceLogin"); +} + +TEST_F(GaiaUrlsTest, InitializeFromConfig_AllUrls) { + base::test::ScopedCommandLine command_line; + command_line.GetProcessCommandLine()->AppendSwitchPath( + "gaia-config", GetTestFilePath("all_urls.json")); + + EXPECT_EQ(gaia_urls()->google_url().spec(), "http://example.com/"); + EXPECT_EQ(gaia_urls()->secure_google_url().spec(), "https://example.com/"); + EXPECT_EQ(gaia_urls()->gaia_url().spec(), "https://accounts.example.com/"); + EXPECT_EQ(gaia_urls()->captcha_base_url().spec(), + "http://accounts.example.com/"); + EXPECT_EQ(gaia_urls()->client_login_url().spec(), + "https://accounts.example.com/ClientLogin"); + EXPECT_EQ(gaia_urls()->service_login_url().spec(), + "https://accounts.example.com/ServiceLogin"); + EXPECT_EQ(gaia_urls()->embedded_setup_chromeos_url(2U).spec(), + "https://accounts.example.com/embedded/setup/v2/chromeos"); + EXPECT_EQ(gaia_urls()->embedded_setup_windows_url().spec(), + "https://accounts.example.com/embedded/setup/windows"); + EXPECT_EQ(gaia_urls()->signin_chrome_sync_dice().spec(), + "https://accounts.example.com/signin/chrome/sync?ssp=1"); + EXPECT_EQ(gaia_urls()->signin_chrome_sync_keys_url().spec(), + "https://accounts.example.com/encryption/unlock/example-platform"); + EXPECT_EQ(gaia_urls()->service_login_auth_url().spec(), + "https://accounts.example.com/ServiceLoginAuth"); + EXPECT_EQ(gaia_urls()->service_logout_url().spec(), + "https://accounts.example.com/Logout"); + EXPECT_EQ(gaia_urls()->LogOutURLWithSource("").spec(), + "https://accounts.example.com/Logout?continue=https://" + "accounts.example.com/chrome/blank.html"); + EXPECT_EQ(gaia_urls()->get_user_info_url().spec(), + "https://accounts.example.com/GetUserInfo"); + EXPECT_EQ(gaia_urls()->token_auth_url().spec(), + "https://accounts.example.com/TokenAuth"); + EXPECT_EQ(gaia_urls()->merge_session_url().spec(), + "https://accounts.example.com/MergeSession"); + EXPECT_EQ(gaia_urls()->get_oauth_token_url().spec(), + "https://accounts.example.com/o/oauth/GetOAuthToken/"); + EXPECT_EQ(gaia_urls()->oauth_get_access_token_url().spec(), + "https://accounts.example.com/OAuthGetAccessToken"); + EXPECT_EQ(gaia_urls()->oauth_wrap_bridge_url().spec(), + "https://accounts.example.com/OAuthWrapBridge"); + EXPECT_EQ(gaia_urls()->oauth_multilogin_url().spec(), + "https://accounts.example.com/oauth/multilogin"); + EXPECT_EQ(gaia_urls()->oauth_user_info_url().spec(), + "https://www.exampleapis.com/oauth2/v1/userinfo"); + EXPECT_EQ(gaia_urls()->oauth_revoke_token_url().spec(), + "https://accounts.example.com/AuthSubRevokeToken"); + EXPECT_EQ(gaia_urls()->oauth1_login_url().spec(), + "https://accounts.example.com/OAuthLogin"); + EXPECT_EQ(gaia_urls()->ListAccountsURLWithSource("").spec(), + "https://accounts.example.com/ListAccounts?json=standard"); + EXPECT_EQ(gaia_urls()->embedded_signin_url().spec(), + "https://accounts.example.com/embedded/setup/chrome/usermenu"); + EXPECT_EQ(gaia_urls()->add_account_url().spec(), + "https://accounts.example.com/AddSession"); + EXPECT_EQ(gaia_urls()->reauth_url().spec(), + "https://accounts.example.com/embedded/xreauth/chrome"); + EXPECT_EQ(gaia_urls()->GetCheckConnectionInfoURLWithSource("").spec(), + "https://accounts.example.com/GetCheckConnectionInfo"); + EXPECT_EQ(gaia_urls()->oauth2_auth_url().spec(), + "https://accounts.example.com/o/oauth2/auth"); + EXPECT_EQ(gaia_urls()->oauth2_token_url().spec(), + "https://www.exampleapis.com/oauth2/v4/token"); + EXPECT_EQ(gaia_urls()->oauth2_issue_token_url().spec(), + "https://oauthaccountmanager.exampleapis.com/v1/issuetoken"); + EXPECT_EQ(gaia_urls()->oauth2_token_info_url().spec(), + "https://www.exampleapis.com/oauth2/v2/tokeninfo"); + EXPECT_EQ(gaia_urls()->oauth2_revoke_url().spec(), + "https://accounts.example.com/o/oauth2/revoke"); + EXPECT_EQ(gaia_urls()->reauth_api_url().spec(), + "https://www.exampleapis.com/reauth/v1beta/users/"); + EXPECT_EQ(gaia_urls()->gaia_login_form_realm().spec(), + "https://accounts.example.com/"); +} + +TEST_F(GaiaUrlsTest, InitializeFromConfig_AllBaseUrls) { + base::test::ScopedCommandLine command_line; + command_line.GetProcessCommandLine()->AppendSwitchPath( + "gaia-config", GetTestFilePath("all_base_urls.json")); + + EXPECT_EQ(gaia_urls()->google_url().spec(), "http://example.com/"); + EXPECT_EQ(gaia_urls()->secure_google_url().spec(), "https://example.com/"); + EXPECT_EQ(gaia_urls()->gaia_url().spec(), "https://accounts.example.com/"); + EXPECT_EQ(gaia_urls()->captcha_base_url().spec(), + "http://accounts.example.com/"); + EXPECT_EQ(gaia_urls()->client_login_url().spec(), + "https://accounts.example.com/ClientLogin"); + EXPECT_EQ(gaia_urls()->service_login_url().spec(), + "https://accounts.example.com/ServiceLogin"); + EXPECT_EQ(gaia_urls()->embedded_setup_chromeos_url(2U).spec(), + "https://accounts.example.com/embedded/setup/v2/chromeos"); + EXPECT_EQ(gaia_urls()->embedded_setup_windows_url().spec(), + "https://accounts.example.com/embedded/setup/windows"); + EXPECT_EQ(gaia_urls()->signin_chrome_sync_dice().spec(), + "https://accounts.example.com/signin/chrome/sync?ssp=1"); + EXPECT_EQ(gaia_urls()->signin_chrome_sync_keys_url().spec(), + std::string("https://accounts.example.com/encryption/unlock/") + + kSigninChromeSyncKeysPlatformSuffix); + EXPECT_EQ(gaia_urls()->service_login_auth_url().spec(), + "https://accounts.example.com/ServiceLoginAuth"); + EXPECT_EQ(gaia_urls()->service_logout_url().spec(), + "https://accounts.example.com/Logout"); + EXPECT_EQ(gaia_urls()->LogOutURLWithSource("").spec(), + "https://accounts.example.com/Logout?continue=https://" + "accounts.example.com/chrome/blank.html"); + EXPECT_EQ(gaia_urls()->get_user_info_url().spec(), + "https://accounts.example.com/GetUserInfo"); + EXPECT_EQ(gaia_urls()->token_auth_url().spec(), + "https://accounts.example.com/TokenAuth"); + EXPECT_EQ(gaia_urls()->merge_session_url().spec(), + "https://accounts.example.com/MergeSession"); + EXPECT_EQ(gaia_urls()->get_oauth_token_url().spec(), + "https://lso.example.com/o/oauth/GetOAuthToken/"); + EXPECT_EQ(gaia_urls()->oauth_get_access_token_url().spec(), + "https://accounts.example.com/OAuthGetAccessToken"); + EXPECT_EQ(gaia_urls()->oauth_wrap_bridge_url().spec(), + "https://accounts.example.com/OAuthWrapBridge"); + EXPECT_EQ(gaia_urls()->oauth_multilogin_url().spec(), + "https://accounts.example.com/oauth/multilogin"); + EXPECT_EQ(gaia_urls()->oauth_user_info_url().spec(), + "https://www.exampleapis.com/oauth2/v1/userinfo"); + EXPECT_EQ(gaia_urls()->oauth_revoke_token_url().spec(), + "https://accounts.example.com/AuthSubRevokeToken"); + EXPECT_EQ(gaia_urls()->oauth1_login_url().spec(), + "https://accounts.example.com/OAuthLogin"); + EXPECT_EQ(gaia_urls()->ListAccountsURLWithSource("").spec(), + "https://accounts.example.com/ListAccounts?json=standard"); + EXPECT_EQ(gaia_urls()->embedded_signin_url().spec(), + "https://accounts.example.com/embedded/setup/chrome/usermenu"); + EXPECT_EQ(gaia_urls()->add_account_url().spec(), + "https://accounts.example.com/AddSession"); + EXPECT_EQ(gaia_urls()->reauth_url().spec(), + "https://accounts.example.com/embedded/xreauth/chrome"); + EXPECT_EQ(gaia_urls()->GetCheckConnectionInfoURLWithSource("").spec(), + "https://accounts.example.com/GetCheckConnectionInfo"); + EXPECT_EQ(gaia_urls()->oauth2_auth_url().spec(), + "https://lso.example.com/o/oauth2/auth"); + EXPECT_EQ(gaia_urls()->oauth2_token_url().spec(), + "https://www.exampleapis.com/oauth2/v4/token"); + EXPECT_EQ(gaia_urls()->oauth2_issue_token_url().spec(), + "https://oauthaccountmanager.exampleapis.com/v1/issuetoken"); + EXPECT_EQ(gaia_urls()->oauth2_token_info_url().spec(), + "https://www.exampleapis.com/oauth2/v2/tokeninfo"); + EXPECT_EQ(gaia_urls()->oauth2_revoke_url().spec(), + "https://lso.example.com/o/oauth2/revoke"); + EXPECT_EQ(gaia_urls()->reauth_api_url().spec(), + "https://www.exampleapis.com/reauth/v1beta/users/"); + EXPECT_EQ(gaia_urls()->gaia_login_form_realm().spec(), + "https://accounts.example.com/"); +} + +TEST_F(GaiaUrlsTest, InitializeFromConfig_BadUrl) { + base::test::ScopedCommandLine command_line; + command_line.GetProcessCommandLine()->AppendSwitchPath( + "gaia-config", GetTestFilePath("bad_url.json")); + + // A bad URL should be ignored and fallback to the default URL. + EXPECT_EQ(gaia_urls()->google_url().spec(), "http://google.com/"); +} + +TEST_F(GaiaUrlsTest, InitializeFromConfig_BadUrlKey) { + base::test::ScopedCommandLine command_line; + command_line.GetProcessCommandLine()->AppendSwitchPath( + "gaia-config", GetTestFilePath("bad_url_key.json")); + + // Fallback to the default URL. + EXPECT_EQ(gaia_urls()->google_url().spec(), "http://google.com/"); +} + +TEST_F(GaiaUrlsTest, InitializeFromConfig_BadUrlsKey) { + base::test::ScopedCommandLine command_line; + command_line.GetProcessCommandLine()->AppendSwitchPath( + "gaia-config", GetTestFilePath("bad_urls_key.json")); + + // Fallback to the default URL. + EXPECT_EQ(gaia_urls()->google_url().spec(), "http://google.com/"); +} + +TEST_F(GaiaUrlsTest, InitializeFromConfig_FileNotFound) { + base::test::ScopedCommandLine command_line; + command_line.GetProcessCommandLine()->AppendSwitchPath( + "gaia-config", GetTestFilePath("no_such_file.json")); + + // Fallback to the default URL. + EXPECT_EQ(gaia_urls()->google_url().spec(), "http://google.com/"); +} + +TEST_F(GaiaUrlsTest, InitializeFromConfig_NotAJson) { + base::test::ScopedCommandLine command_line; + command_line.GetProcessCommandLine()->AppendSwitchPath( + "gaia-config", GetTestFilePath("not_a_json.txt")); + + // Fallback to the default URL. + EXPECT_EQ(gaia_urls()->google_url().spec(), "http://google.com/"); +} diff --git a/chromium/google_apis/gcm/base/socket_stream_unittest.cc b/chromium/google_apis/gcm/base/socket_stream_unittest.cc index d8ea8fbfb57..079d1189886 100644 --- a/chromium/google_apis/gcm/base/socket_stream_unittest.cc +++ b/chromium/google_apis/gcm/base/socket_stream_unittest.cc @@ -20,6 +20,7 @@ #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/remote.h" #include "net/base/ip_address.h" +#include "net/base/network_isolation_key.h" #include "net/log/net_log_source.h" #include "net/socket/socket_test_util.h" #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" @@ -28,6 +29,7 @@ #include "services/network/network_service.h" #include "services/network/public/mojom/proxy_resolving_socket.mojom.h" #include "testing/gtest/include/gtest/gtest.h" +#include "url/origin.h" namespace gcm { namespace { @@ -231,8 +233,12 @@ void GCMSocketStreamTest::OpenConnection() { network::mojom::ProxyResolvingSocketOptionsPtr options = network::mojom::ProxyResolvingSocketOptions::New(); options->use_tls = true; + const url::Origin kOrigin = url::Origin::Create(kDestination); mojo_socket_factory_remote_->CreateProxyResolvingSocket( - kDestination, std::move(options), + kDestination, + net::NetworkIsolationKey(kOrigin /* top_frame_origin */, + kOrigin /* frame_origin */), + std::move(options), net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS), mojo_socket_remote_.BindNewPipeAndPassReceiver(), mojo::NullRemote() /* observer */, diff --git a/chromium/google_apis/gcm/engine/connection_factory_impl.cc b/chromium/google_apis/gcm/engine/connection_factory_impl.cc index 0e20ff33255..e4d2cf86fe1 100644 --- a/chromium/google_apis/gcm/engine/connection_factory_impl.cc +++ b/chromium/google_apis/gcm/engine/connection_factory_impl.cc @@ -17,6 +17,7 @@ #include "google_apis/gcm/protocol/mcs.pb.h" #include "mojo/public/cpp/bindings/pending_remote.h" #include "net/base/net_errors.h" +#include "net/base/network_isolation_key.h" #include "net/http/http_request_headers.h" #include "net/http/proxy_fallback.h" #include "net/log/net_log_source_type.h" @@ -26,6 +27,8 @@ #include "net/ssl/ssl_config_service.h" #include "net/traffic_annotation/network_traffic_annotation.h" #include "services/network/public/mojom/tcp_socket.mojom.h" +#include "url/gurl.h" +#include "url/origin.h" namespace gcm { @@ -359,8 +362,13 @@ void ConnectionFactoryImpl::StartConnection() { network::mojom::ProxyResolvingSocketOptionsPtr options = network::mojom::ProxyResolvingSocketOptions::New(); options->use_tls = true; + // |current_endpoint| is always a Google URL, so this NetworkIsolationKey will + // be the same for all callers, and will allow pooling all connections to GCM + // in one socket connection, if an H2 or QUIC proxy is in use. + auto origin = url::Origin::Create(current_endpoint); + net::NetworkIsolationKey network_isolation_key(origin, origin); socket_factory_->CreateProxyResolvingSocket( - current_endpoint, std::move(options), + current_endpoint, std::move(network_isolation_key), std::move(options), net::MutableNetworkTrafficAnnotationTag(traffic_annotation), socket_.BindNewPipeAndPassReceiver(), mojo::NullRemote() /* observer */, base::BindOnce(&ConnectionFactoryImpl::OnConnectDone, diff --git a/chromium/google_apis/gcm/engine/connection_factory_impl_unittest.cc b/chromium/google_apis/gcm/engine/connection_factory_impl_unittest.cc index 0c83bb2f850..3e26f257086 100644 --- a/chromium/google_apis/gcm/engine/connection_factory_impl_unittest.cc +++ b/chromium/google_apis/gcm/engine/connection_factory_impl_unittest.cc @@ -292,6 +292,8 @@ class ConnectionFactoryImplTest return login_request.client_event(); } + base::RunLoop* GetRunLoop() { return run_loop_.get(); } + private: void GetProxyResolvingSocketFactory( mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory> @@ -509,7 +511,7 @@ TEST_F(ConnectionFactoryImplTest, CanarySucceedsRetryDuringLogin) { // Pump the loop, to ensure the pending backoff retry has no effect. base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( - FROM_HERE, base::RunLoop::QuitCurrentWhenIdleClosureDeprecated(), + FROM_HERE, GetRunLoop()->QuitWhenIdleClosure(), base::TimeDelta::FromMilliseconds(1)); WaitForConnections(); } diff --git a/chromium/google_apis/gcm/engine/connection_handler_impl_unittest.cc b/chromium/google_apis/gcm/engine/connection_handler_impl_unittest.cc index 2b7e485f579..27003b49f51 100644 --- a/chromium/google_apis/gcm/engine/connection_handler_impl_unittest.cc +++ b/chromium/google_apis/gcm/engine/connection_handler_impl_unittest.cc @@ -27,6 +27,7 @@ #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/remote.h" #include "net/base/ip_address.h" +#include "net/base/network_isolation_key.h" #include "net/base/test_completion_callback.h" #include "net/log/net_log_source.h" #include "net/socket/socket_test_util.h" @@ -38,6 +39,7 @@ #include "services/network/network_service.h" #include "services/network/public/mojom/proxy_resolving_socket.mojom.h" #include "testing/gtest/include/gtest/gtest.h" +#include "url/origin.h" namespace gcm { namespace { @@ -249,8 +251,12 @@ void GCMConnectionHandlerImplTest::BuildSocket(const ReadList& read_list, network::mojom::ProxyResolvingSocketOptions::New(); options->use_tls = true; mojo_socket_remote_.reset(); + const url::Origin kOrigin = url::Origin::Create(kDestination); mojo_socket_factory_remote_->CreateProxyResolvingSocket( - kDestination, std::move(options), + kDestination, + net::NetworkIsolationKey(kOrigin /* top_frame_origin */, + kOrigin /* frame_origin */), + std::move(options), net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS), mojo_socket_remote_.BindNewPipeAndPassReceiver(), mojo::NullRemote() /* observer */, diff --git a/chromium/google_apis/gcm/engine/gservices_settings.cc b/chromium/google_apis/gcm/engine/gservices_settings.cc index 1d53f9f2308..c869c5bbf62 100644 --- a/chromium/google_apis/gcm/engine/gservices_settings.cc +++ b/chromium/google_apis/gcm/engine/gservices_settings.cc @@ -9,6 +9,7 @@ #include "base/bind.h" #include "base/command_line.h" #include "base/hash/sha1.h" +#include "base/logging.h" #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" diff --git a/chromium/google_apis/gcm/engine/heartbeat_manager.h b/chromium/google_apis/gcm/engine/heartbeat_manager.h index acd9a62ee5d..34b849dd979 100644 --- a/chromium/google_apis/gcm/engine/heartbeat_manager.h +++ b/chromium/google_apis/gcm/engine/heartbeat_manager.h @@ -8,7 +8,6 @@ #include <memory> #include "base/callback.h" -#include "base/logging.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/power_monitor/power_observer.h" diff --git a/chromium/google_apis/google_api_keys.cc b/chromium/google_apis/google_api_keys.cc index c2714269723..afff72322ac 100644 --- a/chromium/google_apis/google_api_keys.cc +++ b/chromium/google_apis/google_api_keys.cc @@ -10,6 +10,7 @@ #include <stddef.h> #include <memory> +#include <string> #include "base/command_line.h" #include "base/environment.h" diff --git a/chromium/google_apis/google_api_keys_mac_unittest.mm b/chromium/google_apis/google_api_keys_mac_unittest.mm index 77db7927997..dc1a3ae4db8 100644 --- a/chromium/google_apis/google_api_keys_mac_unittest.mm +++ b/chromium/google_apis/google_api_keys_mac_unittest.mm @@ -32,6 +32,7 @@ #include <string> #include "base/command_line.h" #include "base/lazy_instance.h" +#include "base/logging.h" #include "base/strings/stringize_macros.h" #include "google_apis/google_api_keys_mac.h" diff --git a/chromium/google_apis/google_api_keys_unittest.cc b/chromium/google_apis/google_api_keys_unittest.cc index a359c9f0fa4..d92b237cf82 100644 --- a/chromium/google_apis/google_api_keys_unittest.cc +++ b/chromium/google_apis/google_api_keys_unittest.cc @@ -37,6 +37,7 @@ #include <string> #include "base/command_line.h" #include "base/lazy_instance.h" +#include "base/logging.h" #include "base/strings/stringize_macros.h" #if defined(OS_MACOSX) |