Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: google_apis/gaia/gaia_auth_fetcher_unittest.cc

Issue 2035293002: Remove URLRequest::GetResponseCookies and URLRequestJob::GetResponseCookies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // A complete set of unit tests for GaiaAuthFetcher. 5 // A complete set of unit tests for GaiaAuthFetcher.
6 // Originally ported from GoogleAuthenticator tests. 6 // Originally ported from GoogleAuthenticator tests.
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/memory/ref_counted.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 #include "google_apis/gaia/gaia_auth_consumer.h" 15 #include "google_apis/gaia/gaia_auth_consumer.h"
15 #include "google_apis/gaia/gaia_auth_fetcher.h" 16 #include "google_apis/gaia/gaia_auth_fetcher.h"
16 #include "google_apis/gaia/gaia_urls.h" 17 #include "google_apis/gaia/gaia_urls.h"
17 #include "google_apis/gaia/google_service_auth_error.h" 18 #include "google_apis/gaia/google_service_auth_error.h"
18 #include "google_apis/gaia/mock_url_fetcher_factory.h" 19 #include "google_apis/gaia/mock_url_fetcher_factory.h"
19 #include "google_apis/google_api_keys.h" 20 #include "google_apis/google_api_keys.h"
20 #include "net/base/load_flags.h" 21 #include "net/base/load_flags.h"
21 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
23 #include "net/http/http_response_headers.h"
22 #include "net/http/http_status_code.h" 24 #include "net/http/http_status_code.h"
23 #include "net/url_request/test_url_fetcher_factory.h" 25 #include "net/url_request/test_url_fetcher_factory.h"
24 #include "net/url_request/url_fetcher_delegate.h" 26 #include "net/url_request/url_fetcher_delegate.h"
25 #include "net/url_request/url_request_status.h" 27 #include "net/url_request/url_request_status.h"
26 #include "net/url_request/url_request_test_util.h" 28 #include "net/url_request/url_request_test_util.h"
27 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
29 #include "url/gurl.h" 31 #include "url/gurl.h"
30 32
31 using ::testing::Invoke; 33 using ::testing::Invoke;
32 using ::testing::_; 34 using ::testing::_;
33 35
36 namespace {
37 std::string CookieStringToHeader(const char* cookie_string) {
38 return std::string("Set-Cookie: ") + cookie_string;
39 }
40 }
mmenke 2016/06/08 14:46:44 nit: // namespace
mmenke 2016/06/08 14:46:44 Also, while you're here, this should probably be e
martijnc 2016/06/08 16:08:10 Both done.
41
34 const char kGetAuthCodeValidCookie[] = 42 const char kGetAuthCodeValidCookie[] =
35 "oauth_code=test-code; Path=/test; Secure; HttpOnly"; 43 "oauth_code=test-code; Path=/test; Secure; HttpOnly";
36 const char kGetAuthCodeCookieNoSecure[] = 44 const char kGetAuthCodeCookieNoSecure[] =
37 "oauth_code=test-code; Path=/test; HttpOnly"; 45 "oauth_code=test-code; Path=/test; HttpOnly";
38 const char kGetAuthCodeCookieNoHttpOnly[] = 46 const char kGetAuthCodeCookieNoHttpOnly[] =
39 "oauth_code=test-code; Path=/test; Secure"; 47 "oauth_code=test-code; Path=/test; Secure";
40 const char kGetAuthCodeCookieNoOAuthCode[] = 48 const char kGetAuthCodeCookieNoOAuthCode[] =
41 "Path=/test; Secure; HttpOnly"; 49 "Path=/test; Secure; HttpOnly";
42 const char kGetTokenPairValidResponse[] = 50 const char kGetTokenPairValidResponse[] =
43 "{" 51 "{"
(...skipping 19 matching lines...) Expand all
63 error = net::ERR_FAILED; 71 error = net::ERR_FAILED;
64 } 72 }
65 73
66 set_status(net::URLRequestStatus::FromError(error)); 74 set_status(net::URLRequestStatus::FromError(error));
67 SetResponseString(results); 75 SetResponseString(results);
68 } 76 }
69 77
70 MockFetcher::MockFetcher(const GURL& url, 78 MockFetcher::MockFetcher(const GURL& url,
71 const net::URLRequestStatus& status, 79 const net::URLRequestStatus& status,
72 int response_code, 80 int response_code,
73 const net::ResponseCookies& cookies,
74 const std::string& results, 81 const std::string& results,
75 net::URLFetcher::RequestType request_type, 82 net::URLFetcher::RequestType request_type,
76 net::URLFetcherDelegate* d) 83 net::URLFetcherDelegate* d)
77 : TestURLFetcher(0, url, d) { 84 : TestURLFetcher(0, url, d) {
78 set_url(url); 85 set_url(url);
79 set_status(status); 86 set_status(status);
80 set_response_code(response_code); 87 set_response_code(response_code);
81 set_cookies(cookies);
82 SetResponseString(results); 88 SetResponseString(results);
83 } 89 }
84 90
85 MockFetcher::~MockFetcher() {} 91 MockFetcher::~MockFetcher() {}
86 92
87 void MockFetcher::Start() { 93 void MockFetcher::Start() {
88 delegate()->OnURLFetchComplete(this); 94 delegate()->OnURLFetchComplete(this);
89 } 95 }
90 96
91 class GaiaAuthFetcherTest : public testing::Test { 97 class GaiaAuthFetcherTest : public testing::Test {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 &out_error, 140 &out_error,
135 &out_error_url, 141 &out_error_url,
136 &out_captcha_url, 142 &out_captcha_url,
137 &out_captcha_token); 143 &out_captcha_token);
138 EXPECT_EQ(error, out_error); 144 EXPECT_EQ(error, out_error);
139 EXPECT_EQ(error_url, out_error_url); 145 EXPECT_EQ(error_url, out_error_url);
140 EXPECT_EQ(captcha_url, out_captcha_url); 146 EXPECT_EQ(captcha_url, out_captcha_url);
141 EXPECT_EQ(captcha_token, out_captcha_token); 147 EXPECT_EQ(captcha_token, out_captcha_token);
142 } 148 }
143 149
144 net::ResponseCookies cookies_;
145 GURL issue_auth_token_source_; 150 GURL issue_auth_token_source_;
146 GURL client_login_to_oauth2_source_; 151 GURL client_login_to_oauth2_source_;
147 GURL oauth2_token_source_; 152 GURL oauth2_token_source_;
148 GURL token_auth_source_; 153 GURL token_auth_source_;
149 GURL merge_session_source_; 154 GURL merge_session_source_;
150 GURL uberauth_token_source_; 155 GURL uberauth_token_source_;
151 GURL oauth_login_gurl_; 156 GURL oauth_login_gurl_;
152 157
153 protected: 158 protected:
154 net::TestURLRequestContextGetter* GetRequestContext() { 159 net::TestURLRequestContextGetter* GetRequestContext() {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 234
230 GoogleServiceAuthError expected_error = 235 GoogleServiceAuthError expected_error =
231 GoogleServiceAuthError::FromConnectionError(error_no); 236 GoogleServiceAuthError::FromConnectionError(error_no);
232 237
233 MockGaiaConsumer consumer; 238 MockGaiaConsumer consumer;
234 EXPECT_CALL(consumer, OnIssueAuthTokenFailure(_, expected_error)) 239 EXPECT_CALL(consumer, OnIssueAuthTokenFailure(_, expected_error))
235 .Times(1); 240 .Times(1);
236 241
237 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 242 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
238 243
239 MockFetcher mock_fetcher( 244 MockFetcher mock_fetcher(issue_auth_token_source_, status, 0, std::string(),
240 issue_auth_token_source_, status, 0, cookies_, std::string(), 245 net::URLFetcher::GET, &auth);
241 net::URLFetcher::GET, &auth);
242 auth.OnURLFetchComplete(&mock_fetcher); 246 auth.OnURLFetchComplete(&mock_fetcher);
243 } 247 }
244 248
245 249
246 TEST_F(GaiaAuthFetcherTest, ParseRequest) { 250 TEST_F(GaiaAuthFetcherTest, ParseRequest) {
247 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth\n", "sid", "lsid", "auth"); 251 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth\n", "sid", "lsid", "auth");
248 RunParsingTest("LSID=lsid\nSID=sid\nAuth=auth\n", "sid", "lsid", "auth"); 252 RunParsingTest("LSID=lsid\nSID=sid\nAuth=auth\n", "sid", "lsid", "auth");
249 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth", "sid", "lsid", "auth"); 253 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth", "sid", "lsid", "auth");
250 RunParsingTest("SID=sid\nAuth=auth\n", "sid", std::string(), "auth"); 254 RunParsingTest("SID=sid\nAuth=auth\n", "sid", std::string(), "auth");
251 RunParsingTest("LSID=lsid\nAuth=auth\n", std::string(), "lsid", "auth"); 255 RunParsingTest("LSID=lsid\nAuth=auth\n", std::string(), "lsid", "auth");
(...skipping 16 matching lines...) Expand all
268 "CaptchaUrl=C\n", "E", "U", "C", "T"); 272 "CaptchaUrl=C\n", "E", "U", "C", "T");
269 } 273 }
270 274
271 TEST_F(GaiaAuthFetcherTest, WorkingIssueAuthToken) { 275 TEST_F(GaiaAuthFetcherTest, WorkingIssueAuthToken) {
272 MockGaiaConsumer consumer; 276 MockGaiaConsumer consumer;
273 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess(_, "token")) 277 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess(_, "token"))
274 .Times(1); 278 .Times(1);
275 279
276 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 280 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
277 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 281 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
278 MockFetcher mock_fetcher( 282 MockFetcher mock_fetcher(issue_auth_token_source_, status, net::HTTP_OK,
279 issue_auth_token_source_, status, net::HTTP_OK, cookies_, "token", 283 "token", net::URLFetcher::GET, &auth);
280 net::URLFetcher::GET, &auth);
281 auth.OnURLFetchComplete(&mock_fetcher); 284 auth.OnURLFetchComplete(&mock_fetcher);
282 } 285 }
283 286
284 TEST_F(GaiaAuthFetcherTest, CheckTwoFactorResponse) { 287 TEST_F(GaiaAuthFetcherTest, CheckTwoFactorResponse) {
285 std::string response = 288 std::string response =
286 base::StringPrintf("Error=BadAuthentication\n%s\n", 289 base::StringPrintf("Error=BadAuthentication\n%s\n",
287 GaiaAuthFetcher::kSecondFactor); 290 GaiaAuthFetcher::kSecondFactor);
288 EXPECT_TRUE(GaiaAuthFetcher::IsSecondFactorSuccess(response)); 291 EXPECT_TRUE(GaiaAuthFetcher::IsSecondFactorSuccess(response));
289 } 292 }
290 293
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess("service", "token")) 360 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess("service", "token"))
358 .Times(1); 361 .Times(1);
359 362
360 net::TestURLFetcherFactory factory; 363 net::TestURLFetcherFactory factory;
361 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 364 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
362 auth.StartIssueAuthToken("sid", "lsid", "service"); 365 auth.StartIssueAuthToken("sid", "lsid", "service");
363 366
364 EXPECT_TRUE(auth.HasPendingFetch()); 367 EXPECT_TRUE(auth.HasPendingFetch());
365 MockFetcher mock_fetcher( 368 MockFetcher mock_fetcher(
366 issue_auth_token_source_, 369 issue_auth_token_source_,
367 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 370 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), net::HTTP_OK,
368 net::HTTP_OK, cookies_, "token", 371 "token", net::URLFetcher::GET, &auth);
369 net::URLFetcher::GET, &auth);
370 auth.OnURLFetchComplete(&mock_fetcher); 372 auth.OnURLFetchComplete(&mock_fetcher);
371 EXPECT_FALSE(auth.HasPendingFetch()); 373 EXPECT_FALSE(auth.HasPendingFetch());
372 } 374 }
373 375
374 TEST_F(GaiaAuthFetcherTest, FullTokenFailure) { 376 TEST_F(GaiaAuthFetcherTest, FullTokenFailure) {
375 MockGaiaConsumer consumer; 377 MockGaiaConsumer consumer;
376 EXPECT_CALL(consumer, OnIssueAuthTokenFailure("service", _)) 378 EXPECT_CALL(consumer, OnIssueAuthTokenFailure("service", _))
377 .Times(1); 379 .Times(1);
378 380
379 net::TestURLFetcherFactory factory; 381 net::TestURLFetcherFactory factory;
380 382
381 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 383 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
382 auth.StartIssueAuthToken("sid", "lsid", "service"); 384 auth.StartIssueAuthToken("sid", "lsid", "service");
383 385
384 EXPECT_TRUE(auth.HasPendingFetch()); 386 EXPECT_TRUE(auth.HasPendingFetch());
385 MockFetcher mock_fetcher( 387 MockFetcher mock_fetcher(
386 issue_auth_token_source_, 388 issue_auth_token_source_,
387 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 389 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
388 net::HTTP_FORBIDDEN, 390 net::HTTP_FORBIDDEN,
389 cookies_,
390 std::string(), 391 std::string(),
391 net::URLFetcher::GET, 392 net::URLFetcher::GET,
392 &auth); 393 &auth);
393 auth.OnURLFetchComplete(&mock_fetcher); 394 auth.OnURLFetchComplete(&mock_fetcher);
394 EXPECT_FALSE(auth.HasPendingFetch()); 395 EXPECT_FALSE(auth.HasPendingFetch());
395 } 396 }
396 397
397 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccess) { 398 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccess) {
398 MockGaiaConsumer consumer; 399 MockGaiaConsumer consumer;
399 EXPECT_CALL(consumer, OnClientOAuthCode("test-code")).Times(0); 400 EXPECT_CALL(consumer, OnClientOAuthCode("test-code")).Times(0);
400 EXPECT_CALL(consumer, OnClientOAuthSuccess( 401 EXPECT_CALL(consumer, OnClientOAuthSuccess(
401 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); 402 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1);
402 403
403 net::TestURLFetcherFactory factory; 404 net::TestURLFetcherFactory factory;
404 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 405 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
405 auth.StartCookieForOAuthLoginTokenExchange("0"); 406 auth.StartCookieForOAuthLoginTokenExchange("0");
406 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); 407 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
407 EXPECT_TRUE(NULL != fetcher); 408 EXPECT_TRUE(NULL != fetcher);
408 EXPECT_EQ(net::LOAD_NORMAL, fetcher->GetLoadFlags()); 409 EXPECT_EQ(net::LOAD_NORMAL, fetcher->GetLoadFlags());
409 EXPECT_EQ(std::string::npos, 410 EXPECT_EQ(std::string::npos,
410 fetcher->GetOriginalURL().query().find("device_type=chrome")); 411 fetcher->GetOriginalURL().query().find("device_type=chrome"));
411 412
412 net::ResponseCookies cookies;
413 cookies.push_back(kGetAuthCodeValidCookie);
414 EXPECT_TRUE(auth.HasPendingFetch()); 413 EXPECT_TRUE(auth.HasPendingFetch());
414 scoped_refptr<net::HttpResponseHeaders> reponse_headers =
415 new net::HttpResponseHeaders("");
416 reponse_headers->AddHeader(CookieStringToHeader(kGetAuthCodeValidCookie));
415 MockFetcher mock_fetcher1( 417 MockFetcher mock_fetcher1(
416 client_login_to_oauth2_source_, 418 client_login_to_oauth2_source_,
417 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 419 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
418 net::HTTP_OK, 420 net::HTTP_OK,
419 cookies,
420 std::string(), 421 std::string(),
421 net::URLFetcher::POST, 422 net::URLFetcher::POST,
422 &auth); 423 &auth);
424 mock_fetcher1.set_response_headers(reponse_headers);
423 auth.OnURLFetchComplete(&mock_fetcher1); 425 auth.OnURLFetchComplete(&mock_fetcher1);
424 EXPECT_TRUE(auth.HasPendingFetch()); 426 EXPECT_TRUE(auth.HasPendingFetch());
425 MockFetcher mock_fetcher2( 427 MockFetcher mock_fetcher2(
426 oauth2_token_source_, 428 oauth2_token_source_,
427 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 429 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), net::HTTP_OK,
428 net::HTTP_OK, cookies_, kGetTokenPairValidResponse, 430 kGetTokenPairValidResponse, net::URLFetcher::POST, &auth);
429 net::URLFetcher::POST, &auth);
430 auth.OnURLFetchComplete(&mock_fetcher2); 431 auth.OnURLFetchComplete(&mock_fetcher2);
431 EXPECT_FALSE(auth.HasPendingFetch()); 432 EXPECT_FALSE(auth.HasPendingFetch());
432 } 433 }
433 434
434 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccessNoTokenFetch) { 435 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccessNoTokenFetch) {
435 MockGaiaConsumer consumer; 436 MockGaiaConsumer consumer;
436 EXPECT_CALL(consumer, OnClientOAuthCode("test-code")).Times(1); 437 EXPECT_CALL(consumer, OnClientOAuthCode("test-code")).Times(1);
437 EXPECT_CALL(consumer, OnClientOAuthSuccess( 438 EXPECT_CALL(consumer, OnClientOAuthSuccess(
438 GaiaAuthConsumer::ClientOAuthResult("", "", 0))).Times(0); 439 GaiaAuthConsumer::ClientOAuthResult("", "", 0))).Times(0);
439 440
440 net::TestURLFetcherFactory factory; 441 net::TestURLFetcherFactory factory;
441 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 442 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
442 auth.StartCookieForOAuthLoginTokenExchange( 443 auth.StartCookieForOAuthLoginTokenExchange(
443 false, "0", "ABCDE_12345", ""); 444 false, "0", "ABCDE_12345", "");
444 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); 445 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
445 EXPECT_TRUE(NULL != fetcher); 446 EXPECT_TRUE(NULL != fetcher);
446 EXPECT_EQ(net::LOAD_NORMAL, fetcher->GetLoadFlags()); 447 EXPECT_EQ(net::LOAD_NORMAL, fetcher->GetLoadFlags());
447 EXPECT_EQ(std::string::npos, 448 EXPECT_EQ(std::string::npos,
448 fetcher->GetOriginalURL().query().find("device_type=chrome")); 449 fetcher->GetOriginalURL().query().find("device_type=chrome"));
449 450
450 net::ResponseCookies cookies; 451 scoped_refptr<net::HttpResponseHeaders> reponse_headers =
451 cookies.push_back(kGetAuthCodeValidCookie); 452 new net::HttpResponseHeaders("");
453 reponse_headers->AddHeader(CookieStringToHeader(kGetAuthCodeValidCookie));
452 EXPECT_TRUE(auth.HasPendingFetch()); 454 EXPECT_TRUE(auth.HasPendingFetch());
453 MockFetcher mock_fetcher1( 455 MockFetcher mock_fetcher1(
454 client_login_to_oauth2_source_, 456 client_login_to_oauth2_source_,
455 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 457 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
456 net::HTTP_OK, 458 net::HTTP_OK,
457 cookies,
458 std::string(), 459 std::string(),
459 net::URLFetcher::POST, 460 net::URLFetcher::POST,
460 &auth); 461 &auth);
462 mock_fetcher1.set_response_headers(reponse_headers);
461 auth.OnURLFetchComplete(&mock_fetcher1); 463 auth.OnURLFetchComplete(&mock_fetcher1);
462 EXPECT_FALSE(auth.HasPendingFetch()); 464 EXPECT_FALSE(auth.HasPendingFetch());
463 } 465 }
464 466
465 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenWithCookies_DeviceId) { 467 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenWithCookies_DeviceId) {
466 MockGaiaConsumer consumer; 468 MockGaiaConsumer consumer;
467 net::TestURLFetcherFactory factory; 469 net::TestURLFetcherFactory factory;
468 std::string expected_device_id("ABCDE-12345"); 470 std::string expected_device_id("ABCDE-12345");
469 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 471 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
470 auth.StartCookieForOAuthLoginTokenExchangeWithDeviceId("0", 472 auth.StartCookieForOAuthLoginTokenExchangeWithDeviceId("0",
(...skipping 12 matching lines...) Expand all
483 485
484 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenClientLoginToOAuth2Failure) { 486 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenClientLoginToOAuth2Failure) {
485 MockGaiaConsumer consumer; 487 MockGaiaConsumer consumer;
486 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) 488 EXPECT_CALL(consumer, OnClientOAuthFailure(_))
487 .Times(1); 489 .Times(1);
488 490
489 net::TestURLFetcherFactory factory; 491 net::TestURLFetcherFactory factory;
490 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 492 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
491 auth.StartCookieForOAuthLoginTokenExchange(std::string()); 493 auth.StartCookieForOAuthLoginTokenExchange(std::string());
492 494
493 net::ResponseCookies cookies;
494 EXPECT_TRUE(auth.HasPendingFetch()); 495 EXPECT_TRUE(auth.HasPendingFetch());
495 MockFetcher mock_fetcher( 496 MockFetcher mock_fetcher(
496 client_login_to_oauth2_source_, 497 client_login_to_oauth2_source_,
497 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 498 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
498 net::HTTP_FORBIDDEN, 499 net::HTTP_FORBIDDEN,
499 cookies,
500 std::string(), 500 std::string(),
501 net::URLFetcher::POST, 501 net::URLFetcher::POST,
502 &auth); 502 &auth);
503 auth.OnURLFetchComplete(&mock_fetcher); 503 auth.OnURLFetchComplete(&mock_fetcher);
504 EXPECT_FALSE(auth.HasPendingFetch()); 504 EXPECT_FALSE(auth.HasPendingFetch());
505 } 505 }
506 506
507 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenOAuth2TokenPairFailure) { 507 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenOAuth2TokenPairFailure) {
508 MockGaiaConsumer consumer; 508 MockGaiaConsumer consumer;
509 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) 509 EXPECT_CALL(consumer, OnClientOAuthFailure(_))
510 .Times(1); 510 .Times(1);
511 511
512 net::TestURLFetcherFactory factory; 512 net::TestURLFetcherFactory factory;
513 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 513 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
514 auth.StartCookieForOAuthLoginTokenExchange(std::string()); 514 auth.StartCookieForOAuthLoginTokenExchange(std::string());
515 515
516 net::ResponseCookies cookies; 516 scoped_refptr<net::HttpResponseHeaders> reponse_headers =
517 cookies.push_back(kGetAuthCodeValidCookie); 517 new net::HttpResponseHeaders("");
518 reponse_headers->AddHeader(CookieStringToHeader(kGetAuthCodeValidCookie));
518 EXPECT_TRUE(auth.HasPendingFetch()); 519 EXPECT_TRUE(auth.HasPendingFetch());
519 MockFetcher mock_fetcher1( 520 MockFetcher mock_fetcher1(
520 client_login_to_oauth2_source_, 521 client_login_to_oauth2_source_,
521 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 522 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
522 net::HTTP_OK, 523 net::HTTP_OK,
523 cookies,
524 std::string(), 524 std::string(),
525 net::URLFetcher::POST, 525 net::URLFetcher::POST,
526 &auth); 526 &auth);
527 mock_fetcher1.set_response_headers(reponse_headers);
527 auth.OnURLFetchComplete(&mock_fetcher1); 528 auth.OnURLFetchComplete(&mock_fetcher1);
528 EXPECT_TRUE(auth.HasPendingFetch()); 529 EXPECT_TRUE(auth.HasPendingFetch());
529 MockFetcher mock_fetcher2( 530 MockFetcher mock_fetcher2(
530 oauth2_token_source_, 531 oauth2_token_source_,
531 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 532 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
532 net::HTTP_FORBIDDEN, 533 net::HTTP_FORBIDDEN,
533 cookies_,
534 std::string(), 534 std::string(),
535 net::URLFetcher::POST, 535 net::URLFetcher::POST,
536 &auth); 536 &auth);
537 auth.OnURLFetchComplete(&mock_fetcher2); 537 auth.OnURLFetchComplete(&mock_fetcher2);
538 EXPECT_FALSE(auth.HasPendingFetch()); 538 EXPECT_FALSE(auth.HasPendingFetch());
539 } 539 }
540 540
541 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) { 541 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) {
542 MockGaiaConsumer consumer; 542 MockGaiaConsumer consumer;
543 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) 543 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>"))
544 .Times(1); 544 .Times(1);
545 545
546 net::TestURLFetcherFactory factory; 546 net::TestURLFetcherFactory factory;
547 547
548 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 548 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
549 auth.StartMergeSession("myubertoken", std::string()); 549 auth.StartMergeSession("myubertoken", std::string());
550 550
551 EXPECT_TRUE(auth.HasPendingFetch()); 551 EXPECT_TRUE(auth.HasPendingFetch());
552 MockFetcher mock_fetcher( 552 MockFetcher mock_fetcher(
553 merge_session_source_, 553 merge_session_source_,
554 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 554 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), net::HTTP_OK,
555 net::HTTP_OK, cookies_, "<html></html>", net::URLFetcher::GET, 555 "<html></html>", net::URLFetcher::GET, &auth);
556 &auth);
557 auth.OnURLFetchComplete(&mock_fetcher); 556 auth.OnURLFetchComplete(&mock_fetcher);
558 EXPECT_FALSE(auth.HasPendingFetch()); 557 EXPECT_FALSE(auth.HasPendingFetch());
559 } 558 }
560 559
561 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccessRedirect) { 560 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccessRedirect) {
562 MockGaiaConsumer consumer; 561 MockGaiaConsumer consumer;
563 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) 562 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>"))
564 .Times(1); 563 .Times(1);
565 564
566 net::TestURLFetcherFactory factory; 565 net::TestURLFetcherFactory factory;
567 566
568 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 567 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
569 auth.StartMergeSession("myubertoken", std::string()); 568 auth.StartMergeSession("myubertoken", std::string());
570 569
571 // Make sure the fetcher created has the expected flags. Set its url() 570 // Make sure the fetcher created has the expected flags. Set its url()
572 // properties to reflect a redirect. 571 // properties to reflect a redirect.
573 net::TestURLFetcher* test_fetcher = factory.GetFetcherByID(0); 572 net::TestURLFetcher* test_fetcher = factory.GetFetcherByID(0);
574 EXPECT_TRUE(test_fetcher != NULL); 573 EXPECT_TRUE(test_fetcher != NULL);
575 EXPECT_TRUE(test_fetcher->GetLoadFlags() == net::LOAD_NORMAL); 574 EXPECT_TRUE(test_fetcher->GetLoadFlags() == net::LOAD_NORMAL);
576 EXPECT_TRUE(auth.HasPendingFetch()); 575 EXPECT_TRUE(auth.HasPendingFetch());
577 576
578 GURL final_url("http://www.google.com/CheckCookie"); 577 GURL final_url("http://www.google.com/CheckCookie");
579 test_fetcher->set_url(final_url); 578 test_fetcher->set_url(final_url);
580 test_fetcher->set_status( 579 test_fetcher->set_status(
581 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); 580 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0));
582 test_fetcher->set_response_code(net::HTTP_OK); 581 test_fetcher->set_response_code(net::HTTP_OK);
583 test_fetcher->set_cookies(cookies_);
584 test_fetcher->SetResponseString("<html></html>"); 582 test_fetcher->SetResponseString("<html></html>");
585 583
586 auth.OnURLFetchComplete(test_fetcher); 584 auth.OnURLFetchComplete(test_fetcher);
587 EXPECT_FALSE(auth.HasPendingFetch()); 585 EXPECT_FALSE(auth.HasPendingFetch());
588 } 586 }
589 587
590 TEST_F(GaiaAuthFetcherTest, UberAuthTokenSuccess) { 588 TEST_F(GaiaAuthFetcherTest, UberAuthTokenSuccess) {
591 MockGaiaConsumer consumer; 589 MockGaiaConsumer consumer;
592 EXPECT_CALL(consumer, OnUberAuthTokenSuccess("uberToken")) 590 EXPECT_CALL(consumer, OnUberAuthTokenSuccess("uberToken"))
593 .Times(1); 591 .Times(1);
594 592
595 net::TestURLFetcherFactory factory; 593 net::TestURLFetcherFactory factory;
596 594
597 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 595 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
598 auth.StartTokenFetchForUberAuthExchange("myAccessToken"); 596 auth.StartTokenFetchForUberAuthExchange("myAccessToken");
599 597
600 EXPECT_TRUE(auth.HasPendingFetch()); 598 EXPECT_TRUE(auth.HasPendingFetch());
601 MockFetcher mock_fetcher( 599 MockFetcher mock_fetcher(
602 uberauth_token_source_, 600 uberauth_token_source_,
603 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 601 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), net::HTTP_OK,
604 net::HTTP_OK, cookies_, "uberToken", net::URLFetcher::POST, 602 "uberToken", net::URLFetcher::POST, &auth);
605 &auth);
606 auth.OnURLFetchComplete(&mock_fetcher); 603 auth.OnURLFetchComplete(&mock_fetcher);
607 EXPECT_FALSE(auth.HasPendingFetch()); 604 EXPECT_FALSE(auth.HasPendingFetch());
608 } 605 }
609 606
610 TEST_F(GaiaAuthFetcherTest, ParseClientLoginToOAuth2Response) { 607 TEST_F(GaiaAuthFetcherTest, ParseClientLoginToOAuth2Response) {
611 { // No cookies. 608 { // No cookies.
612 std::string auth_code; 609 std::string auth_code;
613 net::ResponseCookies cookies; 610 net::ResponseCookies cookies;
614 EXPECT_FALSE(GaiaAuthFetcher::ParseClientLoginToOAuth2Response( 611 EXPECT_FALSE(GaiaAuthFetcher::ParseClientLoginToOAuth2Response(
615 cookies, &auth_code)); 612 cookies, &auth_code));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 result.sid = "sid"; 653 result.sid = "sid";
657 result.token = "auth"; 654 result.token = "auth";
658 result.data = data; 655 result.data = data;
659 656
660 MockGaiaConsumer consumer; 657 MockGaiaConsumer consumer;
661 EXPECT_CALL(consumer, OnClientLoginSuccess(result)) 658 EXPECT_CALL(consumer, OnClientLoginSuccess(result))
662 .Times(1); 659 .Times(1);
663 660
664 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 661 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
665 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 662 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
666 MockFetcher mock_fetcher( 663 MockFetcher mock_fetcher(oauth_login_gurl_, status, net::HTTP_OK, data,
667 oauth_login_gurl_, status, net::HTTP_OK, cookies_, data, 664 net::URLFetcher::GET, &auth);
668 net::URLFetcher::GET, &auth);
669 auth.OnURLFetchComplete(&mock_fetcher); 665 auth.OnURLFetchComplete(&mock_fetcher);
670 } 666 }
671 667
672 TEST_F(GaiaAuthFetcherTest, ListAccounts) { 668 TEST_F(GaiaAuthFetcherTest, ListAccounts) {
673 std::string data("[\"gaia.l.a.r\", [" 669 std::string data("[\"gaia.l.a.r\", ["
674 "[\"gaia.l.a\", 1, \"First Last\", \"user@gmail.com\", " 670 "[\"gaia.l.a\", 1, \"First Last\", \"user@gmail.com\", "
675 "\"//googleusercontent.com/A/B/C/D/photo.jpg\", 1, 1, 0]]]"); 671 "\"//googleusercontent.com/A/B/C/D/photo.jpg\", 1, 1, 0]]]");
676 MockGaiaConsumer consumer; 672 MockGaiaConsumer consumer;
677 EXPECT_CALL(consumer, OnListAccountsSuccess(data)).Times(1); 673 EXPECT_CALL(consumer, OnListAccountsSuccess(data)).Times(1);
678 674
679 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 675 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
680 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 676 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
681 MockFetcher mock_fetcher( 677 MockFetcher mock_fetcher(
682 GaiaUrls::GetInstance()->ListAccountsURLWithSource(std::string()), 678 GaiaUrls::GetInstance()->ListAccountsURLWithSource(std::string()), status,
683 status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); 679 net::HTTP_OK, data, net::URLFetcher::GET, &auth);
684 auth.OnURLFetchComplete(&mock_fetcher); 680 auth.OnURLFetchComplete(&mock_fetcher);
685 } 681 }
686 682
687 TEST_F(GaiaAuthFetcherTest, LogOutSuccess) { 683 TEST_F(GaiaAuthFetcherTest, LogOutSuccess) {
688 MockGaiaConsumer consumer; 684 MockGaiaConsumer consumer;
689 EXPECT_CALL(consumer, OnLogOutSuccess()).Times(1); 685 EXPECT_CALL(consumer, OnLogOutSuccess()).Times(1);
690 686
691 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 687 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
692 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 688 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
693 MockFetcher mock_fetcher( 689 MockFetcher mock_fetcher(
694 GaiaUrls::GetInstance()->LogOutURLWithSource(std::string()), status, 690 GaiaUrls::GetInstance()->LogOutURLWithSource(std::string()), status,
695 net::HTTP_OK, cookies_, std::string(), net::URLFetcher::GET, &auth); 691 net::HTTP_OK, std::string(), net::URLFetcher::GET, &auth);
696 auth.OnURLFetchComplete(&mock_fetcher); 692 auth.OnURLFetchComplete(&mock_fetcher);
697 } 693 }
698 694
699 TEST_F(GaiaAuthFetcherTest, LogOutFailure) { 695 TEST_F(GaiaAuthFetcherTest, LogOutFailure) {
700 int error_no = net::ERR_CONNECTION_RESET; 696 int error_no = net::ERR_CONNECTION_RESET;
701 net::URLRequestStatus status(net::URLRequestStatus::FAILED, error_no); 697 net::URLRequestStatus status(net::URLRequestStatus::FAILED, error_no);
702 698
703 GoogleServiceAuthError expected_error = 699 GoogleServiceAuthError expected_error =
704 GoogleServiceAuthError::FromConnectionError(error_no); 700 GoogleServiceAuthError::FromConnectionError(error_no);
705 MockGaiaConsumer consumer; 701 MockGaiaConsumer consumer;
706 EXPECT_CALL(consumer, OnLogOutFailure(expected_error)).Times(1); 702 EXPECT_CALL(consumer, OnLogOutFailure(expected_error)).Times(1);
707 703
708 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 704 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
709 705
710 MockFetcher mock_fetcher( 706 MockFetcher mock_fetcher(
711 GaiaUrls::GetInstance()->LogOutURLWithSource(std::string()), status, 0, 707 GaiaUrls::GetInstance()->LogOutURLWithSource(std::string()), status, 0,
712 cookies_, std::string(), net::URLFetcher::GET, &auth); 708 std::string(), net::URLFetcher::GET, &auth);
713 auth.OnURLFetchComplete(&mock_fetcher); 709 auth.OnURLFetchComplete(&mock_fetcher);
714 } 710 }
715 711
716 TEST_F(GaiaAuthFetcherTest, GetCheckConnectionInfo) { 712 TEST_F(GaiaAuthFetcherTest, GetCheckConnectionInfo) {
717 std::string data( 713 std::string data(
718 "[{\"carryBackToken\": \"token1\", \"url\": \"http://www.google.com\"}]"); 714 "[{\"carryBackToken\": \"token1\", \"url\": \"http://www.google.com\"}]");
719 MockGaiaConsumer consumer; 715 MockGaiaConsumer consumer;
720 EXPECT_CALL(consumer, OnGetCheckConnectionInfoSuccess(data)).Times(1); 716 EXPECT_CALL(consumer, OnGetCheckConnectionInfoSuccess(data)).Times(1);
721 717
722 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 718 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
723 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 719 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
724 MockFetcher mock_fetcher( 720 MockFetcher mock_fetcher(
725 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource( 721 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource(
726 std::string()), 722 std::string()),
727 status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth); 723 status, net::HTTP_OK, data, net::URLFetcher::GET, &auth);
728 auth.OnURLFetchComplete(&mock_fetcher); 724 auth.OnURLFetchComplete(&mock_fetcher);
729 } 725 }
730 726
731 TEST_F(GaiaAuthFetcherTest, ListIDPSessions) { 727 TEST_F(GaiaAuthFetcherTest, ListIDPSessions) {
732 std::string data("{\"sessions\":[{\"login_hint\":\"abcdefghijklmnop\"}]}"); 728 std::string data("{\"sessions\":[{\"login_hint\":\"abcdefghijklmnop\"}]}");
733 MockGaiaConsumer consumer; 729 MockGaiaConsumer consumer;
734 EXPECT_CALL(consumer, OnListIdpSessionsSuccess("abcdefghijklmnop")).Times(1); 730 EXPECT_CALL(consumer, OnListIdpSessionsSuccess("abcdefghijklmnop")).Times(1);
735 731
736 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 732 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
737 auth.StartListIDPSessions(std::string(), std::string()); 733 auth.StartListIDPSessions(std::string(), std::string());
738 734
739 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 735 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
740 MockFetcher mock_fetcher( 736 MockFetcher mock_fetcher(GaiaUrls::GetInstance()->oauth2_iframe_url(), status,
741 GaiaUrls::GetInstance()->oauth2_iframe_url(), 737 net::HTTP_OK, data, net::URLFetcher::GET, &auth);
742 status, net::HTTP_OK, cookies_, data, net::URLFetcher::GET, &auth);
743 auth.OnURLFetchComplete(&mock_fetcher); 738 auth.OnURLFetchComplete(&mock_fetcher);
744 } 739 }
745 740
746 TEST_F(GaiaAuthFetcherTest, GetTokenResponse) { 741 TEST_F(GaiaAuthFetcherTest, GetTokenResponse) {
747 MockGaiaConsumer consumer; 742 MockGaiaConsumer consumer;
748 EXPECT_CALL(consumer, 743 EXPECT_CALL(consumer,
749 OnGetTokenResponseSuccess( 744 OnGetTokenResponseSuccess(
750 GaiaAuthConsumer::ClientOAuthResult(std::string(), 745 GaiaAuthConsumer::ClientOAuthResult(std::string(),
751 "at1", 746 "at1",
752 3600))).Times(1); 747 3600))).Times(1);
753 748
754 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); 749 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext());
755 auth.StartGetTokenResponse(std::string(), std::string(), std::string()); 750 auth.StartGetTokenResponse(std::string(), std::string(), std::string());
756 751
757 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 752 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
758 MockFetcher mock_fetcher( 753 MockFetcher mock_fetcher(GaiaUrls::GetInstance()->oauth2_iframe_url(), status,
759 GaiaUrls::GetInstance()->oauth2_iframe_url(), 754 net::HTTP_OK, kGetTokenPairValidResponse,
760 status, net::HTTP_OK, cookies_, kGetTokenPairValidResponse, 755 net::URLFetcher::GET, &auth);
761 net::URLFetcher::GET, &auth);
762 auth.OnURLFetchComplete(&mock_fetcher); 756 auth.OnURLFetchComplete(&mock_fetcher);
763 } 757 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698