-
Notifications
You must be signed in to change notification settings - Fork 12
/
nss_octopass-shadow_test.c
170 lines (140 loc) · 4.9 KB
/
nss_octopass-shadow_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* Management linux user and authentication with the organization/team on Github.
Copyright (C) 2017 Tomohisa Oda
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#define OCTOPASS_CONFIG_FILE "test/octopass.conf"
#include <criterion/criterion.h>
#include "nss_octopass-shadow.c"
extern void setup(void);
Test(nss_octopass, getspnam_r, .init = setup)
{
enum nss_status status;
struct spwd spent;
int err = 0;
int buflen = 2048;
char buf[buflen];
const char *name = "linyows";
status = _nss_octopass_getspnam_r(name, &spent, buf, buflen, &err);
cr_assert_eq(err, 0);
cr_assert_eq(status, NSS_STATUS_SUCCESS);
cr_assert_str_eq(spent.sp_namp, "linyows");
cr_assert_str_eq(spent.sp_pwdp, "!!");
cr_assert_eq(spent.sp_lstchg, -1);
cr_assert_eq(spent.sp_min, -1);
cr_assert_eq(spent.sp_max, -1);
cr_assert_eq(spent.sp_warn, -1);
cr_assert_eq(spent.sp_inact, -1);
cr_assert_eq(spent.sp_expire, -1);
cr_assert_eq(spent.sp_flag, ~0ul);
}
Test(nss_octopass, getspnam_r__when_team_member_not_found, .init = setup)
{
enum nss_status status;
struct spwd spent;
int err = 0;
int buflen = 2048;
char buf[buflen];
const char *name = "linyowsno";
status = _nss_octopass_getspnam_r(name, &spent, buf, buflen, &err);
cr_assert_eq(err, ENOENT);
cr_assert_eq(status, NSS_STATUS_NOTFOUND);
}
Test(nss_octopass, spent_list, .init = setup)
{
enum nss_status status;
struct spwd spent;
int err = 0;
unsigned long entry_number = 0;
int buflen = 2048;
char buf[buflen];
status = _nss_octopass_setspent(0);
cr_assert_eq(ent_json_idx, 0);
cr_assert_eq(json_object_size(ent_json_root), 0);
cr_assert_eq(status, NSS_STATUS_SUCCESS);
while (status == NSS_STATUS_SUCCESS) {
entry_number += 1;
status = _nss_octopass_getspent_r(&spent, buf, buflen, &err);
if (status != NSS_STATUS_SUCCESS) {
continue;
}
cr_assert_eq(ent_json_idx, entry_number);
cr_assert_eq(json_is_array(ent_json_root), 1);
cr_assert_eq(status, NSS_STATUS_SUCCESS);
if (strcmp(spent.sp_namp, "linyows") != 0) {
continue;
}
cr_assert_str_eq(spent.sp_namp, "linyows");
cr_assert_str_eq(spent.sp_pwdp, "!!");
cr_assert_eq(spent.sp_lstchg, -1);
cr_assert_eq(spent.sp_min, -1);
cr_assert_eq(spent.sp_max, -1);
cr_assert_eq(spent.sp_warn, -1);
cr_assert_eq(spent.sp_inact, -1);
cr_assert_eq(spent.sp_expire, -1);
cr_assert_eq(spent.sp_flag, ~0ul);
}
status = _nss_octopass_endspent();
cr_assert_eq(ent_json_idx, 0);
cr_assert_eq(ent_json_root, NULL);
cr_assert_eq(status, NSS_STATUS_SUCCESS);
}
Test(nss_octopass, spent_list__when_team_not_exist, .init = setup)
{
putenv("OCTOPASS_TEAM=team_not_exists");
enum nss_status status;
struct spwd spent;
int err = 0;
unsigned long entry_number = 0;
int buflen = 2048;
char buf[buflen];
status = _nss_octopass_setspent(0);
cr_assert_eq(ent_json_idx, 0);
cr_assert_eq(json_object_size(ent_json_root), 0);
cr_assert_eq(status, NSS_STATUS_UNAVAIL);
while (status == NSS_STATUS_SUCCESS) {
entry_number += 1;
status = _nss_octopass_getspent_r(&spent, buf, buflen, &err);
cr_assert_eq(status, NSS_STATUS_UNAVAIL);
cr_assert_eq(ent_json_idx, 0);
cr_assert_eq(ent_json_root, NULL);
}
status = _nss_octopass_endspent();
cr_assert_eq(ent_json_idx, 0);
cr_assert_eq(ent_json_root, NULL);
cr_assert_eq(status, NSS_STATUS_SUCCESS);
clearenv();
}
Test(nss_octopass, spent_list__when_wrong_token, .init = setup)
{
putenv("OCTOPASS_TOKEN=wrong_token");
enum nss_status status;
struct spwd spent;
int err = 0;
unsigned long entry_number = 0;
int buflen = 2048;
char buf[buflen];
status = _nss_octopass_setspent(0);
cr_assert_eq(ent_json_idx, 0);
cr_assert_eq(json_object_size(ent_json_root), 0);
cr_assert_eq(status, NSS_STATUS_UNAVAIL);
while (status == NSS_STATUS_SUCCESS) {
entry_number += 1;
status = _nss_octopass_getspent_r(&spent, buf, buflen, &err);
cr_assert_eq(status, NSS_STATUS_UNAVAIL);
cr_assert_eq(ent_json_idx, 0);
cr_assert_eq(ent_json_root, NULL);
}
status = _nss_octopass_endspent();
cr_assert_eq(ent_json_idx, 0);
cr_assert_eq(ent_json_root, NULL);
cr_assert_eq(status, NSS_STATUS_SUCCESS);
clearenv();
}