OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Unit tests for UsernamePassword. | |
6 | |
7 #include "pam_offline/authenticator.h" | |
8 | |
9 #include <string.h> // For memset(), memcpy() | |
10 #include <stdlib.h> | |
11 | |
12 #include "gtest/gtest.h" | |
13 #include "pam_offline/authenticator.h" | |
14 #include "pam_offline/username_password.h" | |
15 #include "pam_offline/utils.h" | |
16 | |
17 namespace pam_offline { | |
18 | |
19 using std::string; | |
20 | |
21 const char kImageDir[] = "test_image_dir"; | |
22 const char kFakeUser[] = "testuser@invalid.domain"; | |
23 | |
24 class AuthenticatorTest : public ::testing::Test { }; | |
25 | |
26 TEST(AuthenticatorTest, BadInitTest) { | |
27 // create an authenticator that points to an invalid shadow root | |
28 // and make sure it complains | |
29 Authenticator authn("/dev/null"); | |
30 UsernamePassword up(kFakeUser, strlen(kFakeUser), | |
31 "zero", 4); | |
32 | |
33 EXPECT_EQ(false, authn.Init()); | |
34 EXPECT_EQ(false, authn.TestAllMasterKeys(up)); | |
35 } | |
36 | |
37 TEST(AuthenticatorTest, GoodDecryptTest0) { | |
38 Authenticator authn(kImageDir); | |
39 UsernamePassword up(kFakeUser, strlen(kFakeUser), | |
40 "zero", 4); | |
41 | |
42 EXPECT_EQ(true, authn.Init()); | |
43 EXPECT_EQ(true, authn.TestAllMasterKeys(up)); | |
44 } | |
45 | |
46 TEST(AuthenticatorTest, GoodDecryptTest1) { | |
47 Authenticator authn(kImageDir); | |
48 UsernamePassword up(kFakeUser, strlen(kFakeUser), | |
49 "one", 3); | |
50 | |
51 EXPECT_EQ(true, authn.Init()); | |
52 EXPECT_EQ(true, authn.TestAllMasterKeys(up)); | |
53 } | |
54 | |
55 TEST(AuthenticatorTest, GoodDecryptTest2) { | |
56 Authenticator authn(kImageDir); | |
57 UsernamePassword up(kFakeUser, strlen(kFakeUser), | |
58 "two", 3); | |
59 | |
60 EXPECT_EQ(true, authn.Init()); | |
61 EXPECT_EQ(true, authn.TestAllMasterKeys(up)); | |
62 } | |
63 | |
64 TEST(AuthenticatorTest, BadDecryptTest) { | |
65 Authenticator authn(kImageDir); | |
66 UsernamePassword up(kFakeUser, strlen(kFakeUser), | |
67 "bogus", 5); | |
68 | |
69 EXPECT_EQ(true, authn.Init()); | |
70 EXPECT_EQ(false, authn.TestAllMasterKeys(up)); | |
71 } | |
72 | |
73 } // namespace pam_offline | |
OLD | NEW |