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

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

Issue 11829038: Fix a couple of GaiaAuthFetcherTest tests to work when non-official keys are used. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "google_apis/gaia/gaia_auth_consumer.h" 15 #include "google_apis/gaia/gaia_auth_consumer.h"
16 #include "google_apis/gaia/gaia_auth_fetcher.h" 16 #include "google_apis/gaia/gaia_auth_fetcher.h"
17 #include "google_apis/gaia/gaia_urls.h" 17 #include "google_apis/gaia/gaia_urls.h"
18 #include "google_apis/gaia/google_service_auth_error.h" 18 #include "google_apis/gaia/google_service_auth_error.h"
19 #include "google_apis/gaia/mock_url_fetcher_factory.h" 19 #include "google_apis/gaia/mock_url_fetcher_factory.h"
20 #include "google_apis/google_api_keys.h"
20 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
21 #include "net/base/load_flags.h" 22 #include "net/base/load_flags.h"
22 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
23 #include "net/http/http_status_code.h" 24 #include "net/http/http_status_code.h"
24 #include "net/url_request/test_url_fetcher_factory.h" 25 #include "net/url_request/test_url_fetcher_factory.h"
25 #include "net/url_request/url_fetcher_delegate.h" 26 #include "net/url_request/url_fetcher_delegate.h"
26 #include "net/url_request/url_request_status.h" 27 #include "net/url_request/url_request_status.h"
27 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 30
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 MockGaiaConsumer consumer; 805 MockGaiaConsumer consumer;
805 EXPECT_CALL(consumer, OnClientOAuthSuccess( 806 EXPECT_CALL(consumer, OnClientOAuthSuccess(
806 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); 807 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1);
807 808
808 GaiaAuthFetcher auth(&consumer, "tests", profile_.GetRequestContext()); 809 GaiaAuthFetcher auth(&consumer, "tests", profile_.GetRequestContext());
809 std::vector<std::string> scopes; 810 std::vector<std::string> scopes;
810 scopes.push_back(GaiaUrls::GetInstance()->oauth1_login_scope()); 811 scopes.push_back(GaiaUrls::GetInstance()->oauth1_login_scope());
811 scopes.push_back("https://some.other.scope.com"); 812 scopes.push_back("https://some.other.scope.com");
812 auth.StartClientOAuth("username", "password", scopes, "", "en"); 813 auth.StartClientOAuth("username", "password", scopes, "", "en");
813 814
814 scoped_ptr<base::Value> actual(base::JSONReader::Read(auth.request_body_)); 815 std::string expected_text = base::StringPrintf(
815 scoped_ptr<base::Value> expected(base::JSONReader::Read(
816 "{" 816 "{"
817 "\"email\": \"username\"," 817 "\"email\": \"username\","
818 "\"password\": \"password\"," 818 "\"password\": \"password\","
819 "\"scopes\": [\"https://www.google.com/accounts/OAuthLogin\"," 819 "\"scopes\": [\"https://www.google.com/accounts/OAuthLogin\","
820 " \"https://some.other.scope.com\"]," 820 " \"https://some.other.scope.com\"],"
821 "\"oauth2_client_id\": \"77185425430.apps.googleusercontent.com\"," 821 "\"oauth2_client_id\": \"%s\","
822 "\"friendly_device_name\": \"tests\"," 822 "\"friendly_device_name\": \"tests\","
823 "\"accepts_challenges\": [\"Captcha\", \"TwoStep\"]," 823 "\"accepts_challenges\": [\"Captcha\", \"TwoStep\"],"
824 "\"locale\": \"en\"," 824 "\"locale\": \"en\","
825 "\"fallback\": { \"name\": \"GetOAuth2Token\" }" 825 "\"fallback\": { \"name\": \"GetOAuth2Token\" }"
826 "}")); 826 "}",
827 google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN).c_str());
828
829 scoped_ptr<base::Value> actual(base::JSONReader::Read(auth.request_body_));
830 scoped_ptr<base::Value> expected(base::JSONReader::Read(expected_text));
827 EXPECT_TRUE(expected->Equals(actual.get())); 831 EXPECT_TRUE(expected->Equals(actual.get()));
828 } 832 }
829 833
830 TEST_F(GaiaAuthFetcherTest, ClientOAuthWithQuote) { 834 TEST_F(GaiaAuthFetcherTest, ClientOAuthWithQuote) {
831 MockURLFetcherFactory<MockFetcher> factory; 835 MockURLFetcherFactory<MockFetcher> factory;
832 factory.set_results(kClientOAuthValidResponse); 836 factory.set_results(kClientOAuthValidResponse);
833 837
834 MockGaiaConsumer consumer; 838 MockGaiaConsumer consumer;
835 EXPECT_CALL(consumer, OnClientOAuthSuccess( 839 EXPECT_CALL(consumer, OnClientOAuthSuccess(
836 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); 840 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1);
837 841
838 GaiaAuthFetcher auth(&consumer, "te\"sts", profile_.GetRequestContext()); 842 GaiaAuthFetcher auth(&consumer, "te\"sts", profile_.GetRequestContext());
839 std::vector<std::string> scopes; 843 std::vector<std::string> scopes;
840 scopes.push_back("https://some.\"other.scope.com"); 844 scopes.push_back("https://some.\"other.scope.com");
841 auth.StartClientOAuth("user\"name", "pass\"word", scopes, "", "e\"n"); 845 auth.StartClientOAuth("user\"name", "pass\"word", scopes, "", "e\"n");
842 846
843 scoped_ptr<base::Value> actual(base::JSONReader::Read(auth.request_body_)); 847 std::string expected_text = base::StringPrintf(
844 scoped_ptr<base::Value> expected(base::JSONReader::Read(
845 "{" 848 "{"
846 "\"email\": \"user\\\"name\"," 849 "\"email\": \"user\\\"name\","
847 "\"password\": \"pass\\\"word\"," 850 "\"password\": \"pass\\\"word\","
848 "\"scopes\": [\"https://some.\\\"other.scope.com\"]," 851 "\"scopes\": [\"https://some.\\\"other.scope.com\"],"
849 "\"oauth2_client_id\": \"77185425430.apps.googleusercontent.com\"," 852 "\"oauth2_client_id\": \"%s\","
850 "\"friendly_device_name\": \"te\\\"sts\"," 853 "\"friendly_device_name\": \"te\\\"sts\","
851 "\"accepts_challenges\": [\"Captcha\", \"TwoStep\"]," 854 "\"accepts_challenges\": [\"Captcha\", \"TwoStep\"],"
852 "\"locale\": \"e\\\"n\"," 855 "\"locale\": \"e\\\"n\","
853 "\"fallback\": { \"name\": \"GetOAuth2Token\" }" 856 "\"fallback\": { \"name\": \"GetOAuth2Token\" }"
854 "}")); 857 "}",
858 google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN).c_str());
blundell 2013/01/10 09:12:22 Is this generic enough to handle all of the differ
Jói 2013/01/10 18:46:25 Yes, the interfaces in src/google_api/google_api_k
859 scoped_ptr<base::Value> actual(base::JSONReader::Read(auth.request_body_));
860 scoped_ptr<base::Value> expected(base::JSONReader::Read(expected_text));
855 EXPECT_TRUE(expected->Equals(actual.get())); 861 EXPECT_TRUE(expected->Equals(actual.get()));
856 } 862 }
857 863
858 TEST_F(GaiaAuthFetcherTest, ClientOAuthBadAuth) { 864 TEST_F(GaiaAuthFetcherTest, ClientOAuthBadAuth) {
859 MockURLFetcherFactory<MockFetcher> factory; 865 MockURLFetcherFactory<MockFetcher> factory;
860 factory.set_success(false); 866 factory.set_success(false);
861 factory.set_results("{" 867 factory.set_results("{"
862 " \"cause\" : \"BadAuthentication\"," 868 " \"cause\" : \"BadAuthentication\","
863 " \"fallback\" : {" 869 " \"fallback\" : {"
864 " \"name\" : \"Terminating\"," 870 " \"name\" : \"Terminating\","
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 .Times(1); 1018 .Times(1);
1013 1019
1014 GaiaAuthFetcher auth(&consumer, std::string(), 1020 GaiaAuthFetcher auth(&consumer, std::string(),
1015 profile_.GetRequestContext()); 1021 profile_.GetRequestContext());
1016 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 1022 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
1017 MockFetcher mock_fetcher( 1023 MockFetcher mock_fetcher(
1018 oauth_login_gurl_, status, net::HTTP_OK, cookies_, data, 1024 oauth_login_gurl_, status, net::HTTP_OK, cookies_, data,
1019 net::URLFetcher::GET, &auth); 1025 net::URLFetcher::GET, &auth);
1020 auth.OnURLFetchComplete(&mock_fetcher); 1026 auth.OnURLFetchComplete(&mock_fetcher);
1021 } 1027 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698