-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstns_shadow_test.c
145 lines (130 loc) · 3.85 KB
/
stns_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
#include "stns_test.h"
Test(ensure_spwd_by_name, ok)
{
char *f = "test/example1.json";
char *json;
int code;
struct spwd spbuf;
char buffer[MAXBUF];
stns_conf_t c;
stns_response_t r;
json = malloc(MAXBUF);
readfile(f, &json);
code = ensure_spwd_by_name(json, &c, "user1", &spbuf, buffer, MAXBUF, 0);
cr_assert_eq(code, NSS_STATUS_SUCCESS);
cr_assert_str_eq(spbuf.sp_namp, "user1");
cr_assert_str_eq(spbuf.sp_pwdp, "test");
cr_assert_eq(spbuf.sp_lstchg, -1);
cr_assert_eq(spbuf.sp_min, -1);
cr_assert_eq(spbuf.sp_max, -1);
cr_assert_eq(spbuf.sp_warn, -1);
cr_assert_eq(spbuf.sp_inact, -1);
cr_assert_eq(spbuf.sp_expire, -1);
cr_assert_eq(spbuf.sp_flag, ~0ul);
readfile(f, &json);
code = ensure_spwd_by_name(json, &c, "user3", &spbuf, buffer, MAXBUF, 0);
cr_assert_eq(code, NSS_STATUS_NOTFOUND);
char *n = malloc(1);
strcpy(n, "");
code = ensure_spwd_by_name(n, &c, "user3", &spbuf, buffer, MAXBUF, 0);
cr_assert_eq(code, NSS_STATUS_UNAVAIL);
free(json);
free(n);
}
Test(ensure_spwd_by_uid, ok)
{
char *f = "test/example1.json";
char *json;
int code;
struct spwd spbuf;
char buffer[MAXBUF];
stns_conf_t c;
stns_response_t r;
c.uid_shift = 0;
json = malloc(MAXBUF);
readfile(f, &json);
code = ensure_spwd_by_uid(json, &c, 1, &spbuf, buffer, MAXBUF, 0);
cr_assert_eq(code, NSS_STATUS_SUCCESS);
cr_assert_str_eq(spbuf.sp_namp, "user1");
cr_assert_str_eq(spbuf.sp_pwdp, "test");
cr_assert_eq(spbuf.sp_lstchg, -1);
cr_assert_eq(spbuf.sp_min, -1);
cr_assert_eq(spbuf.sp_max, -1);
cr_assert_eq(spbuf.sp_warn, -1);
cr_assert_eq(spbuf.sp_inact, -1);
cr_assert_eq(spbuf.sp_expire, -1);
cr_assert_eq(spbuf.sp_flag, ~0ul);
readfile(f, &json);
code = ensure_spwd_by_uid(json, &c, 3, &spbuf, buffer, MAXBUF, 0);
cr_assert_eq(code, NSS_STATUS_NOTFOUND);
char *n = malloc(1);
strcpy(n, "");
code = ensure_spwd_by_uid(n, &c, 3, &spbuf, buffer, MAXBUF, 0);
cr_assert_eq(code, NSS_STATUS_UNAVAIL);
free(json);
free(n);
}
Test(inner_nss_stns_setspent, ok)
{
char *f = "test/example1.json";
char *json;
int code;
struct spwd spbuf;
char buffer[MAXBUF];
stns_conf_t c;
stns_response_t r;
c.uid_shift = 0;
c.gid_shift = 0;
json = malloc(MAXBUF);
readfile(f, &json);
code = inner_nss_stns_setspent(json, &c);
cr_assert_eq(code, NSS_STATUS_SUCCESS);
char *n = malloc(1);
strcpy(n, "");
code = inner_nss_stns_setspent(n, &c);
cr_assert_eq(code, NSS_STATUS_UNAVAIL);
_nss_stns_endspent();
free(n);
free(json);
}
Test(inner_nss_stns_getspent_r, ok)
{
char *f = "test/example1.json";
char *json;
int code;
int errnop = 0;
struct spwd spbuf;
char buffer[MAXBUF];
stns_conf_t c;
stns_response_t r;
json = malloc(MAXBUF);
readfile(f, &json);
code = inner_nss_stns_setspent(json, &c);
cr_assert_eq(code, NSS_STATUS_SUCCESS);
code = inner_nss_stns_getspent_r(&c, &spbuf, buffer, MAXBUF, &errnop);
cr_assert_eq(code, NSS_STATUS_SUCCESS);
cr_assert_str_eq(spbuf.sp_namp, "user1");
cr_assert_str_eq(spbuf.sp_pwdp, "test");
cr_assert_eq(spbuf.sp_lstchg, -1);
cr_assert_eq(spbuf.sp_min, -1);
cr_assert_eq(spbuf.sp_max, -1);
cr_assert_eq(spbuf.sp_warn, -1);
cr_assert_eq(spbuf.sp_inact, -1);
cr_assert_eq(spbuf.sp_expire, -1);
cr_assert_eq(spbuf.sp_flag, ~0ul);
code = inner_nss_stns_getspent_r(&c, &spbuf, buffer, MAXBUF, &errnop);
cr_assert_eq(code, NSS_STATUS_SUCCESS);
cr_assert_str_eq(spbuf.sp_namp, "user2");
cr_assert_str_eq(spbuf.sp_pwdp, "!!");
cr_assert_eq(spbuf.sp_lstchg, -1);
cr_assert_eq(spbuf.sp_min, -1);
cr_assert_eq(spbuf.sp_max, -1);
cr_assert_eq(spbuf.sp_warn, -1);
cr_assert_eq(spbuf.sp_inact, -1);
cr_assert_eq(spbuf.sp_expire, -1);
cr_assert_eq(spbuf.sp_flag, ~0ul);
code = inner_nss_stns_getspent_r(&c, &spbuf, buffer, MAXBUF, &errnop);
cr_assert_eq(code, NSS_STATUS_NOTFOUND);
_nss_stns_endspent();
free(json);
}