| OLD | NEW |
| 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" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 } | 347 } |
| 348 | 348 |
| 349 TEST_F(GaiaAuthFetcherTest, ServiceUnavailableError) { | 349 TEST_F(GaiaAuthFetcherTest, ServiceUnavailableError) { |
| 350 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 350 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 351 std::string data = "Error=ServiceUnavailable\n"; | 351 std::string data = "Error=ServiceUnavailable\n"; |
| 352 GoogleServiceAuthError error = | 352 GoogleServiceAuthError error = |
| 353 GaiaAuthFetcher::GenerateAuthError(data, status); | 353 GaiaAuthFetcher::GenerateAuthError(data, status); |
| 354 EXPECT_EQ(error.state(), GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 354 EXPECT_EQ(error.state(), GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
| 355 } | 355 } |
| 356 | 356 |
| 357 TEST_F(GaiaAuthFetcherTest, FullTokenSuccess) { | |
| 358 MockGaiaConsumer consumer; | |
| 359 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess("service", "token")) | |
| 360 .Times(1); | |
| 361 | |
| 362 net::TestURLFetcherFactory factory; | |
| 363 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | |
| 364 auth.StartIssueAuthToken("sid", "lsid", "service"); | |
| 365 | |
| 366 EXPECT_TRUE(auth.HasPendingFetch()); | |
| 367 MockFetcher mock_fetcher( | |
| 368 issue_auth_token_source_, | |
| 369 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), net::HTTP_OK, | |
| 370 "token", net::URLFetcher::GET, &auth); | |
| 371 auth.OnURLFetchComplete(&mock_fetcher); | |
| 372 EXPECT_FALSE(auth.HasPendingFetch()); | |
| 373 } | |
| 374 | |
| 375 TEST_F(GaiaAuthFetcherTest, FullTokenFailure) { | |
| 376 MockGaiaConsumer consumer; | |
| 377 EXPECT_CALL(consumer, OnIssueAuthTokenFailure("service", _)) | |
| 378 .Times(1); | |
| 379 | |
| 380 net::TestURLFetcherFactory factory; | |
| 381 | |
| 382 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | |
| 383 auth.StartIssueAuthToken("sid", "lsid", "service"); | |
| 384 | |
| 385 EXPECT_TRUE(auth.HasPendingFetch()); | |
| 386 MockFetcher mock_fetcher( | |
| 387 issue_auth_token_source_, | |
| 388 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | |
| 389 net::HTTP_FORBIDDEN, | |
| 390 std::string(), | |
| 391 net::URLFetcher::GET, | |
| 392 &auth); | |
| 393 auth.OnURLFetchComplete(&mock_fetcher); | |
| 394 EXPECT_FALSE(auth.HasPendingFetch()); | |
| 395 } | |
| 396 | |
| 397 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccess) { | 357 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccess) { |
| 398 MockGaiaConsumer consumer; | 358 MockGaiaConsumer consumer; |
| 399 EXPECT_CALL(consumer, OnClientOAuthCode("test-code")).Times(0); | 359 EXPECT_CALL(consumer, OnClientOAuthCode("test-code")).Times(0); |
| 400 EXPECT_CALL(consumer, OnClientOAuthSuccess( | 360 EXPECT_CALL(consumer, OnClientOAuthSuccess( |
| 401 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); | 361 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); |
| 402 | 362 |
| 403 net::TestURLFetcherFactory factory; | 363 net::TestURLFetcherFactory factory; |
| 404 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 364 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 405 auth.StartCookieForOAuthLoginTokenExchange("0"); | 365 auth.StartCookieForOAuthLoginTokenExchange("0"); |
| 406 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 366 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 EXPECT_CALL(consumer, OnGetCheckConnectionInfoSuccess(data)).Times(1); | 676 EXPECT_CALL(consumer, OnGetCheckConnectionInfoSuccess(data)).Times(1); |
| 717 | 677 |
| 718 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 678 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 719 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 679 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 720 MockFetcher mock_fetcher( | 680 MockFetcher mock_fetcher( |
| 721 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource( | 681 GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource( |
| 722 std::string()), | 682 std::string()), |
| 723 status, net::HTTP_OK, data, net::URLFetcher::GET, &auth); | 683 status, net::HTTP_OK, data, net::URLFetcher::GET, &auth); |
| 724 auth.OnURLFetchComplete(&mock_fetcher); | 684 auth.OnURLFetchComplete(&mock_fetcher); |
| 725 } | 685 } |
| 726 | |
| 727 TEST_F(GaiaAuthFetcherTest, ListIDPSessions) { | |
| 728 std::string data("{\"sessions\":[{\"login_hint\":\"abcdefghijklmnop\"}]}"); | |
| 729 MockGaiaConsumer consumer; | |
| 730 EXPECT_CALL(consumer, OnListIdpSessionsSuccess("abcdefghijklmnop")).Times(1); | |
| 731 | |
| 732 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | |
| 733 auth.StartListIDPSessions(std::string(), std::string()); | |
| 734 | |
| 735 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | |
| 736 MockFetcher mock_fetcher(GaiaUrls::GetInstance()->oauth2_iframe_url(), status, | |
| 737 net::HTTP_OK, data, net::URLFetcher::GET, &auth); | |
| 738 auth.OnURLFetchComplete(&mock_fetcher); | |
| 739 } | |
| 740 | |
| 741 TEST_F(GaiaAuthFetcherTest, GetTokenResponse) { | |
| 742 MockGaiaConsumer consumer; | |
| 743 EXPECT_CALL(consumer, | |
| 744 OnGetTokenResponseSuccess( | |
| 745 GaiaAuthConsumer::ClientOAuthResult(std::string(), | |
| 746 "at1", | |
| 747 3600))).Times(1); | |
| 748 | |
| 749 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | |
| 750 auth.StartGetTokenResponse(std::string(), std::string(), std::string()); | |
| 751 | |
| 752 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | |
| 753 MockFetcher mock_fetcher(GaiaUrls::GetInstance()->oauth2_iframe_url(), status, | |
| 754 net::HTTP_OK, kGetTokenPairValidResponse, | |
| 755 net::URLFetcher::GET, &auth); | |
| 756 auth.OnURLFetchComplete(&mock_fetcher); | |
| 757 } | |
| OLD | NEW |