| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 // Unit tests for Service | 5 // Unit tests for Service |
| 6 | 6 |
| 7 #include "service.h" | 7 #include "service.h" |
| 8 | 8 |
| 9 #include <base/at_exit.h> | 9 #include <base/at_exit.h> |
| 10 #include <base/platform_thread.h> | 10 #include <base/platform_thread.h> |
| 11 #include <base/file_util.h> | 11 #include <base/file_util.h> |
| 12 #include <gtest/gtest.h> | 12 #include <gtest/gtest.h> |
| 13 | 13 |
| 14 #include "crypto.h" | 14 #include "crypto.h" |
| 15 #include "make_tests.h" | 15 #include "make_tests.h" |
| 16 #include "mock_install_attributes.h" |
| 16 #include "mock_mount.h" | 17 #include "mock_mount.h" |
| 17 #include "mock_tpm.h" | 18 #include "mock_tpm.h" |
| 18 #include "secure_blob.h" | 19 #include "secure_blob.h" |
| 19 #include "username_passkey.h" | 20 #include "username_passkey.h" |
| 20 | 21 |
| 21 namespace cryptohome { | 22 namespace cryptohome { |
| 22 using ::testing::Return; | 23 using ::testing::Return; |
| 23 using ::testing::_; | 24 using ::testing::_; |
| 24 using ::testing::NiceMock; | 25 using ::testing::NiceMock; |
| 25 | 26 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 71 |
| 71 TEST_F(ServiceInterfaceTest, CheckKeySuccessTest) { | 72 TEST_F(ServiceInterfaceTest, CheckKeySuccessTest) { |
| 72 MockMount mount; | 73 MockMount mount; |
| 73 EXPECT_CALL(mount, Init()) | 74 EXPECT_CALL(mount, Init()) |
| 74 .WillOnce(Return(true)); | 75 .WillOnce(Return(true)); |
| 75 EXPECT_CALL(mount, TestCredentials(_)) | 76 EXPECT_CALL(mount, TestCredentials(_)) |
| 76 .WillOnce(Return(true)); | 77 .WillOnce(Return(true)); |
| 77 | 78 |
| 78 Service service; | 79 Service service; |
| 79 service.set_mount(&mount); | 80 service.set_mount(&mount); |
| 81 NiceMock<MockInstallAttributes> attrs; |
| 82 service.set_install_attrs(&attrs); |
| 80 service.set_initialize_tpm(false); | 83 service.set_initialize_tpm(false); |
| 81 service.Initialize(); | 84 service.Initialize(); |
| 82 gboolean out = FALSE; | 85 gboolean out = FALSE; |
| 83 GError *error = NULL; | 86 GError *error = NULL; |
| 84 | 87 |
| 85 char user[] = "chromeos-user"; | 88 char user[] = "chromeos-user"; |
| 86 char key[] = "274146c6e8886a843ddfea373e2dc71b"; | 89 char key[] = "274146c6e8886a843ddfea373e2dc71b"; |
| 87 EXPECT_TRUE(service.CheckKey(user, key, &out, &error)); | 90 EXPECT_TRUE(service.CheckKey(user, key, &out, &error)); |
| 88 EXPECT_TRUE(out); | 91 EXPECT_TRUE(out); |
| 89 } | 92 } |
| 90 | 93 |
| 91 TEST_F(ServiceInterfaceTest, CheckAsyncTestCredentials) { | 94 TEST_F(ServiceInterfaceTest, CheckAsyncTestCredentials) { |
| 92 Mount mount; | 95 Mount mount; |
| 93 NiceMock<MockTpm> tpm; | 96 NiceMock<MockTpm> tpm; |
| 94 mount.get_crypto()->set_tpm(&tpm); | 97 mount.get_crypto()->set_tpm(&tpm); |
| 95 mount.set_shadow_root(kImageDir); | 98 mount.set_shadow_root(kImageDir); |
| 96 mount.set_skel_source(kSkelDir); | 99 mount.set_skel_source(kSkelDir); |
| 97 mount.set_use_tpm(false); | 100 mount.set_use_tpm(false); |
| 98 mount.set_fallback_to_scrypt(true); | 101 mount.set_fallback_to_scrypt(true); |
| 99 | 102 |
| 100 ServiceSubclass service; | 103 ServiceSubclass service; |
| 101 service.set_mount(&mount); | 104 service.set_mount(&mount); |
| 105 NiceMock<MockInstallAttributes> attrs; |
| 106 service.set_install_attrs(&attrs); |
| 102 service.set_initialize_tpm(false); | 107 service.set_initialize_tpm(false); |
| 103 service.Initialize(); | 108 service.Initialize(); |
| 104 | 109 |
| 105 cryptohome::SecureBlob passkey; | 110 cryptohome::SecureBlob passkey; |
| 106 cryptohome::Crypto::PasswordToPasskey(kDefaultUsers[7].password, | 111 cryptohome::Crypto::PasswordToPasskey(kDefaultUsers[7].password, |
| 107 system_salt_, &passkey); | 112 system_salt_, &passkey); |
| 108 std::string passkey_string(static_cast<const char*>(passkey.const_data()), | 113 std::string passkey_string(static_cast<const char*>(passkey.const_data()), |
| 109 passkey.size()); | 114 passkey.size()); |
| 110 | 115 |
| 111 gboolean out = FALSE; | 116 gboolean out = FALSE; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 131 PlatformThread::Sleep(100); | 136 PlatformThread::Sleep(100); |
| 132 } | 137 } |
| 133 EXPECT_TRUE(out); | 138 EXPECT_TRUE(out); |
| 134 } | 139 } |
| 135 | 140 |
| 136 TEST(Standalone, CheckAutoCleanupCallback) { | 141 TEST(Standalone, CheckAutoCleanupCallback) { |
| 137 // Checks that AutoCleanupCallback() is called periodically. | 142 // Checks that AutoCleanupCallback() is called periodically. |
| 138 NiceMock<MockMount> mount; | 143 NiceMock<MockMount> mount; |
| 139 Service service; | 144 Service service; |
| 140 service.set_mount(&mount); | 145 service.set_mount(&mount); |
| 146 NiceMock<MockInstallAttributes> attrs; |
| 147 service.set_install_attrs(&attrs); |
| 141 service.set_initialize_tpm(false); | 148 service.set_initialize_tpm(false); |
| 142 | 149 |
| 143 // Service will schedule periodic clean-ups. Wait a bit and make | 150 // Service will schedule periodic clean-ups. Wait a bit and make |
| 144 // sure that we had at least 3 executed. | 151 // sure that we had at least 3 executed. |
| 145 EXPECT_CALL(mount, DoAutomaticFreeDiskSpaceControl()) | 152 EXPECT_CALL(mount, DoAutomaticFreeDiskSpaceControl()) |
| 146 .Times(::testing::AtLeast(3)); | 153 .Times(::testing::AtLeast(3)); |
| 147 EXPECT_CALL(mount, UpdateUserActivityTimestamp()) | 154 EXPECT_CALL(mount, UpdateUserActivityTimestamp()) |
| 148 .Times(::testing::AtLeast(3)); | 155 .Times(::testing::AtLeast(3)); |
| 149 service.set_auto_cleanup_period(2); // 2ms = 500HZ | 156 service.set_auto_cleanup_period(2); // 2ms = 500HZ |
| 150 service.set_update_user_activity_period(2); // 2 x 5ms = 25HZ | 157 service.set_update_user_activity_period(2); // 2 x 5ms = 25HZ |
| 151 service.Initialize(); | 158 service.Initialize(); |
| 152 PlatformThread::Sleep(100); | 159 PlatformThread::Sleep(100); |
| 153 } | 160 } |
| 154 | 161 |
| 155 } // namespace cryptohome | 162 } // namespace cryptohome |
| OLD | NEW |