gaia_urls_unittest.cc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "google_apis/gaia/gaia_urls.h"
  5. #include "base/base_paths.h"
  6. #include "base/command_line.h"
  7. #include "base/files/file_path.h"
  8. #include "base/memory/ptr_util.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "base/path_service.h"
  11. #include "base/test/scoped_command_line.h"
  12. #include "build/build_config.h"
  13. #include "build/chromeos_buildflags.h"
  14. #include "google_apis/gaia/gaia_config.h"
  15. #include "testing/gmock/include/gmock/gmock.h"
  16. #include "testing/gtest/include/gtest/gtest.h"
  17. #include "url/gurl.h"
  18. namespace {
  19. #if BUILDFLAG(IS_ANDROID)
  20. const char kSigninChromeSyncKeysPlatformSuffix[] = "android";
  21. #elif BUILDFLAG(IS_IOS)
  22. const char kSigninChromeSyncKeysPlatformSuffix[] = "ios";
  23. #elif BUILDFLAG(IS_CHROMEOS_ASH)
  24. const char kSigninChromeSyncKeysPlatformSuffix[] = "chromeos";
  25. #else
  26. const char kSigninChromeSyncKeysPlatformSuffix[] = "desktop";
  27. #endif
  28. base::FilePath GetTestFilePath(const std::string& relative_path) {
  29. base::FilePath path;
  30. if (!base::PathService::Get(base::DIR_SOURCE_ROOT, &path))
  31. return base::FilePath();
  32. return path.AppendASCII("google_apis")
  33. .AppendASCII("test")
  34. .AppendASCII("data")
  35. .AppendASCII("gaia")
  36. .AppendASCII(relative_path);
  37. }
  38. } // namespace
  39. class GaiaUrlsTest : public ::testing::Test {
  40. public:
  41. GaiaUrlsTest() = default;
  42. ~GaiaUrlsTest() override { delete gaia_urls_; }
  43. // Lazily constructs |gaia_urls_|.
  44. GaiaUrls* gaia_urls() {
  45. if (!gaia_urls_) {
  46. GaiaConfig::ResetInstanceForTesting();
  47. gaia_urls_ = new GaiaUrls();
  48. }
  49. return gaia_urls_;
  50. }
  51. private:
  52. // GaiaUrls must be constructed after command line parameters are overridden.
  53. // GaiaUrls cannot be put into std::unique_ptr<> because ~GaiaUrls() is
  54. // private. Thus, the owning raw pointer is used.
  55. raw_ptr<GaiaUrls> gaia_urls_ = nullptr;
  56. };
  57. TEST_F(GaiaUrlsTest, InitializeDefault_AllUrls) {
  58. EXPECT_EQ(gaia_urls()->google_url().spec(), "http://google.com/");
  59. EXPECT_EQ(gaia_urls()->secure_google_url().spec(), "https://google.com/");
  60. EXPECT_EQ(gaia_urls()->gaia_url().spec(), "https://accounts.google.com/");
  61. EXPECT_EQ(gaia_urls()->client_login_url().spec(),
  62. "https://accounts.google.com/ClientLogin");
  63. EXPECT_EQ(gaia_urls()->service_login_url().spec(),
  64. "https://accounts.google.com/ServiceLogin");
  65. EXPECT_EQ(gaia_urls()->embedded_setup_chromeos_url(2U).spec(),
  66. "https://accounts.google.com/embedded/setup/v2/chromeos");
  67. EXPECT_EQ(gaia_urls()->embedded_setup_chromeos_kid_signup_url().spec(),
  68. "https://accounts.google.com/embedded/setup/kidsignup/chromeos");
  69. EXPECT_EQ(gaia_urls()->embedded_setup_chromeos_kid_signin_url().spec(),
  70. "https://accounts.google.com/embedded/setup/kidsignin/chromeos");
  71. EXPECT_EQ(gaia_urls()->embedded_setup_windows_url().spec(),
  72. "https://accounts.google.com/embedded/setup/windows");
  73. EXPECT_EQ(gaia_urls()->signin_chrome_sync_dice().spec(),
  74. "https://accounts.google.com/signin/chrome/sync?ssp=1");
  75. EXPECT_EQ(gaia_urls()->signin_chrome_sync_keys_retrieval_url().spec(),
  76. std::string("https://accounts.google.com/encryption/unlock/") +
  77. kSigninChromeSyncKeysPlatformSuffix);
  78. EXPECT_EQ(
  79. gaia_urls()->signin_chrome_sync_keys_recoverability_degraded_url().spec(),
  80. std::string("https://accounts.google.com/encryption/unlock/") +
  81. kSigninChromeSyncKeysPlatformSuffix +
  82. std::string("?kdi=CAIaDgoKY2hyb21lc3luYxAB"));
  83. EXPECT_EQ(gaia_urls()->service_login_auth_url().spec(),
  84. "https://accounts.google.com/ServiceLoginAuth");
  85. EXPECT_EQ(gaia_urls()->service_logout_url().spec(),
  86. "https://accounts.google.com/Logout");
  87. EXPECT_EQ(gaia_urls()->LogOutURLWithSource("").spec(),
  88. "https://accounts.google.com/Logout?continue=https://"
  89. "accounts.google.com/chrome/blank.html");
  90. EXPECT_EQ(gaia_urls()->token_auth_url().spec(),
  91. "https://accounts.google.com/TokenAuth");
  92. EXPECT_EQ(gaia_urls()->merge_session_url().spec(),
  93. "https://accounts.google.com/MergeSession");
  94. EXPECT_EQ(gaia_urls()->get_oauth_token_url().spec(),
  95. "https://accounts.google.com/o/oauth/GetOAuthToken/");
  96. EXPECT_EQ(gaia_urls()->oauth_get_access_token_url().spec(),
  97. "https://accounts.google.com/OAuthGetAccessToken");
  98. EXPECT_EQ(gaia_urls()->oauth_wrap_bridge_url().spec(),
  99. "https://accounts.google.com/OAuthWrapBridge");
  100. EXPECT_EQ(gaia_urls()->oauth_multilogin_url().spec(),
  101. "https://accounts.google.com/oauth/multilogin");
  102. EXPECT_EQ(gaia_urls()->oauth_user_info_url().spec(),
  103. "https://www.googleapis.com/oauth2/v1/userinfo");
  104. EXPECT_EQ(gaia_urls()->oauth_revoke_token_url().spec(),
  105. "https://accounts.google.com/AuthSubRevokeToken");
  106. EXPECT_EQ(gaia_urls()->oauth1_login_url().spec(),
  107. "https://accounts.google.com/OAuthLogin");
  108. EXPECT_EQ(gaia_urls()->ListAccountsURLWithSource("").spec(),
  109. "https://accounts.google.com/ListAccounts?json=standard");
  110. EXPECT_EQ(gaia_urls()->embedded_signin_url().spec(),
  111. "https://accounts.google.com/embedded/setup/chrome/usermenu");
  112. EXPECT_EQ(gaia_urls()->add_account_url().spec(),
  113. "https://accounts.google.com/AddSession");
  114. EXPECT_EQ(gaia_urls()->reauth_url().spec(),
  115. "https://accounts.google.com/embedded/xreauth/chrome");
  116. EXPECT_EQ(gaia_urls()->account_capabilities_url().spec(),
  117. "https://accountcapabilities-pa.googleapis.com/v1/"
  118. "accountcapabilities:batchGet");
  119. EXPECT_EQ(gaia_urls()->GetCheckConnectionInfoURLWithSource("").spec(),
  120. "https://accounts.google.com/GetCheckConnectionInfo");
  121. EXPECT_EQ(gaia_urls()->oauth2_auth_url().spec(),
  122. "https://accounts.google.com/o/oauth2/auth");
  123. EXPECT_EQ(gaia_urls()->oauth2_token_url().spec(),
  124. "https://www.googleapis.com/oauth2/v4/token");
  125. EXPECT_EQ(gaia_urls()->oauth2_issue_token_url().spec(),
  126. "https://oauthaccountmanager.googleapis.com/v1/issuetoken");
  127. EXPECT_EQ(gaia_urls()->oauth2_token_info_url().spec(),
  128. "https://www.googleapis.com/oauth2/v2/tokeninfo");
  129. EXPECT_EQ(gaia_urls()->oauth2_revoke_url().spec(),
  130. "https://accounts.google.com/o/oauth2/revoke");
  131. EXPECT_EQ(gaia_urls()->reauth_api_url().spec(),
  132. "https://www.googleapis.com/reauth/v1beta/users/");
  133. }
  134. TEST_F(GaiaUrlsTest, InitializeDefault_URLSwitches) {
  135. base::test::ScopedCommandLine command_line;
  136. command_line.GetProcessCommandLine()->AppendSwitchASCII(
  137. "google-url", "http://test-google.com");
  138. command_line.GetProcessCommandLine()->AppendSwitchASCII(
  139. "gaia-url", "https://test-gaia.com");
  140. command_line.GetProcessCommandLine()->AppendSwitchASCII(
  141. "google-apis-url", "https://test-googleapis.com");
  142. command_line.GetProcessCommandLine()->AppendSwitchASCII(
  143. "lso-url", "https://test-lso.com");
  144. command_line.GetProcessCommandLine()->AppendSwitchASCII(
  145. "oauth-account-manager-url", "https://test-oauthaccountmanager.com");
  146. EXPECT_EQ(gaia_urls()->google_url().spec(), "http://test-google.com/");
  147. EXPECT_EQ(gaia_urls()->secure_google_url().spec(),
  148. "https://test-google.com/");
  149. EXPECT_EQ(gaia_urls()->gaia_url().spec(), "https://test-gaia.com/");
  150. EXPECT_EQ(gaia_urls()->client_login_url().spec(),
  151. "https://test-gaia.com/ClientLogin");
  152. EXPECT_EQ(gaia_urls()->service_login_url().spec(),
  153. "https://test-gaia.com/ServiceLogin");
  154. EXPECT_EQ(gaia_urls()->embedded_setup_chromeos_url(2U).spec(),
  155. "https://test-gaia.com/embedded/setup/v2/chromeos");
  156. EXPECT_EQ(gaia_urls()->embedded_setup_chromeos_kid_signup_url().spec(),
  157. "https://test-gaia.com/embedded/setup/kidsignup/chromeos");
  158. EXPECT_EQ(gaia_urls()->embedded_setup_chromeos_kid_signin_url().spec(),
  159. "https://test-gaia.com/embedded/setup/kidsignin/chromeos");
  160. EXPECT_EQ(gaia_urls()->embedded_setup_windows_url().spec(),
  161. "https://test-gaia.com/embedded/setup/windows");
  162. EXPECT_EQ(gaia_urls()->signin_chrome_sync_dice().spec(),
  163. "https://test-gaia.com/signin/chrome/sync?ssp=1");
  164. EXPECT_EQ(gaia_urls()->signin_chrome_sync_keys_retrieval_url().spec(),
  165. std::string("https://test-gaia.com/encryption/unlock/") +
  166. kSigninChromeSyncKeysPlatformSuffix);
  167. EXPECT_EQ(
  168. gaia_urls()->signin_chrome_sync_keys_recoverability_degraded_url().spec(),
  169. std::string("https://test-gaia.com/encryption/unlock/") +
  170. kSigninChromeSyncKeysPlatformSuffix +
  171. std::string("?kdi=CAIaDgoKY2hyb21lc3luYxAB"));
  172. EXPECT_EQ(gaia_urls()->service_login_auth_url().spec(),
  173. "https://test-gaia.com/ServiceLoginAuth");
  174. EXPECT_EQ(gaia_urls()->service_logout_url().spec(),
  175. "https://test-gaia.com/Logout");
  176. EXPECT_EQ(gaia_urls()->LogOutURLWithSource("").spec(),
  177. "https://test-gaia.com/Logout?continue=https://"
  178. "test-gaia.com/chrome/blank.html");
  179. EXPECT_EQ(gaia_urls()->token_auth_url().spec(),
  180. "https://test-gaia.com/TokenAuth");
  181. EXPECT_EQ(gaia_urls()->merge_session_url().spec(),
  182. "https://test-gaia.com/MergeSession");
  183. EXPECT_EQ(gaia_urls()->get_oauth_token_url().spec(),
  184. "https://test-lso.com/o/oauth/GetOAuthToken/");
  185. EXPECT_EQ(gaia_urls()->oauth_get_access_token_url().spec(),
  186. "https://test-gaia.com/OAuthGetAccessToken");
  187. EXPECT_EQ(gaia_urls()->oauth_wrap_bridge_url().spec(),
  188. "https://test-gaia.com/OAuthWrapBridge");
  189. EXPECT_EQ(gaia_urls()->oauth_multilogin_url().spec(),
  190. "https://test-gaia.com/oauth/multilogin");
  191. EXPECT_EQ(gaia_urls()->oauth_user_info_url().spec(),
  192. "https://test-googleapis.com/oauth2/v1/userinfo");
  193. EXPECT_EQ(gaia_urls()->oauth_revoke_token_url().spec(),
  194. "https://test-gaia.com/AuthSubRevokeToken");
  195. EXPECT_EQ(gaia_urls()->oauth1_login_url().spec(),
  196. "https://test-gaia.com/OAuthLogin");
  197. EXPECT_EQ(gaia_urls()->ListAccountsURLWithSource("").spec(),
  198. "https://test-gaia.com/ListAccounts?json=standard");
  199. EXPECT_EQ(gaia_urls()->embedded_signin_url().spec(),
  200. "https://test-gaia.com/embedded/setup/chrome/usermenu");
  201. EXPECT_EQ(gaia_urls()->add_account_url().spec(),
  202. "https://test-gaia.com/AddSession");
  203. EXPECT_EQ(gaia_urls()->reauth_url().spec(),
  204. "https://test-gaia.com/embedded/xreauth/chrome");
  205. EXPECT_EQ(gaia_urls()->GetCheckConnectionInfoURLWithSource("").spec(),
  206. "https://test-gaia.com/GetCheckConnectionInfo");
  207. EXPECT_EQ(gaia_urls()->oauth2_auth_url().spec(),
  208. "https://test-lso.com/o/oauth2/auth");
  209. EXPECT_EQ(gaia_urls()->oauth2_token_url().spec(),
  210. "https://test-googleapis.com/oauth2/v4/token");
  211. EXPECT_EQ(gaia_urls()->oauth2_issue_token_url().spec(),
  212. "https://test-oauthaccountmanager.com/v1/issuetoken");
  213. EXPECT_EQ(gaia_urls()->oauth2_token_info_url().spec(),
  214. "https://test-googleapis.com/oauth2/v2/tokeninfo");
  215. EXPECT_EQ(gaia_urls()->oauth2_revoke_url().spec(),
  216. "https://test-lso.com/o/oauth2/revoke");
  217. EXPECT_EQ(gaia_urls()->reauth_api_url().spec(),
  218. "https://test-googleapis.com/reauth/v1beta/users/");
  219. }
  220. TEST_F(GaiaUrlsTest, InitializeFromConfig_OneUrl) {
  221. base::test::ScopedCommandLine command_line;
  222. command_line.GetProcessCommandLine()->AppendSwitchPath(
  223. "gaia-config", GetTestFilePath("one_url.json"));
  224. // A URL present in config should be set.
  225. EXPECT_EQ(gaia_urls()->client_login_url().spec(),
  226. "https://accounts.example.com/ExampleClientLogin");
  227. // All other URLs should have default values.
  228. EXPECT_EQ(gaia_urls()->service_login_url().spec(),
  229. "https://accounts.google.com/ServiceLogin");
  230. }
  231. TEST_F(GaiaUrlsTest, InitializeFromConfig_OneBaseUrl) {
  232. base::test::ScopedCommandLine command_line;
  233. command_line.GetProcessCommandLine()->AppendSwitchPath(
  234. "gaia-config", GetTestFilePath("one_base_url.json"));
  235. // A base URL present in config should be set and should be use to compute all
  236. // derived URLs with default suffixes.
  237. EXPECT_EQ(gaia_urls()->gaia_url().spec(), "https://accounts.example.com/");
  238. EXPECT_EQ(gaia_urls()->client_login_url().spec(),
  239. "https://accounts.example.com/ClientLogin");
  240. EXPECT_EQ(gaia_urls()->service_login_url().spec(),
  241. "https://accounts.example.com/ServiceLogin");
  242. // All other URLs should have default values.
  243. EXPECT_EQ(gaia_urls()->get_oauth_token_url().spec(),
  244. "https://accounts.google.com/o/oauth/GetOAuthToken/");
  245. }
  246. TEST_F(GaiaUrlsTest, InitializeFromConfig_PrecedenceOverSwitches) {
  247. base::test::ScopedCommandLine command_line;
  248. command_line.GetProcessCommandLine()->AppendSwitchPath(
  249. "gaia-config", GetTestFilePath("one_url.json"));
  250. command_line.GetProcessCommandLine()->AppendSwitchASCII(
  251. "gaia-url", "https://myaccounts.com");
  252. // A URL present in config should be overridden.
  253. EXPECT_EQ(gaia_urls()->client_login_url().spec(),
  254. "https://accounts.example.com/ExampleClientLogin");
  255. // All other URLs should be computed according command line flags.
  256. EXPECT_EQ(gaia_urls()->gaia_url().spec(), "https://myaccounts.com/");
  257. EXPECT_EQ(gaia_urls()->service_login_url().spec(),
  258. "https://myaccounts.com/ServiceLogin");
  259. }
  260. TEST_F(GaiaUrlsTest, InitializeFromConfig_AllUrls) {
  261. base::test::ScopedCommandLine command_line;
  262. command_line.GetProcessCommandLine()->AppendSwitchPath(
  263. "gaia-config", GetTestFilePath("all_urls.json"));
  264. EXPECT_EQ(gaia_urls()->google_url().spec(), "http://example.com/");
  265. EXPECT_EQ(gaia_urls()->secure_google_url().spec(), "https://example.com/");
  266. EXPECT_EQ(gaia_urls()->gaia_url().spec(), "https://accounts.example.com/");
  267. EXPECT_EQ(gaia_urls()->client_login_url().spec(),
  268. "https://accounts.example.com/ClientLogin");
  269. EXPECT_EQ(gaia_urls()->service_login_url().spec(),
  270. "https://accounts.example.com/ServiceLogin");
  271. EXPECT_EQ(gaia_urls()->embedded_setup_chromeos_url(2U).spec(),
  272. "https://accounts.example.com/embedded/setup/v2/chromeos");
  273. EXPECT_EQ(gaia_urls()->embedded_setup_chromeos_kid_signup_url().spec(),
  274. "https://accounts.example.com/embedded/setup/kidsignup/chromeos");
  275. EXPECT_EQ(gaia_urls()->embedded_setup_chromeos_kid_signin_url().spec(),
  276. "https://accounts.example.com/embedded/setup/kidsignin/chromeos");
  277. EXPECT_EQ(gaia_urls()->embedded_setup_windows_url().spec(),
  278. "https://accounts.example.com/embedded/setup/windows");
  279. EXPECT_EQ(gaia_urls()->signin_chrome_sync_dice().spec(),
  280. "https://accounts.example.com/signin/chrome/sync?ssp=1");
  281. EXPECT_EQ(gaia_urls()->signin_chrome_sync_keys_retrieval_url().spec(),
  282. "https://accounts.example.com/encryption/unlock/example-platform");
  283. EXPECT_EQ(
  284. gaia_urls()->signin_chrome_sync_keys_recoverability_degraded_url().spec(),
  285. "https://accounts.example.com/encryption/unlock/example-platform?"
  286. "kdi=CAIaDgoKY2hyb21lc3luYxAB");
  287. EXPECT_EQ(gaia_urls()->service_login_auth_url().spec(),
  288. "https://accounts.example.com/ServiceLoginAuth");
  289. EXPECT_EQ(gaia_urls()->service_logout_url().spec(),
  290. "https://accounts.example.com/Logout");
  291. EXPECT_EQ(gaia_urls()->LogOutURLWithSource("").spec(),
  292. "https://accounts.example.com/Logout?continue=https://"
  293. "accounts.example.com/chrome/blank.html");
  294. EXPECT_EQ(gaia_urls()->token_auth_url().spec(),
  295. "https://accounts.example.com/TokenAuth");
  296. EXPECT_EQ(gaia_urls()->merge_session_url().spec(),
  297. "https://accounts.example.com/MergeSession");
  298. EXPECT_EQ(gaia_urls()->get_oauth_token_url().spec(),
  299. "https://accounts.example.com/o/oauth/GetOAuthToken/");
  300. EXPECT_EQ(gaia_urls()->oauth_get_access_token_url().spec(),
  301. "https://accounts.example.com/OAuthGetAccessToken");
  302. EXPECT_EQ(gaia_urls()->oauth_wrap_bridge_url().spec(),
  303. "https://accounts.example.com/OAuthWrapBridge");
  304. EXPECT_EQ(gaia_urls()->oauth_multilogin_url().spec(),
  305. "https://accounts.example.com/oauth/multilogin");
  306. EXPECT_EQ(gaia_urls()->oauth_user_info_url().spec(),
  307. "https://www.exampleapis.com/oauth2/v1/userinfo");
  308. EXPECT_EQ(gaia_urls()->oauth_revoke_token_url().spec(),
  309. "https://accounts.example.com/AuthSubRevokeToken");
  310. EXPECT_EQ(gaia_urls()->oauth1_login_url().spec(),
  311. "https://accounts.example.com/OAuthLogin");
  312. EXPECT_EQ(gaia_urls()->ListAccountsURLWithSource("").spec(),
  313. "https://accounts.example.com/ListAccounts?json=standard");
  314. EXPECT_EQ(gaia_urls()->embedded_signin_url().spec(),
  315. "https://accounts.example.com/embedded/setup/chrome/usermenu");
  316. EXPECT_EQ(gaia_urls()->add_account_url().spec(),
  317. "https://accounts.example.com/AddSession");
  318. EXPECT_EQ(gaia_urls()->reauth_url().spec(),
  319. "https://accounts.example.com/embedded/xreauth/chrome");
  320. EXPECT_EQ(gaia_urls()->account_capabilities_url().spec(),
  321. "https://accountcapabilities.exampleapis.com/v1/capabilities");
  322. EXPECT_EQ(gaia_urls()->GetCheckConnectionInfoURLWithSource("").spec(),
  323. "https://accounts.example.com/GetCheckConnectionInfo");
  324. EXPECT_EQ(gaia_urls()->oauth2_auth_url().spec(),
  325. "https://accounts.example.com/o/oauth2/auth");
  326. EXPECT_EQ(gaia_urls()->oauth2_token_url().spec(),
  327. "https://www.exampleapis.com/oauth2/v4/token");
  328. EXPECT_EQ(gaia_urls()->oauth2_issue_token_url().spec(),
  329. "https://oauthaccountmanager.exampleapis.com/v1/issuetoken");
  330. EXPECT_EQ(gaia_urls()->oauth2_token_info_url().spec(),
  331. "https://www.exampleapis.com/oauth2/v2/tokeninfo");
  332. EXPECT_EQ(gaia_urls()->oauth2_revoke_url().spec(),
  333. "https://accounts.example.com/o/oauth2/revoke");
  334. EXPECT_EQ(gaia_urls()->reauth_api_url().spec(),
  335. "https://www.exampleapis.com/reauth/v1beta/users/");
  336. }
  337. TEST_F(GaiaUrlsTest, InitializeFromConfig_AllBaseUrls) {
  338. base::test::ScopedCommandLine command_line;
  339. command_line.GetProcessCommandLine()->AppendSwitchPath(
  340. "gaia-config", GetTestFilePath("all_base_urls.json"));
  341. EXPECT_EQ(gaia_urls()->google_url().spec(), "http://example.com/");
  342. EXPECT_EQ(gaia_urls()->secure_google_url().spec(), "https://example.com/");
  343. EXPECT_EQ(gaia_urls()->gaia_url().spec(), "https://accounts.example.com/");
  344. EXPECT_EQ(gaia_urls()->client_login_url().spec(),
  345. "https://accounts.example.com/ClientLogin");
  346. EXPECT_EQ(gaia_urls()->service_login_url().spec(),
  347. "https://accounts.example.com/ServiceLogin");
  348. EXPECT_EQ(gaia_urls()->embedded_setup_chromeos_url(2U).spec(),
  349. "https://accounts.example.com/embedded/setup/v2/chromeos");
  350. EXPECT_EQ(gaia_urls()->embedded_setup_windows_url().spec(),
  351. "https://accounts.example.com/embedded/setup/windows");
  352. EXPECT_EQ(gaia_urls()->signin_chrome_sync_dice().spec(),
  353. "https://accounts.example.com/signin/chrome/sync?ssp=1");
  354. EXPECT_EQ(gaia_urls()->signin_chrome_sync_keys_retrieval_url().spec(),
  355. std::string("https://accounts.example.com/encryption/unlock/") +
  356. kSigninChromeSyncKeysPlatformSuffix);
  357. EXPECT_EQ(
  358. gaia_urls()->signin_chrome_sync_keys_recoverability_degraded_url().spec(),
  359. std::string("https://accounts.example.com/encryption/unlock/") +
  360. kSigninChromeSyncKeysPlatformSuffix +
  361. std::string("?kdi=CAIaDgoKY2hyb21lc3luYxAB"));
  362. EXPECT_EQ(gaia_urls()->service_login_auth_url().spec(),
  363. "https://accounts.example.com/ServiceLoginAuth");
  364. EXPECT_EQ(gaia_urls()->service_logout_url().spec(),
  365. "https://accounts.example.com/Logout");
  366. EXPECT_EQ(gaia_urls()->LogOutURLWithSource("").spec(),
  367. "https://accounts.example.com/Logout?continue=https://"
  368. "accounts.example.com/chrome/blank.html");
  369. EXPECT_EQ(gaia_urls()->token_auth_url().spec(),
  370. "https://accounts.example.com/TokenAuth");
  371. EXPECT_EQ(gaia_urls()->merge_session_url().spec(),
  372. "https://accounts.example.com/MergeSession");
  373. EXPECT_EQ(gaia_urls()->get_oauth_token_url().spec(),
  374. "https://lso.example.com/o/oauth/GetOAuthToken/");
  375. EXPECT_EQ(gaia_urls()->oauth_get_access_token_url().spec(),
  376. "https://accounts.example.com/OAuthGetAccessToken");
  377. EXPECT_EQ(gaia_urls()->oauth_wrap_bridge_url().spec(),
  378. "https://accounts.example.com/OAuthWrapBridge");
  379. EXPECT_EQ(gaia_urls()->oauth_multilogin_url().spec(),
  380. "https://accounts.example.com/oauth/multilogin");
  381. EXPECT_EQ(gaia_urls()->oauth_user_info_url().spec(),
  382. "https://www.exampleapis.com/oauth2/v1/userinfo");
  383. EXPECT_EQ(gaia_urls()->oauth_revoke_token_url().spec(),
  384. "https://accounts.example.com/AuthSubRevokeToken");
  385. EXPECT_EQ(gaia_urls()->oauth1_login_url().spec(),
  386. "https://accounts.example.com/OAuthLogin");
  387. EXPECT_EQ(gaia_urls()->ListAccountsURLWithSource("").spec(),
  388. "https://accounts.example.com/ListAccounts?json=standard");
  389. EXPECT_EQ(gaia_urls()->embedded_signin_url().spec(),
  390. "https://accounts.example.com/embedded/setup/chrome/usermenu");
  391. EXPECT_EQ(gaia_urls()->add_account_url().spec(),
  392. "https://accounts.example.com/AddSession");
  393. EXPECT_EQ(gaia_urls()->reauth_url().spec(),
  394. "https://accounts.example.com/embedded/xreauth/chrome");
  395. EXPECT_EQ(gaia_urls()->account_capabilities_url().spec(),
  396. "https://accountcapabilities.exampleapis.com/v1/"
  397. "accountcapabilities:batchGet");
  398. EXPECT_EQ(gaia_urls()->GetCheckConnectionInfoURLWithSource("").spec(),
  399. "https://accounts.example.com/GetCheckConnectionInfo");
  400. EXPECT_EQ(gaia_urls()->oauth2_auth_url().spec(),
  401. "https://lso.example.com/o/oauth2/auth");
  402. EXPECT_EQ(gaia_urls()->oauth2_token_url().spec(),
  403. "https://www.exampleapis.com/oauth2/v4/token");
  404. EXPECT_EQ(gaia_urls()->oauth2_issue_token_url().spec(),
  405. "https://oauthaccountmanager.exampleapis.com/v1/issuetoken");
  406. EXPECT_EQ(gaia_urls()->oauth2_token_info_url().spec(),
  407. "https://www.exampleapis.com/oauth2/v2/tokeninfo");
  408. EXPECT_EQ(gaia_urls()->oauth2_revoke_url().spec(),
  409. "https://lso.example.com/o/oauth2/revoke");
  410. EXPECT_EQ(gaia_urls()->reauth_api_url().spec(),
  411. "https://www.exampleapis.com/reauth/v1beta/users/");
  412. }
  413. TEST_F(GaiaUrlsTest, InitializeFromConfigContents) {
  414. base::test::ScopedCommandLine command_line;
  415. command_line.GetProcessCommandLine()->AppendSwitchASCII(
  416. "gaia-config-contents", R"(
  417. {
  418. "urls": {
  419. "gaia_url": {
  420. "url": "https://accounts.example.com"
  421. }
  422. }
  423. })");
  424. EXPECT_EQ(gaia_urls()->gaia_url().spec(), "https://accounts.example.com/");
  425. }
  426. TEST_F(GaiaUrlsTest, InitializeFromConfig_BadUrl) {
  427. base::test::ScopedCommandLine command_line;
  428. command_line.GetProcessCommandLine()->AppendSwitchPath(
  429. "gaia-config", GetTestFilePath("bad_url.json"));
  430. // A bad URL should be ignored and fallback to the default URL.
  431. EXPECT_EQ(gaia_urls()->google_url().spec(), "http://google.com/");
  432. }
  433. TEST_F(GaiaUrlsTest, InitializeFromConfig_BadUrlKey) {
  434. base::test::ScopedCommandLine command_line;
  435. command_line.GetProcessCommandLine()->AppendSwitchPath(
  436. "gaia-config", GetTestFilePath("bad_url_key.json"));
  437. // Fallback to the default URL.
  438. EXPECT_EQ(gaia_urls()->google_url().spec(), "http://google.com/");
  439. }
  440. TEST_F(GaiaUrlsTest, InitializeFromConfig_BadUrlsKey) {
  441. base::test::ScopedCommandLine command_line;
  442. command_line.GetProcessCommandLine()->AppendSwitchPath(
  443. "gaia-config", GetTestFilePath("bad_urls_key.json"));
  444. // Fallback to the default URL.
  445. EXPECT_EQ(gaia_urls()->google_url().spec(), "http://google.com/");
  446. }
  447. TEST_F(GaiaUrlsTest, InitializeFromConfig_FileNotFound) {
  448. base::test::ScopedCommandLine command_line;
  449. command_line.GetProcessCommandLine()->AppendSwitchPath(
  450. "gaia-config", GetTestFilePath("no_such_file.json"));
  451. EXPECT_DEATH_IF_SUPPORTED(gaia_urls(), "Couldn't read Gaia config file");
  452. }
  453. TEST_F(GaiaUrlsTest, InitializeFromConfig_NotAJson) {
  454. base::test::ScopedCommandLine command_line;
  455. command_line.GetProcessCommandLine()->AppendSwitchPath(
  456. "gaia-config", GetTestFilePath("not_a_json.txt"));
  457. EXPECT_DEATH_IF_SUPPORTED(gaia_urls(), "Couldn't parse Gaia config file");
  458. }