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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 MockFetcher mock_fetcher( | 304 MockFetcher mock_fetcher( |
305 client_login_source_, status, net::HTTP_FORBIDDEN, cookies_, data, | 305 client_login_source_, status, net::HTTP_FORBIDDEN, cookies_, data, |
306 net::URLFetcher::GET, &auth); | 306 net::URLFetcher::GET, &auth); |
307 auth.OnURLFetchComplete(&mock_fetcher); | 307 auth.OnURLFetchComplete(&mock_fetcher); |
308 } | 308 } |
309 | 309 |
310 TEST_F(GaiaAuthFetcherTest, ParseRequest) { | 310 TEST_F(GaiaAuthFetcherTest, ParseRequest) { |
311 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth\n", "sid", "lsid", "auth"); | 311 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth\n", "sid", "lsid", "auth"); |
312 RunParsingTest("LSID=lsid\nSID=sid\nAuth=auth\n", "sid", "lsid", "auth"); | 312 RunParsingTest("LSID=lsid\nSID=sid\nAuth=auth\n", "sid", "lsid", "auth"); |
313 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth", "sid", "lsid", "auth"); | 313 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth", "sid", "lsid", "auth"); |
314 RunParsingTest("SID=sid\nAuth=auth\n", "sid", "", "auth"); | 314 RunParsingTest("SID=sid\nAuth=auth\n", "sid", std::string(), "auth"); |
315 RunParsingTest("LSID=lsid\nAuth=auth\n", "", "lsid", "auth"); | 315 RunParsingTest("LSID=lsid\nAuth=auth\n", std::string(), "lsid", "auth"); |
316 RunParsingTest("\nAuth=auth\n", "", "", "auth"); | 316 RunParsingTest("\nAuth=auth\n", std::string(), std::string(), "auth"); |
317 RunParsingTest("SID=sid", "sid", "", ""); | 317 RunParsingTest("SID=sid", "sid", std::string(), std::string()); |
318 } | 318 } |
319 | 319 |
320 TEST_F(GaiaAuthFetcherTest, ParseErrorRequest) { | 320 TEST_F(GaiaAuthFetcherTest, ParseErrorRequest) { |
321 RunErrorParsingTest("Url=U\n" | 321 RunErrorParsingTest("Url=U\n" |
322 "Error=E\n" | 322 "Error=E\n" |
323 "CaptchaToken=T\n" | 323 "CaptchaToken=T\n" |
324 "CaptchaUrl=C\n", "E", "U", "C", "T"); | 324 "CaptchaUrl=C\n", "E", "U", "C", "T"); |
325 RunErrorParsingTest("CaptchaToken=T\n" | 325 RunErrorParsingTest("CaptchaToken=T\n" |
326 "Error=E\n" | 326 "Error=E\n" |
327 "Url=U\n" | 327 "Url=U\n" |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 net::TestURLFetcherFactory factory; | 581 net::TestURLFetcherFactory factory; |
582 | 582 |
583 GaiaAuthFetcher auth(&consumer, std::string(), | 583 GaiaAuthFetcher auth(&consumer, std::string(), |
584 profile_.GetRequestContext()); | 584 profile_.GetRequestContext()); |
585 auth.StartIssueAuthToken("sid", "lsid", "service"); | 585 auth.StartIssueAuthToken("sid", "lsid", "service"); |
586 | 586 |
587 EXPECT_TRUE(auth.HasPendingFetch()); | 587 EXPECT_TRUE(auth.HasPendingFetch()); |
588 MockFetcher mock_fetcher( | 588 MockFetcher mock_fetcher( |
589 issue_auth_token_source_, | 589 issue_auth_token_source_, |
590 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 590 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
591 net::HTTP_FORBIDDEN, cookies_, "", net::URLFetcher::GET, &auth); | 591 net::HTTP_FORBIDDEN, |
| 592 cookies_, |
| 593 std::string(), |
| 594 net::URLFetcher::GET, |
| 595 &auth); |
592 auth.OnURLFetchComplete(&mock_fetcher); | 596 auth.OnURLFetchComplete(&mock_fetcher); |
593 EXPECT_FALSE(auth.HasPendingFetch()); | 597 EXPECT_FALSE(auth.HasPendingFetch()); |
594 } | 598 } |
595 | 599 |
596 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccess) { | 600 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccess) { |
597 MockGaiaConsumer consumer; | 601 MockGaiaConsumer consumer; |
598 EXPECT_CALL(consumer, OnClientOAuthSuccess( | 602 EXPECT_CALL(consumer, OnClientOAuthSuccess( |
599 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); | 603 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); |
600 | 604 |
601 net::TestURLFetcherFactory factory; | 605 net::TestURLFetcherFactory factory; |
602 GaiaAuthFetcher auth(&consumer, std::string(), | 606 GaiaAuthFetcher auth(&consumer, std::string(), |
603 profile_.GetRequestContext()); | 607 profile_.GetRequestContext()); |
604 auth.StartLsoForOAuthLoginTokenExchange("lso_token"); | 608 auth.StartLsoForOAuthLoginTokenExchange("lso_token"); |
605 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 609 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
606 EXPECT_TRUE(NULL != fetcher); | 610 EXPECT_TRUE(NULL != fetcher); |
607 EXPECT_EQ(net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES, | 611 EXPECT_EQ(net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES, |
608 fetcher->GetLoadFlags()); | 612 fetcher->GetLoadFlags()); |
609 | 613 |
610 net::ResponseCookies cookies; | 614 net::ResponseCookies cookies; |
611 cookies.push_back(kGetAuthCodeValidCookie); | 615 cookies.push_back(kGetAuthCodeValidCookie); |
612 EXPECT_TRUE(auth.HasPendingFetch()); | 616 EXPECT_TRUE(auth.HasPendingFetch()); |
613 MockFetcher mock_fetcher1( | 617 MockFetcher mock_fetcher1( |
614 client_login_to_oauth2_source_, | 618 client_login_to_oauth2_source_, |
615 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 619 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
616 net::HTTP_OK, cookies, "", | 620 net::HTTP_OK, |
617 net::URLFetcher::POST, &auth); | 621 cookies, |
| 622 std::string(), |
| 623 net::URLFetcher::POST, |
| 624 &auth); |
618 auth.OnURLFetchComplete(&mock_fetcher1); | 625 auth.OnURLFetchComplete(&mock_fetcher1); |
619 EXPECT_TRUE(auth.HasPendingFetch()); | 626 EXPECT_TRUE(auth.HasPendingFetch()); |
620 MockFetcher mock_fetcher2( | 627 MockFetcher mock_fetcher2( |
621 oauth2_token_source_, | 628 oauth2_token_source_, |
622 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 629 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
623 net::HTTP_OK, cookies_, kGetTokenPairValidResponse, | 630 net::HTTP_OK, cookies_, kGetTokenPairValidResponse, |
624 net::URLFetcher::POST, &auth); | 631 net::URLFetcher::POST, &auth); |
625 auth.OnURLFetchComplete(&mock_fetcher2); | 632 auth.OnURLFetchComplete(&mock_fetcher2); |
626 EXPECT_FALSE(auth.HasPendingFetch()); | 633 EXPECT_FALSE(auth.HasPendingFetch()); |
627 } | 634 } |
(...skipping 17 matching lines...) Expand all Loading... |
645 net::TestURLFetcherFactory factory; | 652 net::TestURLFetcherFactory factory; |
646 GaiaAuthFetcher auth(&consumer, std::string(), | 653 GaiaAuthFetcher auth(&consumer, std::string(), |
647 profile_.GetRequestContext()); | 654 profile_.GetRequestContext()); |
648 auth.StartLsoForOAuthLoginTokenExchange("lso_token"); | 655 auth.StartLsoForOAuthLoginTokenExchange("lso_token"); |
649 | 656 |
650 net::ResponseCookies cookies; | 657 net::ResponseCookies cookies; |
651 EXPECT_TRUE(auth.HasPendingFetch()); | 658 EXPECT_TRUE(auth.HasPendingFetch()); |
652 MockFetcher mock_fetcher( | 659 MockFetcher mock_fetcher( |
653 client_login_to_oauth2_source_, | 660 client_login_to_oauth2_source_, |
654 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 661 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
655 net::HTTP_FORBIDDEN, cookies, "", | 662 net::HTTP_FORBIDDEN, |
656 net::URLFetcher::POST, &auth); | 663 cookies, |
| 664 std::string(), |
| 665 net::URLFetcher::POST, |
| 666 &auth); |
657 auth.OnURLFetchComplete(&mock_fetcher); | 667 auth.OnURLFetchComplete(&mock_fetcher); |
658 EXPECT_FALSE(auth.HasPendingFetch()); | 668 EXPECT_FALSE(auth.HasPendingFetch()); |
659 } | 669 } |
660 | 670 |
661 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenOAuth2TokenPairFailure) { | 671 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenOAuth2TokenPairFailure) { |
662 MockGaiaConsumer consumer; | 672 MockGaiaConsumer consumer; |
663 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) | 673 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) |
664 .Times(1); | 674 .Times(1); |
665 | 675 |
666 net::TestURLFetcherFactory factory; | 676 net::TestURLFetcherFactory factory; |
667 GaiaAuthFetcher auth(&consumer, std::string(), | 677 GaiaAuthFetcher auth(&consumer, std::string(), |
668 profile_.GetRequestContext()); | 678 profile_.GetRequestContext()); |
669 auth.StartLsoForOAuthLoginTokenExchange("lso_token"); | 679 auth.StartLsoForOAuthLoginTokenExchange("lso_token"); |
670 | 680 |
671 net::ResponseCookies cookies; | 681 net::ResponseCookies cookies; |
672 cookies.push_back(kGetAuthCodeValidCookie); | 682 cookies.push_back(kGetAuthCodeValidCookie); |
673 EXPECT_TRUE(auth.HasPendingFetch()); | 683 EXPECT_TRUE(auth.HasPendingFetch()); |
674 MockFetcher mock_fetcher1( | 684 MockFetcher mock_fetcher1( |
675 client_login_to_oauth2_source_, | 685 client_login_to_oauth2_source_, |
676 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 686 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
677 net::HTTP_OK, cookies, "", | 687 net::HTTP_OK, |
678 net::URLFetcher::POST, &auth); | 688 cookies, |
| 689 std::string(), |
| 690 net::URLFetcher::POST, |
| 691 &auth); |
679 auth.OnURLFetchComplete(&mock_fetcher1); | 692 auth.OnURLFetchComplete(&mock_fetcher1); |
680 EXPECT_TRUE(auth.HasPendingFetch()); | 693 EXPECT_TRUE(auth.HasPendingFetch()); |
681 MockFetcher mock_fetcher2( | 694 MockFetcher mock_fetcher2( |
682 oauth2_token_source_, | 695 oauth2_token_source_, |
683 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), | 696 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), |
684 net::HTTP_FORBIDDEN, cookies_, "", | 697 net::HTTP_FORBIDDEN, |
685 net::URLFetcher::POST, &auth); | 698 cookies_, |
| 699 std::string(), |
| 700 net::URLFetcher::POST, |
| 701 &auth); |
686 auth.OnURLFetchComplete(&mock_fetcher2); | 702 auth.OnURLFetchComplete(&mock_fetcher2); |
687 EXPECT_FALSE(auth.HasPendingFetch()); | 703 EXPECT_FALSE(auth.HasPendingFetch()); |
688 } | 704 } |
689 | 705 |
690 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) { | 706 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) { |
691 MockGaiaConsumer consumer; | 707 MockGaiaConsumer consumer; |
692 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) | 708 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) |
693 .Times(1); | 709 .Times(1); |
694 | 710 |
695 net::TestURLFetcherFactory factory; | 711 net::TestURLFetcherFactory factory; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 factory.set_results(kClientOAuthValidResponse); | 819 factory.set_results(kClientOAuthValidResponse); |
804 | 820 |
805 MockGaiaConsumer consumer; | 821 MockGaiaConsumer consumer; |
806 EXPECT_CALL(consumer, OnClientOAuthSuccess( | 822 EXPECT_CALL(consumer, OnClientOAuthSuccess( |
807 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); | 823 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); |
808 | 824 |
809 GaiaAuthFetcher auth(&consumer, "tests", profile_.GetRequestContext()); | 825 GaiaAuthFetcher auth(&consumer, "tests", profile_.GetRequestContext()); |
810 std::vector<std::string> scopes; | 826 std::vector<std::string> scopes; |
811 scopes.push_back(GaiaUrls::GetInstance()->oauth1_login_scope()); | 827 scopes.push_back(GaiaUrls::GetInstance()->oauth1_login_scope()); |
812 scopes.push_back("https://some.other.scope.com"); | 828 scopes.push_back("https://some.other.scope.com"); |
813 auth.StartClientOAuth("username", "password", scopes, "", "en"); | 829 auth.StartClientOAuth("username", "password", scopes, std::string(), "en"); |
814 | 830 |
815 std::string expected_text = base::StringPrintf( | 831 std::string expected_text = base::StringPrintf( |
816 "{" | 832 "{" |
817 "\"email\": \"username\"," | 833 "\"email\": \"username\"," |
818 "\"password\": \"password\"," | 834 "\"password\": \"password\"," |
819 "\"scopes\": [\"https://www.google.com/accounts/OAuthLogin\"," | 835 "\"scopes\": [\"https://www.google.com/accounts/OAuthLogin\"," |
820 " \"https://some.other.scope.com\"]," | 836 " \"https://some.other.scope.com\"]," |
821 "\"oauth2_client_id\": \"%s\"," | 837 "\"oauth2_client_id\": \"%s\"," |
822 "\"friendly_device_name\": \"tests\"," | 838 "\"friendly_device_name\": \"tests\"," |
823 "\"accepts_challenges\": [\"Captcha\", \"TwoStep\"]," | 839 "\"accepts_challenges\": [\"Captcha\", \"TwoStep\"]," |
(...skipping 11 matching lines...) Expand all Loading... |
835 MockURLFetcherFactory<MockFetcher> factory; | 851 MockURLFetcherFactory<MockFetcher> factory; |
836 factory.set_results(kClientOAuthValidResponse); | 852 factory.set_results(kClientOAuthValidResponse); |
837 | 853 |
838 MockGaiaConsumer consumer; | 854 MockGaiaConsumer consumer; |
839 EXPECT_CALL(consumer, OnClientOAuthSuccess( | 855 EXPECT_CALL(consumer, OnClientOAuthSuccess( |
840 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); | 856 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); |
841 | 857 |
842 GaiaAuthFetcher auth(&consumer, "te\"sts", profile_.GetRequestContext()); | 858 GaiaAuthFetcher auth(&consumer, "te\"sts", profile_.GetRequestContext()); |
843 std::vector<std::string> scopes; | 859 std::vector<std::string> scopes; |
844 scopes.push_back("https://some.\"other.scope.com"); | 860 scopes.push_back("https://some.\"other.scope.com"); |
845 auth.StartClientOAuth("user\"name", "pass\"word", scopes, "", "e\"n"); | 861 auth.StartClientOAuth( |
| 862 "user\"name", "pass\"word", scopes, std::string(), "e\"n"); |
846 | 863 |
847 std::string expected_text = base::StringPrintf( | 864 std::string expected_text = base::StringPrintf( |
848 "{" | 865 "{" |
849 "\"email\": \"user\\\"name\"," | 866 "\"email\": \"user\\\"name\"," |
850 "\"password\": \"pass\\\"word\"," | 867 "\"password\": \"pass\\\"word\"," |
851 "\"scopes\": [\"https://some.\\\"other.scope.com\"]," | 868 "\"scopes\": [\"https://some.\\\"other.scope.com\"]," |
852 "\"oauth2_client_id\": \"%s\"," | 869 "\"oauth2_client_id\": \"%s\"," |
853 "\"friendly_device_name\": \"te\\\"sts\"," | 870 "\"friendly_device_name\": \"te\\\"sts\"," |
854 "\"accepts_challenges\": [\"Captcha\", \"TwoStep\"]," | 871 "\"accepts_challenges\": [\"Captcha\", \"TwoStep\"]," |
855 "\"locale\": \"e\\\"n\"," | 872 "\"locale\": \"e\\\"n\"," |
(...skipping 16 matching lines...) Expand all Loading... |
872 " }" | 889 " }" |
873 "}"); | 890 "}"); |
874 | 891 |
875 MockGaiaConsumer consumer; | 892 MockGaiaConsumer consumer; |
876 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) | 893 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) |
877 .WillOnce(Invoke(ExpectBadAuth)); | 894 .WillOnce(Invoke(ExpectBadAuth)); |
878 | 895 |
879 GaiaAuthFetcher auth(&consumer, "tests", profile_.GetRequestContext()); | 896 GaiaAuthFetcher auth(&consumer, "tests", profile_.GetRequestContext()); |
880 std::vector<std::string> scopes; | 897 std::vector<std::string> scopes; |
881 scopes.push_back(GaiaUrls::GetInstance()->oauth1_login_scope()); | 898 scopes.push_back(GaiaUrls::GetInstance()->oauth1_login_scope()); |
882 auth.StartClientOAuth("username", "password", scopes, "", "en"); | 899 auth.StartClientOAuth("username", "password", scopes, std::string(), "en"); |
883 } | 900 } |
884 | 901 |
885 TEST_F(GaiaAuthFetcherTest, ClientOAuthCaptchaChallenge) { | 902 TEST_F(GaiaAuthFetcherTest, ClientOAuthCaptchaChallenge) { |
886 MockURLFetcherFactory<MockFetcher> factory; | 903 MockURLFetcherFactory<MockFetcher> factory; |
887 factory.set_success(false); | 904 factory.set_success(false); |
888 factory.set_results("{" | 905 factory.set_results("{" |
889 " \"cause\" : \"NeedsAdditional\"," | 906 " \"cause\" : \"NeedsAdditional\"," |
890 " \"fallback\" : {" | 907 " \"fallback\" : {" |
891 " \"name\" : \"Terminating\"," | 908 " \"name\" : \"Terminating\"," |
892 " \"url\" : \"https://www.terminating.com\"" | 909 " \"url\" : \"https://www.terminating.com\"" |
893 " }," | 910 " }," |
894 " \"challenge\" : {" | 911 " \"challenge\" : {" |
895 " \"name\" : \"Captcha\"," | 912 " \"name\" : \"Captcha\"," |
896 " \"image_url\" : \"http://www.image.com/\"," | 913 " \"image_url\" : \"http://www.image.com/\"," |
897 " \"image_width\" : 640," | 914 " \"image_width\" : 640," |
898 " \"image_height\" : 480," | 915 " \"image_height\" : 480," |
899 " \"audio_url\" : \"http://www.audio.com/\"," | 916 " \"audio_url\" : \"http://www.audio.com/\"," |
900 " \"challenge_token\" : \"challengetokenblob\"" | 917 " \"challenge_token\" : \"challengetokenblob\"" |
901 " }" | 918 " }" |
902 "}"); | 919 "}"); |
903 | 920 |
904 MockGaiaConsumer consumer; | 921 MockGaiaConsumer consumer; |
905 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) | 922 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) |
906 .WillOnce(Invoke(ExpectCaptchaChallenge)); | 923 .WillOnce(Invoke(ExpectCaptchaChallenge)); |
907 | 924 |
908 GaiaAuthFetcher auth(&consumer, "tests", profile_.GetRequestContext()); | 925 GaiaAuthFetcher auth(&consumer, "tests", profile_.GetRequestContext()); |
909 std::vector<std::string> scopes; | 926 std::vector<std::string> scopes; |
910 scopes.push_back(GaiaUrls::GetInstance()->oauth1_login_scope()); | 927 scopes.push_back(GaiaUrls::GetInstance()->oauth1_login_scope()); |
911 auth.StartClientOAuth("username", "password", scopes, "", "en"); | 928 auth.StartClientOAuth("username", "password", scopes, std::string(), "en"); |
912 } | 929 } |
913 | 930 |
914 TEST_F(GaiaAuthFetcherTest, ClientOAuthTwoFactorChallenge) { | 931 TEST_F(GaiaAuthFetcherTest, ClientOAuthTwoFactorChallenge) { |
915 MockURLFetcherFactory<MockFetcher> factory; | 932 MockURLFetcherFactory<MockFetcher> factory; |
916 factory.set_success(false); | 933 factory.set_success(false); |
917 factory.set_results("{" | 934 factory.set_results("{" |
918 " \"cause\" : \"NeedsAdditional\"," | 935 " \"cause\" : \"NeedsAdditional\"," |
919 " \"fallback\" : {" | 936 " \"fallback\" : {" |
920 " \"name\" : \"Terminating\"," | 937 " \"name\" : \"Terminating\"," |
921 " \"url\" : \"https://www.terminating.com\"" | 938 " \"url\" : \"https://www.terminating.com\"" |
922 " }," | 939 " }," |
923 " \"challenge\" : {" | 940 " \"challenge\" : {" |
924 " \"name\" : \"TwoStep\"," | 941 " \"name\" : \"TwoStep\"," |
925 " \"prompt_text\" : \"prompt_text\"," | 942 " \"prompt_text\" : \"prompt_text\"," |
926 " \"alternate_text\" : \"alternate_text\"," | 943 " \"alternate_text\" : \"alternate_text\"," |
927 " \"challenge_token\" : \"challengetokenblob\"," | 944 " \"challenge_token\" : \"challengetokenblob\"," |
928 " \"field_length\" : 10" | 945 " \"field_length\" : 10" |
929 " }" | 946 " }" |
930 "}"); | 947 "}"); |
931 | 948 |
932 MockGaiaConsumer consumer; | 949 MockGaiaConsumer consumer; |
933 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) | 950 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) |
934 .WillOnce(Invoke(ExpectTwoFactorChallenge)); | 951 .WillOnce(Invoke(ExpectTwoFactorChallenge)); |
935 | 952 |
936 GaiaAuthFetcher auth(&consumer, "tests", profile_.GetRequestContext()); | 953 GaiaAuthFetcher auth(&consumer, "tests", profile_.GetRequestContext()); |
937 std::vector<std::string> scopes; | 954 std::vector<std::string> scopes; |
938 scopes.push_back(GaiaUrls::GetInstance()->oauth1_login_scope()); | 955 scopes.push_back(GaiaUrls::GetInstance()->oauth1_login_scope()); |
939 auth.StartClientOAuth("username", "password", scopes, "", "en"); | 956 auth.StartClientOAuth("username", "password", scopes, std::string(), "en"); |
940 } | 957 } |
941 | 958 |
942 TEST_F(GaiaAuthFetcherTest, ClientOAuthChallengeSuccess) { | 959 TEST_F(GaiaAuthFetcherTest, ClientOAuthChallengeSuccess) { |
943 MockURLFetcherFactory<MockFetcher> factory; | 960 MockURLFetcherFactory<MockFetcher> factory; |
944 factory.set_results(kClientOAuthValidResponse); | 961 factory.set_results(kClientOAuthValidResponse); |
945 | 962 |
946 MockGaiaConsumer consumer; | 963 MockGaiaConsumer consumer; |
947 EXPECT_CALL(consumer, OnClientOAuthSuccess( | 964 EXPECT_CALL(consumer, OnClientOAuthSuccess( |
948 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(2); | 965 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(2); |
949 | 966 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 .Times(1); | 1035 .Times(1); |
1019 | 1036 |
1020 GaiaAuthFetcher auth(&consumer, std::string(), | 1037 GaiaAuthFetcher auth(&consumer, std::string(), |
1021 profile_.GetRequestContext()); | 1038 profile_.GetRequestContext()); |
1022 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 1039 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
1023 MockFetcher mock_fetcher( | 1040 MockFetcher mock_fetcher( |
1024 oauth_login_gurl_, status, net::HTTP_OK, cookies_, data, | 1041 oauth_login_gurl_, status, net::HTTP_OK, cookies_, data, |
1025 net::URLFetcher::GET, &auth); | 1042 net::URLFetcher::GET, &auth); |
1026 auth.OnURLFetchComplete(&mock_fetcher); | 1043 auth.OnURLFetchComplete(&mock_fetcher); |
1027 } | 1044 } |
OLD | NEW |