| 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 "cryptohome/service.h" | 7 #include "cryptohome/service.h" |
| 8 | 8 |
| 9 #include <glib.h> | 9 #include <glib.h> |
| 10 #include <gtest/gtest.h> | 10 #include <gtest/gtest.h> |
| 11 | 11 |
| 12 #include "cryptohome/mock_authenticator.h" | 12 #include "cryptohome/mock_mount.h" |
| 13 | 13 |
| 14 namespace cryptohome { | 14 namespace cryptohome { |
| 15 using ::testing::Return; | 15 using ::testing::Return; |
| 16 using ::testing::_; | 16 using ::testing::_; |
| 17 | 17 |
| 18 TEST(ServiceInterfaceTests, CheckKeySuccessTest) { | 18 TEST(ServiceInterfaceTests, CheckKeySuccessTest) { |
| 19 MockAuthenticator *auth = new MockAuthenticator; | 19 MockMount *mount = new MockMount; |
| 20 EXPECT_CALL(*auth, Init()) | 20 EXPECT_CALL(*mount, TestCredentials(_)) |
| 21 .WillOnce(Return(true)); | |
| 22 EXPECT_CALL(*auth, TestAllMasterKeys(_)) | |
| 23 .WillOnce(Return(true)); | 21 .WillOnce(Return(true)); |
| 24 | 22 |
| 25 Service service; | 23 Service service; |
| 24 service.set_mount(mount); // takes ownership. |
| 26 service.Initialize(); | 25 service.Initialize(); |
| 27 service.set_authenticator(auth); // takes ownership. | |
| 28 gboolean out = FALSE; | 26 gboolean out = FALSE; |
| 29 GError *error = NULL; | 27 GError *error = NULL; |
| 30 | 28 |
| 31 char user[] = "chromeos-user"; | 29 char user[] = "chromeos-user"; |
| 32 char key[] = "274146c6e8886a843ddfea373e2dc71b"; | 30 char key[] = "274146c6e8886a843ddfea373e2dc71b"; |
| 33 EXPECT_EQ(TRUE, service.CheckKey(user, key, &out, &error)); | 31 EXPECT_EQ(TRUE, service.CheckKey(user, key, &out, &error)); |
| 34 EXPECT_EQ(TRUE, out); | 32 EXPECT_EQ(TRUE, out); |
| 35 } | 33 } |
| 36 | 34 |
| 37 TEST(ServiceInterfaceTests, NopWrappers) { | |
| 38 Service service; | |
| 39 service.Initialize(); | |
| 40 service.set_mount_command("/bin/true"); | |
| 41 service.set_unmount_command("/bin/true"); | |
| 42 gboolean out = FALSE; | |
| 43 GError *error = NULL; | |
| 44 service.set_is_mounted_command("/bin/true"); | |
| 45 EXPECT_EQ(TRUE, service.IsMounted(&out, &error)); | |
| 46 EXPECT_EQ(TRUE, out); | |
| 47 // Change to false so that we can exercise Mount | |
| 48 // without it failing on a double mount. | |
| 49 service.set_is_mounted_command("/bin/false"); | |
| 50 char user[] = "chromeos-user"; | |
| 51 char key[] = "274146c6e8886a843ddfea373e2dc71b"; | |
| 52 out = FALSE; | |
| 53 EXPECT_EQ(TRUE, service.Mount(user, key, &out, &error)); | |
| 54 EXPECT_EQ(TRUE, out); | |
| 55 // Check double mount detection | |
| 56 service.set_is_mounted_command("/bin/true"); | |
| 57 out = FALSE; | |
| 58 EXPECT_EQ(TRUE, service.Mount(user, key, &out, &error)); | |
| 59 EXPECT_EQ(FALSE, out); | |
| 60 | |
| 61 EXPECT_TRUE(service.Unmount(&out, &error)); | |
| 62 EXPECT_EQ(out, TRUE); | |
| 63 // Check IsMounted tests for unmounting nothing. | |
| 64 service.set_is_mounted_command("/bin/false"); | |
| 65 EXPECT_TRUE(service.Unmount(&out, &error)); | |
| 66 EXPECT_EQ(out, TRUE); | |
| 67 } | |
| 68 | |
| 69 // TODO(wad) setup test fixture to create a temp dir | 35 // TODO(wad) setup test fixture to create a temp dir |
| 70 // touch files on Mount/Unmount/IsMounted and | 36 // touch files on Mount/Unmount/IsMounted and |
| 71 // check for goodness. | 37 // check for goodness. |
| 72 | 38 |
| 73 } // namespace cryptohome | 39 } // namespace cryptohome |
| OLD | NEW |