OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 }; | 123 }; |
124 | 124 |
125 TEST_F(GoogleAuthenticatorTest, SaltToAsciiTest) { | 125 TEST_F(GoogleAuthenticatorTest, SaltToAsciiTest) { |
126 unsigned char fake_salt[8] = { 0 }; | 126 unsigned char fake_salt[8] = { 0 }; |
127 fake_salt[0] = 10; | 127 fake_salt[0] = 10; |
128 fake_salt[1] = 1; | 128 fake_salt[1] = 1; |
129 fake_salt[7] = 10 << 4; | 129 fake_salt[7] = 10 << 4; |
130 std::vector<unsigned char> salt_v(fake_salt, fake_salt + sizeof(fake_salt)); | 130 std::vector<unsigned char> salt_v(fake_salt, fake_salt + sizeof(fake_salt)); |
131 | 131 |
132 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(NULL)); | 132 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(NULL)); |
133 auth->set_system_salt(salt_v); | 133 |
134 ON_CALL(*mock_library_, GetSystemSalt()) | |
135 .WillByDefault(Return(salt_v)); | |
136 EXPECT_CALL(*mock_library_, GetSystemSalt()) | |
137 .Times(1); | |
134 | 138 |
135 EXPECT_EQ("0a010000000000a0", auth->SaltAsAscii()); | 139 EXPECT_EQ("0a010000000000a0", auth->SaltAsAscii()); |
136 } | 140 } |
137 | 141 |
138 TEST_F(GoogleAuthenticatorTest, CheckTwoFactorResponse) { | 142 TEST_F(GoogleAuthenticatorTest, CheckTwoFactorResponse) { |
139 std::string response = | 143 std::string response = |
140 StringPrintf("Error=BadAuthentication\n%s\n", | 144 StringPrintf("Error=BadAuthentication\n%s\n", |
141 GoogleAuthenticator::kSecondFactor); | 145 GoogleAuthenticator::kSecondFactor); |
142 EXPECT_TRUE(GoogleAuthenticator::IsSecondFactorSuccess(response)); | 146 EXPECT_TRUE(GoogleAuthenticator::IsSecondFactorSuccess(response)); |
143 } | 147 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 TEST_F(GoogleAuthenticatorTest, EmailAddressIgnorePlusSuffix) { | 189 TEST_F(GoogleAuthenticatorTest, EmailAddressIgnorePlusSuffix) { |
186 EXPECT_EQ(GoogleAuthenticator::Canonicalize("user+cc@what.com"), | 190 EXPECT_EQ(GoogleAuthenticator::Canonicalize("user+cc@what.com"), |
187 GoogleAuthenticator::Canonicalize("user@what.com")); | 191 GoogleAuthenticator::Canonicalize("user@what.com")); |
188 } | 192 } |
189 | 193 |
190 TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreMultiPlusSuffix) { | 194 TEST_F(GoogleAuthenticatorTest, EmailAddressIgnoreMultiPlusSuffix) { |
191 EXPECT_EQ(GoogleAuthenticator::Canonicalize("user+cc+bcc@what.com"), | 195 EXPECT_EQ(GoogleAuthenticator::Canonicalize("user+cc+bcc@what.com"), |
192 GoogleAuthenticator::Canonicalize("user@what.com")); | 196 GoogleAuthenticator::Canonicalize("user@what.com")); |
193 } | 197 } |
194 | 198 |
195 TEST_F(GoogleAuthenticatorTest, ReadSaltTest) { | |
196 FilePath tmp_file_path = PopulateTempFile(raw_bytes_, sizeof(raw_bytes_)); | |
197 | |
198 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(NULL)); | |
199 auth->LoadSystemSalt(tmp_file_path); | |
200 EXPECT_EQ(auth->SaltAsAscii(), bytes_as_ascii_); | |
201 Delete(tmp_file_path, false); | |
202 } | |
203 | |
204 TEST_F(GoogleAuthenticatorTest, ReadLocalaccountTest) { | 199 TEST_F(GoogleAuthenticatorTest, ReadLocalaccountTest) { |
205 FilePath tmp_file_path = FakeLocalaccountFile(bytes_as_ascii_); | 200 FilePath tmp_file_path = FakeLocalaccountFile(bytes_as_ascii_); |
206 | 201 |
207 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(NULL)); | 202 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(NULL)); |
208 auth->LoadLocalaccount(tmp_file_path.BaseName().value()); | 203 auth->LoadLocalaccount(tmp_file_path.BaseName().value()); |
209 EXPECT_EQ(auth->localaccount_, bytes_as_ascii_); | 204 EXPECT_EQ(auth->localaccount_, bytes_as_ascii_); |
210 Delete(tmp_file_path, false); | 205 Delete(tmp_file_path, false); |
211 } | 206 } |
212 | 207 |
213 TEST_F(GoogleAuthenticatorTest, ReadLocalaccountTrailingWSTest) { | 208 TEST_F(GoogleAuthenticatorTest, ReadLocalaccountTrailingWSTest) { |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 URLFetcher::Delegate* d) { | 425 URLFetcher::Delegate* d) { |
431 return new MockFetcher(url, request_type, d); | 426 return new MockFetcher(url, request_type, d); |
432 } | 427 } |
433 private: | 428 private: |
434 DISALLOW_COPY_AND_ASSIGN(MockFactory); | 429 DISALLOW_COPY_AND_ASSIGN(MockFactory); |
435 }; | 430 }; |
436 | 431 |
437 TEST_F(GoogleAuthenticatorTest, FullLoginTest) { | 432 TEST_F(GoogleAuthenticatorTest, FullLoginTest) { |
438 MessageLoopForUI message_loop; | 433 MessageLoopForUI message_loop; |
439 ChromeThread ui_thread(ChromeThread::UI, &message_loop); | 434 ChromeThread ui_thread(ChromeThread::UI, &message_loop); |
440 ChromeThread file_thread(ChromeThread::FILE); | |
441 file_thread.Start(); | |
442 | |
443 GURL source(AuthResponseHandler::kTokenAuthUrl); | 435 GURL source(AuthResponseHandler::kTokenAuthUrl); |
444 URLRequestStatus status(URLRequestStatus::SUCCESS, 0); | 436 URLRequestStatus status(URLRequestStatus::SUCCESS, 0); |
437 chromeos::CryptohomeBlob salt_v(fake_hash_, fake_hash_ + sizeof(fake_hash_)); | |
445 | 438 |
446 MockConsumer consumer; | 439 MockConsumer consumer; |
447 EXPECT_CALL(consumer, OnLoginSuccess(username_, data_)) | 440 EXPECT_CALL(consumer, OnLoginSuccess(username_, data_)) |
448 .Times(1); | 441 .Times(1); |
449 EXPECT_CALL(*mock_library_, Mount(username_, _)) | 442 EXPECT_CALL(*mock_library_, Mount(username_, _)) |
450 .WillOnce(Return(true)); | 443 .WillOnce(Return(true)); |
451 | 444 |
445 ON_CALL(*mock_library_, GetSystemSalt()) | |
446 .WillByDefault(Return(salt_v)); | |
447 EXPECT_CALL(*mock_library_, GetSystemSalt()) | |
448 .Times(1); | |
449 | |
452 TestingProfile profile; | 450 TestingProfile profile; |
453 | 451 |
454 MockFactory factory; | 452 MockFactory factory; |
455 URLFetcher::set_factory(&factory); | 453 URLFetcher::set_factory(&factory); |
456 std::vector<unsigned char> salt_v(fake_hash_, | |
457 fake_hash_ + sizeof(fake_hash_)); | |
458 | 454 |
459 { | 455 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); |
460 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); | 456 auth->AuthenticateToLogin(&profile, username_, hash_ascii_); |
461 auth->set_system_salt(salt_v); | |
462 | 457 |
463 ChromeThread::PostTask( | |
464 ChromeThread::FILE, FROM_HERE, | |
465 NewRunnableMethod(auth.get(), | |
466 &Authenticator::AuthenticateToLogin, | |
467 &profile, username_, hash_ascii_)); | |
468 | |
469 // The following awkwardness is here to force the above Task to run, | |
470 // then allow all the stuff on the UI thread to go through by calling | |
471 // RunAllPending(), then force |auth| to be destroyed, and then start up | |
472 // the FILE thread again so that the destruction of some objects owned by | |
473 // |auth| can proceed on the FILE thread. If I don't Stop/Start, it seems | |
474 // that Authenticate doesn't happen until after RunAllPending is called. | |
475 file_thread.Stop(); | |
476 file_thread.Start(); | |
477 message_loop.RunAllPending(); | |
478 } | |
479 URLFetcher::set_factory(NULL); | 458 URLFetcher::set_factory(NULL); |
480 file_thread.Stop(); | 459 message_loop.RunAllPending(); |
Nikita (slow)
2010/06/15 11:14:50
Shouldn't these 2 lines be swapped just in case?
O
Chris Masone
2010/06/15 15:46:28
I do want to enforce that no other URLFetcher is c
| |
481 } | 460 } |
482 | 461 |
483 } // namespace chromeos | 462 } // namespace chromeos |
OLD | NEW |