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

Side by Side Diff: service_unittest.cc

Issue 6801020: service,cryptohome: wire up lockbox to dbus (Closed)
Patch Set: fix spaces Created 9 years, 8 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
« service.cc ('K') | « service.cc ('k') | 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) 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_mount.h" 16 #include "mock_mount.h"
17 #include "mock_lockbox.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
26 const char kImageDir[] = "test_image_dir"; 27 const char kImageDir[] = "test_image_dir";
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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<MockLockbox> lockbox;
82 service.set_lockbox(&lockbox);
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<MockLockbox> lockbox;
106 service.set_lockbox(&lockbox);
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
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<MockLockbox> lockbox;
147 service.set_lockbox(&lockbox);
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 service.set_auto_cleanup_period(5); // 5ms = 200HZ 154 service.set_auto_cleanup_period(5); // 5ms = 200HZ
148 service.Initialize(); 155 service.Initialize();
149 PlatformThread::Sleep(100); 156 PlatformThread::Sleep(100);
150 } 157 }
151 158
152 } // namespace cryptohome 159 } // namespace cryptohome
OLDNEW
« service.cc ('K') | « service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698