OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | 5 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/prefs/testing_pref_service.h" | 8 #include "base/prefs/testing_pref_service.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 // Local State (if the value is an empty string, it will be ignored). | 72 // Local State (if the value is an empty string, it will be ignored). |
73 void SetUpDefaultValues() { | 73 void SetUpDefaultValues() { |
74 cryptohome_library_.reset(chromeos::CryptohomeLibrary::GetTestImpl()); | 74 cryptohome_library_.reset(chromeos::CryptohomeLibrary::GetTestImpl()); |
75 chromeos::CryptohomeLibrary::SetForTest(cryptohome_library_.get()); | 75 chromeos::CryptohomeLibrary::SetForTest(cryptohome_library_.get()); |
76 SetDeviceRefreshTokenInLocalState("device_refresh_token_4_test"); | 76 SetDeviceRefreshTokenInLocalState("device_refresh_token_4_test"); |
77 oauth2_service_.SetRobotAccountIdPolicyValue("service_acct@g.com"); | 77 oauth2_service_.SetRobotAccountIdPolicyValue("service_acct@g.com"); |
78 AssertConsumerTokensAndErrors(0, 0); | 78 AssertConsumerTokensAndErrors(0, 0); |
79 } | 79 } |
80 | 80 |
81 scoped_ptr<OAuth2TokenService::Request> StartTokenRequest() { | 81 scoped_ptr<OAuth2TokenService::Request> StartTokenRequest() { |
82 return oauth2_service_.StartRequest(std::set<std::string>(), &consumer_); | 82 return oauth2_service_.StartRequest( |
83 std::string(), std::set<std::string>(), &consumer_); | |
83 } | 84 } |
84 | 85 |
85 virtual void TearDown() OVERRIDE { | 86 virtual void TearDown() OVERRIDE { |
86 CryptohomeLibrary::SetForTest(NULL); | 87 CryptohomeLibrary::SetForTest(NULL); |
87 base::RunLoop().RunUntilIdle(); | 88 base::RunLoop().RunUntilIdle(); |
88 } | 89 } |
89 | 90 |
90 // Utility method to set a value in Local State for the device refresh token | 91 // Utility method to set a value in Local State for the device refresh token |
91 // (it must have a non-empty value or it won't be used). | 92 // (it must have a non-empty value or it won't be used). |
92 void SetDeviceRefreshTokenInLocalState(const std::string& refresh_token) { | 93 void SetDeviceRefreshTokenInLocalState(const std::string& refresh_token) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 .WillOnce(Return("")); | 156 .WillOnce(Return("")); |
156 EXPECT_CALL(mock_cryptohome_library, | 157 EXPECT_CALL(mock_cryptohome_library, |
157 EncryptWithSystemSalt(StrEq("test-token"))) | 158 EncryptWithSystemSalt(StrEq("test-token"))) |
158 .Times(1) | 159 .Times(1) |
159 .WillOnce(Return("encrypted")); | 160 .WillOnce(Return("encrypted")); |
160 EXPECT_CALL(mock_cryptohome_library, | 161 EXPECT_CALL(mock_cryptohome_library, |
161 DecryptWithSystemSalt(StrEq("encrypted"))) | 162 DecryptWithSystemSalt(StrEq("encrypted"))) |
162 .Times(1) | 163 .Times(1) |
163 .WillOnce(Return("test-token")); | 164 .WillOnce(Return("test-token")); |
164 | 165 |
165 ASSERT_EQ("", oauth2_service_.GetRefreshToken()); | 166 ASSERT_EQ("", oauth2_service_.GetRefreshToken(std::string())); |
Andrew T Wilson (Slow)
2013/08/30 10:47:00
Would be really nice if DeviceOAuth2TokenService()
fgorski
2013/08/30 20:10:16
Done. Went with GetDeviceAccountId (over ID) for A
| |
166 oauth2_service_.SetAndSaveRefreshToken("test-token"); | 167 oauth2_service_.SetAndSaveRefreshToken("test-token"); |
167 ASSERT_EQ("test-token", oauth2_service_.GetRefreshToken()); | 168 ASSERT_EQ("test-token", oauth2_service_.GetRefreshToken(std::string())); |
168 | 169 |
169 // This call won't invoke decrypt again, since the value is cached. | 170 // This call won't invoke decrypt again, since the value is cached. |
170 ASSERT_EQ("test-token", oauth2_service_.GetRefreshToken()); | 171 ASSERT_EQ("test-token", oauth2_service_.GetRefreshToken(std::string())); |
171 } | 172 } |
172 | 173 |
173 TEST_F(DeviceOAuth2TokenServiceTest, RefreshTokenValidation_Success) { | 174 TEST_F(DeviceOAuth2TokenServiceTest, RefreshTokenValidation_Success) { |
174 SetUpDefaultValues(); | 175 SetUpDefaultValues(); |
175 scoped_ptr<OAuth2TokenService::Request> request = StartTokenRequest(); | 176 scoped_ptr<OAuth2TokenService::Request> request = StartTokenRequest(); |
176 | 177 |
177 ReturnOAuthUrlFetchResults( | 178 ReturnOAuthUrlFetchResults( |
178 kValidatorUrlFetcherId, | 179 kValidatorUrlFetcherId, |
179 net::HTTP_OK, | 180 net::HTTP_OK, |
180 GetValidTokenResponse("tokeninfo_access_token", 3600)); | 181 GetValidTokenResponse("tokeninfo_access_token", 3600)); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 kValidatorUrlFetcherId, | 360 kValidatorUrlFetcherId, |
360 net::HTTP_OK, | 361 net::HTTP_OK, |
361 GetValidTokenInfoResponse("service_acct@g.com")); | 362 GetValidTokenInfoResponse("service_acct@g.com")); |
362 | 363 |
363 // All fetches were successful, but consumer still given error since | 364 // All fetches were successful, but consumer still given error since |
364 // the token owner doesn't match the policy value. | 365 // the token owner doesn't match the policy value. |
365 AssertConsumerTokensAndErrors(0, 1); | 366 AssertConsumerTokensAndErrors(0, 1); |
366 } | 367 } |
367 | 368 |
368 } // namespace chromeos | 369 } // namespace chromeos |
OLD | NEW |