| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/login/signed_settings.h" | 5 #include "chrome/browser/chromeos/login/signed_settings.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_temp_dir.h" | 9 #include "base/memory/scoped_temp_dir.h" |
| 10 #include "base/nss_util.h" | 10 #include "base/nss_util.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 scoped_refptr<SignedSettings> s( | 153 scoped_refptr<SignedSettings> s( |
| 154 SignedSettings::CreateStorePropertyOp(fake_prop_, fake_value_, &d)); | 154 SignedSettings::CreateStorePropertyOp(fake_prop_, fake_value_, &d)); |
| 155 d.expect_failure(SignedSettings::MapKeyOpCode(return_code)); | 155 d.expect_failure(SignedSettings::MapKeyOpCode(return_code)); |
| 156 std::string to_sign = base::StringPrintf("%s=%s", | 156 std::string to_sign = base::StringPrintf("%s=%s", |
| 157 fake_prop_.c_str(), | 157 fake_prop_.c_str(), |
| 158 fake_value_.c_str()); | 158 fake_value_.c_str()); |
| 159 mock_service(s.get(), &m_); | 159 mock_service(s.get(), &m_); |
| 160 EXPECT_CALL(m_, StartSigningAttempt(to_sign, _)) | 160 EXPECT_CALL(m_, StartSigningAttempt(to_sign, _)) |
| 161 .Times(1); | 161 .Times(1); |
| 162 EXPECT_CALL(m_, GetStatus(_)) | 162 EXPECT_CALL(m_, GetStatus(_)) |
| 163 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 163 .WillOnce(Return(OwnershipService::OWNERSHIP_USER)); |
| 164 | 164 |
| 165 s->Execute(); | 165 s->Execute(); |
| 166 s->OnKeyOpComplete(return_code, std::vector<uint8>()); | 166 s->OnKeyOpComplete(return_code, std::vector<uint8>()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void FailingRetrievePropertyOp(const OwnerManager::KeyOpCode return_code) { | 169 void FailingRetrievePropertyOp(const OwnerManager::KeyOpCode return_code) { |
| 170 NormalDelegate<std::string> d(fake_value_); | 170 NormalDelegate<std::string> d(fake_value_); |
| 171 scoped_refptr<SignedSettings> s( | 171 scoped_refptr<SignedSettings> s( |
| 172 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); | 172 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); |
| 173 d.expect_failure(SignedSettings::MapKeyOpCode(return_code)); | 173 d.expect_failure(SignedSettings::MapKeyOpCode(return_code)); |
| 174 std::string to_verify = base::StringPrintf("%s=%s", | 174 std::string to_verify = base::StringPrintf("%s=%s", |
| 175 fake_prop_.c_str(), | 175 fake_prop_.c_str(), |
| 176 fake_value_.c_str()); | 176 fake_value_.c_str()); |
| 177 mock_service(s.get(), &m_); | 177 mock_service(s.get(), &m_); |
| 178 EXPECT_CALL(m_, StartVerifyAttempt(to_verify, _, _)) | 178 EXPECT_CALL(m_, StartVerifyAttempt(to_verify, _, _)) |
| 179 .Times(1); | 179 .Times(1); |
| 180 EXPECT_CALL(m_, GetStatus(_)) | 180 EXPECT_CALL(m_, GetStatus(_)) |
| 181 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 181 .WillOnce(Return(OwnershipService::OWNERSHIP_USER)); |
| 182 | 182 |
| 183 s->Execute(); | 183 s->Execute(); |
| 184 s->OnKeyOpComplete(return_code, std::vector<uint8>()); | 184 s->OnKeyOpComplete(return_code, std::vector<uint8>()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void FailingStorePolicyOp(const OwnerManager::KeyOpCode return_code) { | 187 void FailingStorePolicyOp(const OwnerManager::KeyOpCode return_code) { |
| 188 NormalDelegate<bool> d(false); | 188 NormalDelegate<bool> d(false); |
| 189 d.expect_failure(SignedSettings::MapKeyOpCode(return_code)); | 189 d.expect_failure(SignedSettings::MapKeyOpCode(return_code)); |
| 190 | 190 |
| 191 em::PolicyFetchResponse fake_policy; | 191 em::PolicyFetchResponse fake_policy; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 d.expect_success(); | 362 d.expect_success(); |
| 363 scoped_refptr<SignedSettings> s( | 363 scoped_refptr<SignedSettings> s( |
| 364 SignedSettings::CreateStorePropertyOp(fake_prop_, fake_value_, &d)); | 364 SignedSettings::CreateStorePropertyOp(fake_prop_, fake_value_, &d)); |
| 365 std::string to_sign = base::StringPrintf("%s=%s", | 365 std::string to_sign = base::StringPrintf("%s=%s", |
| 366 fake_prop_.c_str(), | 366 fake_prop_.c_str(), |
| 367 fake_value_.c_str()); | 367 fake_value_.c_str()); |
| 368 mock_service(s.get(), &m_); | 368 mock_service(s.get(), &m_); |
| 369 EXPECT_CALL(m_, StartSigningAttempt(to_sign, _)) | 369 EXPECT_CALL(m_, StartSigningAttempt(to_sign, _)) |
| 370 .Times(1); | 370 .Times(1); |
| 371 EXPECT_CALL(m_, GetStatus(_)) | 371 EXPECT_CALL(m_, GetStatus(_)) |
| 372 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 372 .WillOnce(Return(OwnershipService::OWNERSHIP_USER)); |
| 373 | 373 |
| 374 s->Execute(); | 374 s->Execute(); |
| 375 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); | 375 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); |
| 376 message_loop_.RunAllPending(); | 376 message_loop_.RunAllPending(); |
| 377 } | 377 } |
| 378 | 378 |
| 379 TEST_F(SignedSettingsTest, StorePropertyNoKey) { | 379 TEST_F(SignedSettingsTest, StorePropertyNoKey) { |
| 380 FailingStorePropertyOp(OwnerManager::KEY_UNAVAILABLE); | 380 FailingStorePropertyOp(OwnerManager::KEY_UNAVAILABLE); |
| 381 } | 381 } |
| 382 | 382 |
| 383 TEST_F(SignedSettingsTest, StorePropertyFailed) { | 383 TEST_F(SignedSettingsTest, StorePropertyFailed) { |
| 384 FailingStorePropertyOp(OwnerManager::OPERATION_FAILED); | 384 FailingStorePropertyOp(OwnerManager::OPERATION_FAILED); |
| 385 } | 385 } |
| 386 | 386 |
| 387 TEST_F(SignedSettingsTest, RetrieveProperty) { | 387 TEST_F(SignedSettingsTest, RetrieveProperty) { |
| 388 NormalDelegate<std::string> d(fake_value_); | 388 NormalDelegate<std::string> d(fake_value_); |
| 389 d.expect_success(); | 389 d.expect_success(); |
| 390 scoped_refptr<SignedSettings> s( | 390 scoped_refptr<SignedSettings> s( |
| 391 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); | 391 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); |
| 392 std::string to_verify = base::StringPrintf("%s=%s", | 392 std::string to_verify = base::StringPrintf("%s=%s", |
| 393 fake_prop_.c_str(), | 393 fake_prop_.c_str(), |
| 394 fake_value_.c_str()); | 394 fake_value_.c_str()); |
| 395 mock_service(s.get(), &m_); | 395 mock_service(s.get(), &m_); |
| 396 EXPECT_CALL(m_, StartVerifyAttempt(to_verify, _, _)) | 396 EXPECT_CALL(m_, StartVerifyAttempt(to_verify, _, _)) |
| 397 .Times(1); | 397 .Times(1); |
| 398 EXPECT_CALL(m_, GetStatus(_)) | 398 EXPECT_CALL(m_, GetStatus(_)) |
| 399 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 399 .WillOnce(Return(OwnershipService::OWNERSHIP_USER)); |
| 400 | 400 |
| 401 s->Execute(); | 401 s->Execute(); |
| 402 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); | 402 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); |
| 403 } | 403 } |
| 404 | 404 |
| 405 TEST_F(SignedSettingsTest, RetrievePropertyNotFound) { | 405 TEST_F(SignedSettingsTest, RetrievePropertyNotFound) { |
| 406 NormalDelegate<std::string> d(fake_value_); | 406 NormalDelegate<std::string> d(fake_value_); |
| 407 scoped_refptr<SignedSettings> s( | 407 scoped_refptr<SignedSettings> s( |
| 408 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); | 408 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); |
| 409 d.expect_failure(SignedSettings::NOT_FOUND); | 409 d.expect_failure(SignedSettings::NOT_FOUND); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 .Times(1); | 610 .Times(1); |
| 611 | 611 |
| 612 s->Execute(); | 612 s->Execute(); |
| 613 message_loop_.RunAllPending(); | 613 message_loop_.RunAllPending(); |
| 614 UnMockLoginLib(); | 614 UnMockLoginLib(); |
| 615 | 615 |
| 616 s->OnKeyOpComplete(OwnerManager::OPERATION_FAILED, std::vector<uint8>()); | 616 s->OnKeyOpComplete(OwnerManager::OPERATION_FAILED, std::vector<uint8>()); |
| 617 } | 617 } |
| 618 | 618 |
| 619 } // namespace chromeos | 619 } // namespace chromeos |
| OLD | NEW |