1*7f2fe78bSCy Schubert #include <string.h>
2*7f2fe78bSCy Schubert #include <stdlib.h>
3*7f2fe78bSCy Schubert #include <errno.h>
4*7f2fe78bSCy Schubert #include <limits.h>
5*7f2fe78bSCy Schubert #include "test_ccapi_check.h"
6*7f2fe78bSCy Schubert #include "test_ccapi_util.h"
7*7f2fe78bSCy Schubert #include "test_ccapi_context.h"
8*7f2fe78bSCy Schubert #include "test_ccapi_ccache.h"
9*7f2fe78bSCy Schubert
10*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
11*7f2fe78bSCy Schubert
12*7f2fe78bSCy Schubert
check_cc_ccache_release(void)13*7f2fe78bSCy Schubert int check_cc_ccache_release(void) {
14*7f2fe78bSCy Schubert cc_int32 err = 0;
15*7f2fe78bSCy Schubert cc_context_t context = NULL;
16*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
17*7f2fe78bSCy Schubert
18*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_release");
19*7f2fe78bSCy Schubert
20*7f2fe78bSCy Schubert #ifndef cc_ccache_release
21*7f2fe78bSCy Schubert log_error("cc_ccache_release is not implemented yet");
22*7f2fe78bSCy Schubert failure_count++;
23*7f2fe78bSCy Schubert #else
24*7f2fe78bSCy Schubert
25*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
26*7f2fe78bSCy Schubert
27*7f2fe78bSCy Schubert if (!err) {
28*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAR.ORG", &ccache);
29*7f2fe78bSCy Schubert }
30*7f2fe78bSCy Schubert
31*7f2fe78bSCy Schubert
32*7f2fe78bSCy Schubert
33*7f2fe78bSCy Schubert if (!err) {
34*7f2fe78bSCy Schubert check_once_cc_ccache_release(context, ccache, ccNoError, NULL);
35*7f2fe78bSCy Schubert ccache = NULL;
36*7f2fe78bSCy Schubert }
37*7f2fe78bSCy Schubert
38*7f2fe78bSCy Schubert if (context) { cc_context_release(context); }
39*7f2fe78bSCy Schubert
40*7f2fe78bSCy Schubert #endif /* cc_ccache_release */
41*7f2fe78bSCy Schubert
42*7f2fe78bSCy Schubert END_TEST_AND_RETURN
43*7f2fe78bSCy Schubert }
44*7f2fe78bSCy Schubert
check_once_cc_ccache_release(cc_context_t context,cc_ccache_t ccache,cc_int32 expected_err,const char * description)45*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_release(cc_context_t context, cc_ccache_t ccache, cc_int32 expected_err, const char *description) {
46*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
47*7f2fe78bSCy Schubert
48*7f2fe78bSCy Schubert cc_int32 possible_return_values[2] = {
49*7f2fe78bSCy Schubert ccNoError,
50*7f2fe78bSCy Schubert ccErrInvalidCCache,
51*7f2fe78bSCy Schubert };
52*7f2fe78bSCy Schubert
53*7f2fe78bSCy Schubert cc_string_t name = NULL;
54*7f2fe78bSCy Schubert
55*7f2fe78bSCy Schubert err = cc_ccache_get_name(ccache, &name);
56*7f2fe78bSCy Schubert err = cc_ccache_release(ccache);
57*7f2fe78bSCy Schubert ccache = NULL;
58*7f2fe78bSCy Schubert
59*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
60*7f2fe78bSCy Schubert
61*7f2fe78bSCy Schubert #ifdef cc_ccache_release
62*7f2fe78bSCy Schubert
63*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
64*7f2fe78bSCy Schubert
65*7f2fe78bSCy Schubert // check returned error
66*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
67*7f2fe78bSCy Schubert
68*7f2fe78bSCy Schubert if (!err && name) { // try opening released ccache to make sure it still exists
69*7f2fe78bSCy Schubert err = cc_context_open_ccache(context, name->data, &ccache);
70*7f2fe78bSCy Schubert }
71*7f2fe78bSCy Schubert check_if(err == ccErrCCacheNotFound, "released ccache was actually destroyed instead");
72*7f2fe78bSCy Schubert
73*7f2fe78bSCy Schubert if (ccache) { cc_ccache_destroy(ccache); }
74*7f2fe78bSCy Schubert if (name) { cc_string_release(name); }
75*7f2fe78bSCy Schubert
76*7f2fe78bSCy Schubert #endif /* cc_ccache_release */
77*7f2fe78bSCy Schubert
78*7f2fe78bSCy Schubert END_CHECK_ONCE;
79*7f2fe78bSCy Schubert
80*7f2fe78bSCy Schubert return err;
81*7f2fe78bSCy Schubert }
82*7f2fe78bSCy Schubert
83*7f2fe78bSCy Schubert
84*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
85*7f2fe78bSCy Schubert
86*7f2fe78bSCy Schubert
check_cc_ccache_destroy(void)87*7f2fe78bSCy Schubert int check_cc_ccache_destroy(void) {
88*7f2fe78bSCy Schubert cc_int32 err = 0;
89*7f2fe78bSCy Schubert cc_context_t context = NULL;
90*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
91*7f2fe78bSCy Schubert
92*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_destroy");
93*7f2fe78bSCy Schubert
94*7f2fe78bSCy Schubert #ifndef cc_ccache_destroy
95*7f2fe78bSCy Schubert log_error("cc_ccache_destroy is not implemented yet");
96*7f2fe78bSCy Schubert failure_count++;
97*7f2fe78bSCy Schubert #else
98*7f2fe78bSCy Schubert
99*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
100*7f2fe78bSCy Schubert
101*7f2fe78bSCy Schubert if (!err) {
102*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAR.ORG", &ccache);
103*7f2fe78bSCy Schubert }
104*7f2fe78bSCy Schubert
105*7f2fe78bSCy Schubert
106*7f2fe78bSCy Schubert
107*7f2fe78bSCy Schubert if (!err) {
108*7f2fe78bSCy Schubert check_once_cc_ccache_destroy(context, ccache, ccNoError, NULL);
109*7f2fe78bSCy Schubert ccache = NULL;
110*7f2fe78bSCy Schubert }
111*7f2fe78bSCy Schubert
112*7f2fe78bSCy Schubert if (context) { cc_context_release(context); }
113*7f2fe78bSCy Schubert
114*7f2fe78bSCy Schubert #endif /* cc_ccache_destroy */
115*7f2fe78bSCy Schubert
116*7f2fe78bSCy Schubert END_TEST_AND_RETURN
117*7f2fe78bSCy Schubert }
118*7f2fe78bSCy Schubert
check_once_cc_ccache_destroy(cc_context_t context,cc_ccache_t ccache,cc_int32 expected_err,const char * description)119*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_destroy(cc_context_t context, cc_ccache_t ccache, cc_int32 expected_err, const char *description) {
120*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
121*7f2fe78bSCy Schubert
122*7f2fe78bSCy Schubert cc_int32 possible_return_values[2] = {
123*7f2fe78bSCy Schubert ccNoError,
124*7f2fe78bSCy Schubert ccErrInvalidCCache,
125*7f2fe78bSCy Schubert };
126*7f2fe78bSCy Schubert
127*7f2fe78bSCy Schubert cc_string_t name = NULL;
128*7f2fe78bSCy Schubert
129*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
130*7f2fe78bSCy Schubert
131*7f2fe78bSCy Schubert #ifdef cc_ccache_destroy
132*7f2fe78bSCy Schubert
133*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
134*7f2fe78bSCy Schubert
135*7f2fe78bSCy Schubert err = cc_ccache_get_name(ccache, &name);
136*7f2fe78bSCy Schubert err = cc_ccache_destroy(ccache);
137*7f2fe78bSCy Schubert ccache = NULL;
138*7f2fe78bSCy Schubert
139*7f2fe78bSCy Schubert // check returned error
140*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
141*7f2fe78bSCy Schubert
142*7f2fe78bSCy Schubert if (!err && name) { // try opening released ccache to make sure it still exists
143*7f2fe78bSCy Schubert err = cc_context_open_ccache(context, name->data, &ccache);
144*7f2fe78bSCy Schubert }
145*7f2fe78bSCy Schubert check_if(err != ccErrCCacheNotFound, "destroyed ccache was actually released instead");
146*7f2fe78bSCy Schubert
147*7f2fe78bSCy Schubert if (ccache) { cc_ccache_destroy(ccache); }
148*7f2fe78bSCy Schubert if (name) { cc_string_release(name); }
149*7f2fe78bSCy Schubert
150*7f2fe78bSCy Schubert #endif /* cc_ccache_destroy */
151*7f2fe78bSCy Schubert
152*7f2fe78bSCy Schubert END_CHECK_ONCE;
153*7f2fe78bSCy Schubert
154*7f2fe78bSCy Schubert return err;
155*7f2fe78bSCy Schubert }
156*7f2fe78bSCy Schubert
157*7f2fe78bSCy Schubert
158*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
159*7f2fe78bSCy Schubert
160*7f2fe78bSCy Schubert
check_cc_ccache_set_default(void)161*7f2fe78bSCy Schubert int check_cc_ccache_set_default(void) {
162*7f2fe78bSCy Schubert cc_int32 err = 0;
163*7f2fe78bSCy Schubert cc_context_t context = NULL;
164*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
165*7f2fe78bSCy Schubert
166*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_set_default");
167*7f2fe78bSCy Schubert
168*7f2fe78bSCy Schubert #ifndef cc_ccache_set_default
169*7f2fe78bSCy Schubert log_error("cc_ccache_set_default is not implemented yet");
170*7f2fe78bSCy Schubert failure_count++;
171*7f2fe78bSCy Schubert #else
172*7f2fe78bSCy Schubert
173*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
174*7f2fe78bSCy Schubert
175*7f2fe78bSCy Schubert // try when it's the only ccache (already default)
176*7f2fe78bSCy Schubert if (!err) {
177*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
178*7f2fe78bSCy Schubert }
179*7f2fe78bSCy Schubert if (!err) {
180*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAR.ORG", &ccache);
181*7f2fe78bSCy Schubert }
182*7f2fe78bSCy Schubert if (!err) {
183*7f2fe78bSCy Schubert check_once_cc_ccache_set_default(context, ccache, ccNoError, "when it's the only ccache (already default)");
184*7f2fe78bSCy Schubert }
185*7f2fe78bSCy Schubert if (ccache) {
186*7f2fe78bSCy Schubert err = cc_ccache_release(ccache);
187*7f2fe78bSCy Schubert ccache = NULL;
188*7f2fe78bSCy Schubert }
189*7f2fe78bSCy Schubert
190*7f2fe78bSCy Schubert // try when it's not the only ccache (and not default)
191*7f2fe78bSCy Schubert if (!err) {
192*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "baz@BAR.ORG", &ccache);
193*7f2fe78bSCy Schubert }
194*7f2fe78bSCy Schubert if (!err) {
195*7f2fe78bSCy Schubert check_once_cc_ccache_set_default(context, ccache, ccNoError, "when it's not the only ccache (and not default)");
196*7f2fe78bSCy Schubert }
197*7f2fe78bSCy Schubert if (ccache) {
198*7f2fe78bSCy Schubert err = cc_ccache_release(ccache);
199*7f2fe78bSCy Schubert ccache = NULL;
200*7f2fe78bSCy Schubert }
201*7f2fe78bSCy Schubert
202*7f2fe78bSCy Schubert // try when it's not the only ccache (and already default)
203*7f2fe78bSCy Schubert if (!err) {
204*7f2fe78bSCy Schubert err = cc_context_open_default_ccache(context, &ccache);
205*7f2fe78bSCy Schubert }
206*7f2fe78bSCy Schubert if (!err) {
207*7f2fe78bSCy Schubert check_once_cc_ccache_set_default(context, ccache, ccNoError, "when it's not the only ccache (and already default)");
208*7f2fe78bSCy Schubert }
209*7f2fe78bSCy Schubert if (ccache) {
210*7f2fe78bSCy Schubert err = cc_ccache_release(ccache);
211*7f2fe78bSCy Schubert ccache = NULL;
212*7f2fe78bSCy Schubert }
213*7f2fe78bSCy Schubert
214*7f2fe78bSCy Schubert if (!err) {
215*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
216*7f2fe78bSCy Schubert }
217*7f2fe78bSCy Schubert
218*7f2fe78bSCy Schubert if (context) { cc_context_release(context); }
219*7f2fe78bSCy Schubert
220*7f2fe78bSCy Schubert #endif /* cc_ccache_set_default */
221*7f2fe78bSCy Schubert
222*7f2fe78bSCy Schubert END_TEST_AND_RETURN
223*7f2fe78bSCy Schubert }
224*7f2fe78bSCy Schubert
check_once_cc_ccache_set_default(cc_context_t context,cc_ccache_t ccache,cc_int32 expected_err,const char * description)225*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_set_default(cc_context_t context, cc_ccache_t ccache, cc_int32 expected_err, const char *description) {
226*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
227*7f2fe78bSCy Schubert
228*7f2fe78bSCy Schubert cc_int32 possible_return_values[3] = {
229*7f2fe78bSCy Schubert ccNoError,
230*7f2fe78bSCy Schubert ccErrInvalidCCache,
231*7f2fe78bSCy Schubert ccErrCCacheNotFound,
232*7f2fe78bSCy Schubert };
233*7f2fe78bSCy Schubert
234*7f2fe78bSCy Schubert cc_ccache_t default_ccache = NULL;
235*7f2fe78bSCy Schubert cc_string_t name = NULL;
236*7f2fe78bSCy Schubert cc_string_t default_name = NULL;
237*7f2fe78bSCy Schubert
238*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
239*7f2fe78bSCy Schubert
240*7f2fe78bSCy Schubert #ifdef cc_ccache_set_default
241*7f2fe78bSCy Schubert
242*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
243*7f2fe78bSCy Schubert
244*7f2fe78bSCy Schubert err = cc_ccache_set_default(ccache);
245*7f2fe78bSCy Schubert // check returned error
246*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
247*7f2fe78bSCy Schubert
248*7f2fe78bSCy Schubert if (!err) {
249*7f2fe78bSCy Schubert err = cc_ccache_get_name(ccache, &name);
250*7f2fe78bSCy Schubert }
251*7f2fe78bSCy Schubert if (!err) {
252*7f2fe78bSCy Schubert err = cc_context_open_default_ccache(context, &default_ccache);
253*7f2fe78bSCy Schubert }
254*7f2fe78bSCy Schubert if (!err) {
255*7f2fe78bSCy Schubert err = cc_ccache_get_name(default_ccache, &default_name);
256*7f2fe78bSCy Schubert }
257*7f2fe78bSCy Schubert if (name && default_name) {
258*7f2fe78bSCy Schubert check_if(strcmp(name->data, default_name->data), NULL);
259*7f2fe78bSCy Schubert }
260*7f2fe78bSCy Schubert else {
261*7f2fe78bSCy Schubert check_if(1, "cc_ccache_get_name failed");
262*7f2fe78bSCy Schubert }
263*7f2fe78bSCy Schubert
264*7f2fe78bSCy Schubert if (default_ccache) { cc_ccache_release(default_ccache); }
265*7f2fe78bSCy Schubert //if (ccache) { cc_ccache_destroy(ccache); } // ccache is released by the caller
266*7f2fe78bSCy Schubert if (default_name) { cc_string_release(default_name); }
267*7f2fe78bSCy Schubert if (name) { cc_string_release(name); }
268*7f2fe78bSCy Schubert
269*7f2fe78bSCy Schubert #endif /* cc_ccache_set_default */
270*7f2fe78bSCy Schubert
271*7f2fe78bSCy Schubert END_CHECK_ONCE;
272*7f2fe78bSCy Schubert
273*7f2fe78bSCy Schubert return err;
274*7f2fe78bSCy Schubert }
275*7f2fe78bSCy Schubert
276*7f2fe78bSCy Schubert
277*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
278*7f2fe78bSCy Schubert
279*7f2fe78bSCy Schubert
check_cc_ccache_get_credentials_version(void)280*7f2fe78bSCy Schubert int check_cc_ccache_get_credentials_version(void) {
281*7f2fe78bSCy Schubert cc_int32 err = 0;
282*7f2fe78bSCy Schubert cc_context_t context = NULL;
283*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
284*7f2fe78bSCy Schubert
285*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_get_credentials_version");
286*7f2fe78bSCy Schubert
287*7f2fe78bSCy Schubert #ifndef cc_ccache_get_credentials_version
288*7f2fe78bSCy Schubert log_error("cc_ccache_get_credentials_version is not implemented yet");
289*7f2fe78bSCy Schubert failure_count++;
290*7f2fe78bSCy Schubert #else
291*7f2fe78bSCy Schubert
292*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
293*7f2fe78bSCy Schubert
294*7f2fe78bSCy Schubert // try one created with v5 creds
295*7f2fe78bSCy Schubert if (!err) {
296*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAR.ORG", &ccache);
297*7f2fe78bSCy Schubert }
298*7f2fe78bSCy Schubert if (!err) {
299*7f2fe78bSCy Schubert check_once_cc_ccache_get_credentials_version(ccache, cc_credentials_v5, ccNoError, "v5 creds");
300*7f2fe78bSCy Schubert }
301*7f2fe78bSCy Schubert else {
302*7f2fe78bSCy Schubert log_error("cc_context_create_new_ccache failed, can't complete test");
303*7f2fe78bSCy Schubert failure_count++;
304*7f2fe78bSCy Schubert }
305*7f2fe78bSCy Schubert
306*7f2fe78bSCy Schubert if (ccache) {
307*7f2fe78bSCy Schubert cc_ccache_destroy(ccache);
308*7f2fe78bSCy Schubert ccache = NULL;
309*7f2fe78bSCy Schubert }
310*7f2fe78bSCy Schubert
311*7f2fe78bSCy Schubert err = ccNoError;
312*7f2fe78bSCy Schubert
313*7f2fe78bSCy Schubert if (context) { cc_context_release(context); }
314*7f2fe78bSCy Schubert
315*7f2fe78bSCy Schubert #endif /* cc_ccache_get_credentials_version */
316*7f2fe78bSCy Schubert
317*7f2fe78bSCy Schubert END_TEST_AND_RETURN
318*7f2fe78bSCy Schubert }
319*7f2fe78bSCy Schubert
check_once_cc_ccache_get_credentials_version(cc_ccache_t ccache,cc_uint32 expected_cred_vers,cc_int32 expected_err,const char * description)320*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_get_credentials_version(cc_ccache_t ccache, cc_uint32 expected_cred_vers, cc_int32 expected_err, const char *description) {
321*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
322*7f2fe78bSCy Schubert
323*7f2fe78bSCy Schubert cc_int32 possible_return_values[4] = {
324*7f2fe78bSCy Schubert ccNoError,
325*7f2fe78bSCy Schubert ccErrInvalidCCache,
326*7f2fe78bSCy Schubert ccErrBadParam,
327*7f2fe78bSCy Schubert ccErrCCacheNotFound,
328*7f2fe78bSCy Schubert };
329*7f2fe78bSCy Schubert
330*7f2fe78bSCy Schubert cc_uint32 stored_cred_vers = 0;
331*7f2fe78bSCy Schubert
332*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
333*7f2fe78bSCy Schubert
334*7f2fe78bSCy Schubert #ifdef cc_ccache_get_credentials_version
335*7f2fe78bSCy Schubert
336*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
337*7f2fe78bSCy Schubert
338*7f2fe78bSCy Schubert err = cc_ccache_get_credentials_version(ccache, &stored_cred_vers);
339*7f2fe78bSCy Schubert
340*7f2fe78bSCy Schubert // check returned error
341*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
342*7f2fe78bSCy Schubert
343*7f2fe78bSCy Schubert if (!err) {
344*7f2fe78bSCy Schubert check_if(stored_cred_vers != expected_cred_vers, NULL);
345*7f2fe78bSCy Schubert }
346*7f2fe78bSCy Schubert
347*7f2fe78bSCy Schubert #endif /* cc_ccache_get_credentials_version */
348*7f2fe78bSCy Schubert
349*7f2fe78bSCy Schubert END_CHECK_ONCE;
350*7f2fe78bSCy Schubert
351*7f2fe78bSCy Schubert return err;
352*7f2fe78bSCy Schubert }
353*7f2fe78bSCy Schubert
354*7f2fe78bSCy Schubert
355*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
356*7f2fe78bSCy Schubert
357*7f2fe78bSCy Schubert
check_cc_ccache_get_name(void)358*7f2fe78bSCy Schubert int check_cc_ccache_get_name(void) {
359*7f2fe78bSCy Schubert cc_int32 err = 0;
360*7f2fe78bSCy Schubert cc_context_t context = NULL;
361*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
362*7f2fe78bSCy Schubert
363*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_get_name");
364*7f2fe78bSCy Schubert
365*7f2fe78bSCy Schubert #ifndef cc_ccache_get_name
366*7f2fe78bSCy Schubert log_error("cc_ccache_get_name is not implemented yet");
367*7f2fe78bSCy Schubert failure_count++;
368*7f2fe78bSCy Schubert #else
369*7f2fe78bSCy Schubert
370*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
371*7f2fe78bSCy Schubert
372*7f2fe78bSCy Schubert if (!err) {
373*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
374*7f2fe78bSCy Schubert }
375*7f2fe78bSCy Schubert
376*7f2fe78bSCy Schubert // try with unique ccache (which happens to be default)
377*7f2fe78bSCy Schubert if (!err) {
378*7f2fe78bSCy Schubert err = cc_context_create_ccache(context, "0", cc_credentials_v5, "foo@BAR.ORG", &ccache);
379*7f2fe78bSCy Schubert }
380*7f2fe78bSCy Schubert if (!err) {
381*7f2fe78bSCy Schubert check_once_cc_ccache_get_name(ccache, "0", ccNoError, "unique ccache (which happens to be default)");
382*7f2fe78bSCy Schubert }
383*7f2fe78bSCy Schubert else {
384*7f2fe78bSCy Schubert log_error("cc_context_create_ccache failed, can't complete test");
385*7f2fe78bSCy Schubert failure_count++;
386*7f2fe78bSCy Schubert }
387*7f2fe78bSCy Schubert if (ccache) {
388*7f2fe78bSCy Schubert cc_ccache_release(ccache);
389*7f2fe78bSCy Schubert ccache = NULL;
390*7f2fe78bSCy Schubert }
391*7f2fe78bSCy Schubert
392*7f2fe78bSCy Schubert // try with unique ccache (which is not default)
393*7f2fe78bSCy Schubert if (!err) {
394*7f2fe78bSCy Schubert err = cc_context_create_ccache(context, "1", cc_credentials_v5, "foo@BAR.ORG", &ccache);
395*7f2fe78bSCy Schubert }
396*7f2fe78bSCy Schubert if (!err) {
397*7f2fe78bSCy Schubert check_once_cc_ccache_get_name(ccache, "1", ccNoError, "unique ccache (which is not default)");
398*7f2fe78bSCy Schubert }
399*7f2fe78bSCy Schubert else {
400*7f2fe78bSCy Schubert log_error("cc_context_create_ccache failed, can't complete test");
401*7f2fe78bSCy Schubert failure_count++;
402*7f2fe78bSCy Schubert }
403*7f2fe78bSCy Schubert
404*7f2fe78bSCy Schubert // try with bad param
405*7f2fe78bSCy Schubert if (!err) {
406*7f2fe78bSCy Schubert check_once_cc_ccache_get_name(ccache, NULL, ccErrBadParam, "NULL param");
407*7f2fe78bSCy Schubert }
408*7f2fe78bSCy Schubert if (ccache) {
409*7f2fe78bSCy Schubert cc_ccache_release(ccache);
410*7f2fe78bSCy Schubert ccache = NULL;
411*7f2fe78bSCy Schubert }
412*7f2fe78bSCy Schubert
413*7f2fe78bSCy Schubert if (context) {
414*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
415*7f2fe78bSCy Schubert cc_context_release(context);
416*7f2fe78bSCy Schubert }
417*7f2fe78bSCy Schubert
418*7f2fe78bSCy Schubert #endif /* cc_ccache_get_name */
419*7f2fe78bSCy Schubert
420*7f2fe78bSCy Schubert END_TEST_AND_RETURN
421*7f2fe78bSCy Schubert }
422*7f2fe78bSCy Schubert
check_once_cc_ccache_get_name(cc_ccache_t ccache,const char * expected_name,cc_int32 expected_err,const char * description)423*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_get_name(cc_ccache_t ccache, const char *expected_name, cc_int32 expected_err, const char *description) {
424*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
425*7f2fe78bSCy Schubert
426*7f2fe78bSCy Schubert cc_int32 possible_return_values[4] = {
427*7f2fe78bSCy Schubert ccNoError,
428*7f2fe78bSCy Schubert ccErrInvalidCCache,
429*7f2fe78bSCy Schubert ccErrBadParam,
430*7f2fe78bSCy Schubert ccErrCCacheNotFound,
431*7f2fe78bSCy Schubert };
432*7f2fe78bSCy Schubert
433*7f2fe78bSCy Schubert cc_string_t stored_name = NULL;
434*7f2fe78bSCy Schubert
435*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
436*7f2fe78bSCy Schubert
437*7f2fe78bSCy Schubert #ifdef cc_ccache_get_name
438*7f2fe78bSCy Schubert
439*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
440*7f2fe78bSCy Schubert
441*7f2fe78bSCy Schubert if (expected_name == NULL) { // we want to try with a NULL param
442*7f2fe78bSCy Schubert err = cc_ccache_get_name(ccache, NULL);
443*7f2fe78bSCy Schubert }
444*7f2fe78bSCy Schubert else {
445*7f2fe78bSCy Schubert err = cc_ccache_get_name(ccache, &stored_name);
446*7f2fe78bSCy Schubert }
447*7f2fe78bSCy Schubert
448*7f2fe78bSCy Schubert // check returned error
449*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
450*7f2fe78bSCy Schubert
451*7f2fe78bSCy Schubert if (!err) {
452*7f2fe78bSCy Schubert check_if(strcmp(stored_name->data, expected_name), NULL);
453*7f2fe78bSCy Schubert }
454*7f2fe78bSCy Schubert
455*7f2fe78bSCy Schubert if (stored_name) { cc_string_release(stored_name); }
456*7f2fe78bSCy Schubert
457*7f2fe78bSCy Schubert #endif /* cc_ccache_get_name */
458*7f2fe78bSCy Schubert
459*7f2fe78bSCy Schubert END_CHECK_ONCE;
460*7f2fe78bSCy Schubert
461*7f2fe78bSCy Schubert return err;
462*7f2fe78bSCy Schubert }
463*7f2fe78bSCy Schubert
464*7f2fe78bSCy Schubert
465*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
466*7f2fe78bSCy Schubert
check_once_cc_ccache_get_principal(cc_ccache_t ccache,cc_uint32 cred_vers,const char * expected_principal,cc_int32 expected_err,const char * description)467*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_get_principal(cc_ccache_t ccache,
468*7f2fe78bSCy Schubert cc_uint32 cred_vers,
469*7f2fe78bSCy Schubert const char *expected_principal,
470*7f2fe78bSCy Schubert cc_int32 expected_err,
471*7f2fe78bSCy Schubert const char *description) {
472*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
473*7f2fe78bSCy Schubert cc_string_t stored_principal = NULL;
474*7f2fe78bSCy Schubert
475*7f2fe78bSCy Schubert cc_int32 possible_return_values[6] = {
476*7f2fe78bSCy Schubert ccNoError,
477*7f2fe78bSCy Schubert ccErrNoMem,
478*7f2fe78bSCy Schubert ccErrBadCredentialsVersion,
479*7f2fe78bSCy Schubert ccErrBadParam,
480*7f2fe78bSCy Schubert ccErrInvalidCCache,
481*7f2fe78bSCy Schubert ccErrCCacheNotFound,
482*7f2fe78bSCy Schubert };
483*7f2fe78bSCy Schubert
484*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
485*7f2fe78bSCy Schubert
486*7f2fe78bSCy Schubert #ifdef cc_ccache_get_principal
487*7f2fe78bSCy Schubert
488*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
489*7f2fe78bSCy Schubert
490*7f2fe78bSCy Schubert if (expected_principal == NULL) { // we want to try with a NULL param
491*7f2fe78bSCy Schubert err = cc_ccache_get_principal(ccache, cred_vers, NULL);
492*7f2fe78bSCy Schubert }
493*7f2fe78bSCy Schubert else {
494*7f2fe78bSCy Schubert err = cc_ccache_get_principal(ccache, cred_vers, &stored_principal);
495*7f2fe78bSCy Schubert }
496*7f2fe78bSCy Schubert
497*7f2fe78bSCy Schubert // check returned error
498*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
499*7f2fe78bSCy Schubert
500*7f2fe78bSCy Schubert if (!err) {
501*7f2fe78bSCy Schubert check_if(strcmp(stored_principal->data, expected_principal), "expected princ == \"%s\" stored princ == \"%s\"", expected_principal, stored_principal->data);
502*7f2fe78bSCy Schubert }
503*7f2fe78bSCy Schubert
504*7f2fe78bSCy Schubert if (stored_principal) { cc_string_release(stored_principal); }
505*7f2fe78bSCy Schubert
506*7f2fe78bSCy Schubert #endif /* cc_ccache_get_principal */
507*7f2fe78bSCy Schubert
508*7f2fe78bSCy Schubert END_CHECK_ONCE;
509*7f2fe78bSCy Schubert
510*7f2fe78bSCy Schubert return err;
511*7f2fe78bSCy Schubert }
512*7f2fe78bSCy Schubert
513*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
514*7f2fe78bSCy Schubert
check_cc_ccache_get_principal(void)515*7f2fe78bSCy Schubert int check_cc_ccache_get_principal(void) {
516*7f2fe78bSCy Schubert cc_int32 err = 0;
517*7f2fe78bSCy Schubert cc_context_t context = NULL;
518*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
519*7f2fe78bSCy Schubert
520*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_get_principal");
521*7f2fe78bSCy Schubert
522*7f2fe78bSCy Schubert #ifndef cc_ccache_get_principal
523*7f2fe78bSCy Schubert log_error("cc_ccache_get_principal is not implemented yet");
524*7f2fe78bSCy Schubert failure_count++;
525*7f2fe78bSCy Schubert #else
526*7f2fe78bSCy Schubert
527*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
528*7f2fe78bSCy Schubert
529*7f2fe78bSCy Schubert if (!err) {
530*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
531*7f2fe78bSCy Schubert }
532*7f2fe78bSCy Schubert
533*7f2fe78bSCy Schubert // try with krb5 principal
534*7f2fe78bSCy Schubert if (!err) {
535*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo/BAR@BAZ.ORG", &ccache);
536*7f2fe78bSCy Schubert }
537*7f2fe78bSCy Schubert if (!err) {
538*7f2fe78bSCy Schubert check_once_cc_ccache_get_principal(ccache, cc_credentials_v5, "foo/BAR@BAZ.ORG", ccNoError, "trying to get krb5 princ for krb5 ccache");
539*7f2fe78bSCy Schubert }
540*7f2fe78bSCy Schubert else {
541*7f2fe78bSCy Schubert log_error("cc_context_create_new_ccache failed, can't complete test");
542*7f2fe78bSCy Schubert failure_count++;
543*7f2fe78bSCy Schubert }
544*7f2fe78bSCy Schubert
545*7f2fe78bSCy Schubert // try with bad param
546*7f2fe78bSCy Schubert if (!err) {
547*7f2fe78bSCy Schubert check_once_cc_ccache_get_principal(ccache, cc_credentials_v5,
548*7f2fe78bSCy Schubert NULL, ccErrBadParam,
549*7f2fe78bSCy Schubert "passed null out param");
550*7f2fe78bSCy Schubert }
551*7f2fe78bSCy Schubert
552*7f2fe78bSCy Schubert if (ccache) {
553*7f2fe78bSCy Schubert cc_ccache_release(ccache);
554*7f2fe78bSCy Schubert ccache = NULL;
555*7f2fe78bSCy Schubert }
556*7f2fe78bSCy Schubert
557*7f2fe78bSCy Schubert if (context) {
558*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
559*7f2fe78bSCy Schubert cc_context_release(context);
560*7f2fe78bSCy Schubert }
561*7f2fe78bSCy Schubert
562*7f2fe78bSCy Schubert #endif /* cc_ccache_get_principal */
563*7f2fe78bSCy Schubert
564*7f2fe78bSCy Schubert END_TEST_AND_RETURN
565*7f2fe78bSCy Schubert }
566*7f2fe78bSCy Schubert
567*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
568*7f2fe78bSCy Schubert
check_cc_ccache_set_principal(void)569*7f2fe78bSCy Schubert int check_cc_ccache_set_principal(void) {
570*7f2fe78bSCy Schubert cc_int32 err = 0;
571*7f2fe78bSCy Schubert cc_context_t context = NULL;
572*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
573*7f2fe78bSCy Schubert
574*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_set_principal");
575*7f2fe78bSCy Schubert
576*7f2fe78bSCy Schubert #ifndef cc_ccache_set_principal
577*7f2fe78bSCy Schubert log_error("cc_ccache_set_principal is not implemented yet");
578*7f2fe78bSCy Schubert failure_count++;
579*7f2fe78bSCy Schubert #else
580*7f2fe78bSCy Schubert
581*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
582*7f2fe78bSCy Schubert
583*7f2fe78bSCy Schubert if (!err) {
584*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
585*7f2fe78bSCy Schubert }
586*7f2fe78bSCy Schubert
587*7f2fe78bSCy Schubert // replace v5 only ccache's principal
588*7f2fe78bSCy Schubert if (!err) {
589*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5,
590*7f2fe78bSCy Schubert "foo@BAZ.ORG", &ccache);
591*7f2fe78bSCy Schubert }
592*7f2fe78bSCy Schubert if (!err) {
593*7f2fe78bSCy Schubert check_once_cc_ccache_set_principal(
594*7f2fe78bSCy Schubert ccache, cc_credentials_v5, "foo/BAZ@BAR.ORG", ccNoError,
595*7f2fe78bSCy Schubert "replace v5 only ccache's principal (empty ccache)");
596*7f2fe78bSCy Schubert }
597*7f2fe78bSCy Schubert else {
598*7f2fe78bSCy Schubert log_error(
599*7f2fe78bSCy Schubert "cc_context_create_new_ccache failed, can't complete test");
600*7f2fe78bSCy Schubert failure_count++;
601*7f2fe78bSCy Schubert }
602*7f2fe78bSCy Schubert
603*7f2fe78bSCy Schubert // bad params
604*7f2fe78bSCy Schubert if (!err) {
605*7f2fe78bSCy Schubert check_once_cc_ccache_set_principal(ccache, cc_credentials_v5,
606*7f2fe78bSCy Schubert NULL, ccErrBadParam,
607*7f2fe78bSCy Schubert "NULL principal");
608*7f2fe78bSCy Schubert }
609*7f2fe78bSCy Schubert
610*7f2fe78bSCy Schubert if (ccache) {
611*7f2fe78bSCy Schubert cc_ccache_destroy(ccache);
612*7f2fe78bSCy Schubert ccache = NULL;
613*7f2fe78bSCy Schubert }
614*7f2fe78bSCy Schubert
615*7f2fe78bSCy Schubert if (context) {
616*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
617*7f2fe78bSCy Schubert cc_context_release(context);
618*7f2fe78bSCy Schubert }
619*7f2fe78bSCy Schubert
620*7f2fe78bSCy Schubert #endif /* cc_ccache_set_principal */
621*7f2fe78bSCy Schubert
622*7f2fe78bSCy Schubert END_TEST_AND_RETURN
623*7f2fe78bSCy Schubert }
624*7f2fe78bSCy Schubert
check_once_cc_ccache_set_principal(cc_ccache_t ccache,cc_uint32 cred_vers,const char * in_principal,cc_int32 expected_err,const char * description)625*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_set_principal(cc_ccache_t ccache, cc_uint32 cred_vers, const char *in_principal, cc_int32 expected_err, const char *description) {
626*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
627*7f2fe78bSCy Schubert cc_string_t stored_principal = NULL;
628*7f2fe78bSCy Schubert
629*7f2fe78bSCy Schubert cc_int32 possible_return_values[6] = {
630*7f2fe78bSCy Schubert ccNoError,
631*7f2fe78bSCy Schubert ccErrNoMem,
632*7f2fe78bSCy Schubert ccErrInvalidCCache,
633*7f2fe78bSCy Schubert ccErrBadCredentialsVersion,
634*7f2fe78bSCy Schubert ccErrBadParam,
635*7f2fe78bSCy Schubert ccErrCCacheNotFound,
636*7f2fe78bSCy Schubert };
637*7f2fe78bSCy Schubert
638*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
639*7f2fe78bSCy Schubert
640*7f2fe78bSCy Schubert #ifdef cc_ccache_set_principal
641*7f2fe78bSCy Schubert
642*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
643*7f2fe78bSCy Schubert
644*7f2fe78bSCy Schubert err = cc_ccache_set_principal(ccache, cred_vers, in_principal);
645*7f2fe78bSCy Schubert
646*7f2fe78bSCy Schubert // check returned error
647*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
648*7f2fe78bSCy Schubert
649*7f2fe78bSCy Schubert if (!err) {
650*7f2fe78bSCy Schubert err = cc_ccache_get_principal(ccache, cred_vers, &stored_principal);
651*7f2fe78bSCy Schubert }
652*7f2fe78bSCy Schubert
653*7f2fe78bSCy Schubert // compare stored with input
654*7f2fe78bSCy Schubert if (!err) {
655*7f2fe78bSCy Schubert check_if(strcmp(stored_principal->data, in_principal), "expected princ == \"%s\" stored princ == \"%s\"", in_principal, stored_principal->data);
656*7f2fe78bSCy Schubert }
657*7f2fe78bSCy Schubert
658*7f2fe78bSCy Schubert if (stored_principal) { cc_string_release(stored_principal); }
659*7f2fe78bSCy Schubert
660*7f2fe78bSCy Schubert #endif /* cc_ccache_set_principal */
661*7f2fe78bSCy Schubert
662*7f2fe78bSCy Schubert END_CHECK_ONCE;
663*7f2fe78bSCy Schubert
664*7f2fe78bSCy Schubert return err;
665*7f2fe78bSCy Schubert }
666*7f2fe78bSCy Schubert
667*7f2fe78bSCy Schubert
668*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
669*7f2fe78bSCy Schubert
670*7f2fe78bSCy Schubert
check_cc_ccache_store_credentials(void)671*7f2fe78bSCy Schubert int check_cc_ccache_store_credentials(void) {
672*7f2fe78bSCy Schubert cc_int32 err = 0;
673*7f2fe78bSCy Schubert cc_context_t context = NULL;
674*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
675*7f2fe78bSCy Schubert cc_ccache_t dup_ccache = NULL;
676*7f2fe78bSCy Schubert cc_credentials_union creds_union;
677*7f2fe78bSCy Schubert cc_string_t name = NULL;
678*7f2fe78bSCy Schubert
679*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_store_credentials");
680*7f2fe78bSCy Schubert
681*7f2fe78bSCy Schubert #ifndef cc_ccache_store_credentials
682*7f2fe78bSCy Schubert log_error("cc_ccache_store_credentials is not implemented yet");
683*7f2fe78bSCy Schubert failure_count++;
684*7f2fe78bSCy Schubert #else
685*7f2fe78bSCy Schubert
686*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
687*7f2fe78bSCy Schubert
688*7f2fe78bSCy Schubert if (!err) {
689*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
690*7f2fe78bSCy Schubert }
691*7f2fe78bSCy Schubert
692*7f2fe78bSCy Schubert if (!err) {
693*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAR.ORG", &ccache);
694*7f2fe78bSCy Schubert }
695*7f2fe78bSCy Schubert
696*7f2fe78bSCy Schubert // cred with matching version and realm
697*7f2fe78bSCy Schubert if (!err) {
698*7f2fe78bSCy Schubert err = new_v5_creds_union(&creds_union, "BAR.ORG");
699*7f2fe78bSCy Schubert }
700*7f2fe78bSCy Schubert
701*7f2fe78bSCy Schubert if (!err) {
702*7f2fe78bSCy Schubert check_once_cc_ccache_store_credentials(ccache, &creds_union, ccNoError, "ok creds");
703*7f2fe78bSCy Schubert }
704*7f2fe78bSCy Schubert
705*7f2fe78bSCy Schubert if (&creds_union) { release_v5_creds_union(&creds_union); }
706*7f2fe78bSCy Schubert
707*7f2fe78bSCy Schubert // try with bad params
708*7f2fe78bSCy Schubert check_once_cc_ccache_store_credentials(ccache, NULL, ccErrBadParam, "NULL creds param");
709*7f2fe78bSCy Schubert
710*7f2fe78bSCy Schubert // invalid creds
711*7f2fe78bSCy Schubert if (!err) {
712*7f2fe78bSCy Schubert err = new_v5_creds_union(&creds_union, "BAR.ORG");
713*7f2fe78bSCy Schubert }
714*7f2fe78bSCy Schubert
715*7f2fe78bSCy Schubert if (!err) {
716*7f2fe78bSCy Schubert if (creds_union.credentials.credentials_v5->client) {
717*7f2fe78bSCy Schubert free(creds_union.credentials.credentials_v5->client);
718*7f2fe78bSCy Schubert creds_union.credentials.credentials_v5->client = NULL;
719*7f2fe78bSCy Schubert }
720*7f2fe78bSCy Schubert check_once_cc_ccache_store_credentials(ccache, &creds_union, ccErrBadParam, "invalid creds (NULL client string)");
721*7f2fe78bSCy Schubert }
722*7f2fe78bSCy Schubert
723*7f2fe78bSCy Schubert if (&creds_union) { release_v5_creds_union(&creds_union); }
724*7f2fe78bSCy Schubert
725*7f2fe78bSCy Schubert // non-existent ccache
726*7f2fe78bSCy Schubert if (ccache) {
727*7f2fe78bSCy Schubert err = cc_ccache_get_name(ccache, &name);
728*7f2fe78bSCy Schubert if (!err) {
729*7f2fe78bSCy Schubert err = cc_context_open_ccache(context, name->data, &dup_ccache);
730*7f2fe78bSCy Schubert }
731*7f2fe78bSCy Schubert if (name) { cc_string_release(name); }
732*7f2fe78bSCy Schubert if (dup_ccache) { cc_ccache_destroy(dup_ccache); }
733*7f2fe78bSCy Schubert }
734*7f2fe78bSCy Schubert
735*7f2fe78bSCy Schubert if (!err) {
736*7f2fe78bSCy Schubert err = new_v5_creds_union(&creds_union, "BAR.ORG");
737*7f2fe78bSCy Schubert }
738*7f2fe78bSCy Schubert
739*7f2fe78bSCy Schubert if (!err) {
740*7f2fe78bSCy Schubert check_once_cc_ccache_store_credentials(ccache, &creds_union, ccErrInvalidCCache, "invalid ccache");
741*7f2fe78bSCy Schubert }
742*7f2fe78bSCy Schubert
743*7f2fe78bSCy Schubert if (&creds_union) { release_v5_creds_union(&creds_union); }
744*7f2fe78bSCy Schubert if (ccache) { cc_ccache_release(ccache); }
745*7f2fe78bSCy Schubert if (context) {
746*7f2fe78bSCy Schubert destroy_all_ccaches(context);
747*7f2fe78bSCy Schubert cc_context_release(context);
748*7f2fe78bSCy Schubert }
749*7f2fe78bSCy Schubert
750*7f2fe78bSCy Schubert #endif /* cc_ccache_store_credentials */
751*7f2fe78bSCy Schubert
752*7f2fe78bSCy Schubert END_TEST_AND_RETURN
753*7f2fe78bSCy Schubert }
754*7f2fe78bSCy Schubert
check_once_cc_ccache_store_credentials(cc_ccache_t ccache,const cc_credentials_union * credentials,cc_int32 expected_err,const char * description)755*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_store_credentials(cc_ccache_t ccache, const cc_credentials_union *credentials, cc_int32 expected_err, const char *description) {
756*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
757*7f2fe78bSCy Schubert cc_credentials_iterator_t creds_iterator = NULL;
758*7f2fe78bSCy Schubert cc_credentials_t creds = NULL;
759*7f2fe78bSCy Schubert
760*7f2fe78bSCy Schubert cc_int32 possible_return_values[6] = {
761*7f2fe78bSCy Schubert ccNoError,
762*7f2fe78bSCy Schubert ccErrBadParam,
763*7f2fe78bSCy Schubert ccErrInvalidCCache,
764*7f2fe78bSCy Schubert ccErrInvalidCredentials,
765*7f2fe78bSCy Schubert ccErrBadCredentialsVersion,
766*7f2fe78bSCy Schubert ccErrCCacheNotFound,
767*7f2fe78bSCy Schubert };
768*7f2fe78bSCy Schubert
769*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
770*7f2fe78bSCy Schubert
771*7f2fe78bSCy Schubert #ifdef cc_ccache_store_credentials
772*7f2fe78bSCy Schubert
773*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
774*7f2fe78bSCy Schubert
775*7f2fe78bSCy Schubert err = cc_ccache_store_credentials(ccache, credentials);
776*7f2fe78bSCy Schubert
777*7f2fe78bSCy Schubert // check returned error
778*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
779*7f2fe78bSCy Schubert
780*7f2fe78bSCy Schubert // make sure credentials were truly stored
781*7f2fe78bSCy Schubert if (!err) {
782*7f2fe78bSCy Schubert err = cc_ccache_new_credentials_iterator(ccache, &creds_iterator);
783*7f2fe78bSCy Schubert }
784*7f2fe78bSCy Schubert while (!err) {
785*7f2fe78bSCy Schubert err = cc_credentials_iterator_next(creds_iterator, &creds);
786*7f2fe78bSCy Schubert if (creds) {
787*7f2fe78bSCy Schubert if (compare_v5_creds_unions(credentials, creds->data) == 0) {
788*7f2fe78bSCy Schubert break;
789*7f2fe78bSCy Schubert }
790*7f2fe78bSCy Schubert cc_credentials_release(creds);
791*7f2fe78bSCy Schubert creds = NULL;
792*7f2fe78bSCy Schubert }
793*7f2fe78bSCy Schubert }
794*7f2fe78bSCy Schubert
795*7f2fe78bSCy Schubert if (err == ccIteratorEnd) {
796*7f2fe78bSCy Schubert check_if((creds != NULL), "stored credentials not found in ccache");
797*7f2fe78bSCy Schubert err = ccNoError;
798*7f2fe78bSCy Schubert }
799*7f2fe78bSCy Schubert if (creds) { cc_credentials_release(creds); }
800*7f2fe78bSCy Schubert
801*7f2fe78bSCy Schubert #endif /* cc_ccache_store_credentials */
802*7f2fe78bSCy Schubert
803*7f2fe78bSCy Schubert END_CHECK_ONCE;
804*7f2fe78bSCy Schubert
805*7f2fe78bSCy Schubert return err;
806*7f2fe78bSCy Schubert }
807*7f2fe78bSCy Schubert
808*7f2fe78bSCy Schubert
809*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
810*7f2fe78bSCy Schubert
811*7f2fe78bSCy Schubert
check_cc_ccache_remove_credentials(void)812*7f2fe78bSCy Schubert int check_cc_ccache_remove_credentials(void) {
813*7f2fe78bSCy Schubert cc_int32 err = 0;
814*7f2fe78bSCy Schubert cc_context_t context = NULL;
815*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
816*7f2fe78bSCy Schubert cc_ccache_t dup_ccache = NULL;
817*7f2fe78bSCy Schubert cc_credentials_t creds_array[10];
818*7f2fe78bSCy Schubert cc_credentials_t creds = NULL;
819*7f2fe78bSCy Schubert cc_credentials_union creds_union;
820*7f2fe78bSCy Schubert cc_credentials_iterator_t creds_iterator = NULL;
821*7f2fe78bSCy Schubert cc_string_t name = NULL;
822*7f2fe78bSCy Schubert unsigned int i;
823*7f2fe78bSCy Schubert
824*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_remove_credentials");
825*7f2fe78bSCy Schubert
826*7f2fe78bSCy Schubert #ifndef cc_ccache_remove_credentials
827*7f2fe78bSCy Schubert log_error("cc_ccache_remove_credentials is not implemented yet");
828*7f2fe78bSCy Schubert failure_count++;
829*7f2fe78bSCy Schubert #else
830*7f2fe78bSCy Schubert
831*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
832*7f2fe78bSCy Schubert
833*7f2fe78bSCy Schubert if (!err) {
834*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
835*7f2fe78bSCy Schubert }
836*7f2fe78bSCy Schubert
837*7f2fe78bSCy Schubert if (!err) {
838*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAR.ORG", &ccache);
839*7f2fe78bSCy Schubert }
840*7f2fe78bSCy Schubert
841*7f2fe78bSCy Schubert // store 10 creds and retrieve their cc_credentials_t representations
842*7f2fe78bSCy Schubert for(i = 0; !err && (i < 10); i++) {
843*7f2fe78bSCy Schubert new_v5_creds_union(&creds_union, "BAR.ORG");
844*7f2fe78bSCy Schubert err = cc_ccache_store_credentials(ccache, &creds_union);
845*7f2fe78bSCy Schubert if (&creds_union) { release_v5_creds_union(&creds_union); }
846*7f2fe78bSCy Schubert }
847*7f2fe78bSCy Schubert if (err) {
848*7f2fe78bSCy Schubert log_error("failure to store creds_union in remove_creds test");
849*7f2fe78bSCy Schubert }
850*7f2fe78bSCy Schubert if (!err) {
851*7f2fe78bSCy Schubert err = cc_ccache_new_credentials_iterator(ccache, &creds_iterator);
852*7f2fe78bSCy Schubert }
853*7f2fe78bSCy Schubert i = 0;
854*7f2fe78bSCy Schubert while (!err && i < 10) {
855*7f2fe78bSCy Schubert err = cc_credentials_iterator_next(creds_iterator, &creds);
856*7f2fe78bSCy Schubert if (creds) {
857*7f2fe78bSCy Schubert creds_array[i++] = creds;
858*7f2fe78bSCy Schubert creds = NULL;
859*7f2fe78bSCy Schubert }
860*7f2fe78bSCy Schubert }
861*7f2fe78bSCy Schubert if (err == ccIteratorEnd) { err = ccNoError; }
862*7f2fe78bSCy Schubert
863*7f2fe78bSCy Schubert // remove 10 valid creds
864*7f2fe78bSCy Schubert for (i = 0; !err && (i < 8); i++) {
865*7f2fe78bSCy Schubert check_once_cc_ccache_remove_credentials(ccache, creds_array[i], ccNoError, "10 ok creds");
866*7f2fe78bSCy Schubert }
867*7f2fe78bSCy Schubert
868*7f2fe78bSCy Schubert // NULL param
869*7f2fe78bSCy Schubert check_once_cc_ccache_remove_credentials(ccache, NULL, ccErrBadParam, "NULL creds in param");
870*7f2fe78bSCy Schubert
871*7f2fe78bSCy Schubert // non-existent creds (remove same one twice)
872*7f2fe78bSCy Schubert check_once_cc_ccache_remove_credentials(ccache, creds_array[0], ccErrInvalidCredentials, "removed same creds twice");
873*7f2fe78bSCy Schubert
874*7f2fe78bSCy Schubert // non-existent ccache
875*7f2fe78bSCy Schubert if (ccache) {
876*7f2fe78bSCy Schubert err = cc_ccache_get_name(ccache, &name);
877*7f2fe78bSCy Schubert if (!err) {
878*7f2fe78bSCy Schubert err = cc_context_open_ccache(context, name->data, &dup_ccache);
879*7f2fe78bSCy Schubert }
880*7f2fe78bSCy Schubert if (name) { cc_string_release(name); }
881*7f2fe78bSCy Schubert if (dup_ccache) { cc_ccache_destroy(dup_ccache); }
882*7f2fe78bSCy Schubert }
883*7f2fe78bSCy Schubert
884*7f2fe78bSCy Schubert if (!err) {
885*7f2fe78bSCy Schubert err = new_v5_creds_union(&creds_union, "BAR.ORG");
886*7f2fe78bSCy Schubert }
887*7f2fe78bSCy Schubert
888*7f2fe78bSCy Schubert if (!err) {
889*7f2fe78bSCy Schubert check_once_cc_ccache_remove_credentials(ccache, creds_array[8], ccErrInvalidCCache, "invalid ccache");
890*7f2fe78bSCy Schubert }
891*7f2fe78bSCy Schubert
892*7f2fe78bSCy Schubert for(i = 0; i < 10; i++) {
893*7f2fe78bSCy Schubert if (creds_array[i]) { cc_credentials_release(creds_array[i]); }
894*7f2fe78bSCy Schubert }
895*7f2fe78bSCy Schubert
896*7f2fe78bSCy Schubert if (ccache) { cc_ccache_release(ccache); }
897*7f2fe78bSCy Schubert if (context) {
898*7f2fe78bSCy Schubert destroy_all_ccaches(context);
899*7f2fe78bSCy Schubert cc_context_release(context);
900*7f2fe78bSCy Schubert }
901*7f2fe78bSCy Schubert
902*7f2fe78bSCy Schubert #endif /* cc_ccache_remove_credentials */
903*7f2fe78bSCy Schubert
904*7f2fe78bSCy Schubert END_TEST_AND_RETURN
905*7f2fe78bSCy Schubert }
906*7f2fe78bSCy Schubert
check_once_cc_ccache_remove_credentials(cc_ccache_t ccache,cc_credentials_t in_creds,cc_int32 expected_err,const char * description)907*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_remove_credentials(cc_ccache_t ccache, cc_credentials_t in_creds, cc_int32 expected_err, const char *description) {
908*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
909*7f2fe78bSCy Schubert cc_credentials_iterator_t creds_iterator = NULL;
910*7f2fe78bSCy Schubert cc_credentials_t creds = NULL;
911*7f2fe78bSCy Schubert
912*7f2fe78bSCy Schubert cc_int32 possible_return_values[6] = {
913*7f2fe78bSCy Schubert ccNoError,
914*7f2fe78bSCy Schubert ccErrBadParam,
915*7f2fe78bSCy Schubert ccErrInvalidCCache,
916*7f2fe78bSCy Schubert ccErrInvalidCredentials,
917*7f2fe78bSCy Schubert ccErrCredentialsNotFound,
918*7f2fe78bSCy Schubert ccErrCCacheNotFound,
919*7f2fe78bSCy Schubert };
920*7f2fe78bSCy Schubert
921*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
922*7f2fe78bSCy Schubert
923*7f2fe78bSCy Schubert #ifdef cc_ccache_remove_credentials
924*7f2fe78bSCy Schubert
925*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
926*7f2fe78bSCy Schubert
927*7f2fe78bSCy Schubert err = cc_ccache_remove_credentials(ccache, in_creds);
928*7f2fe78bSCy Schubert
929*7f2fe78bSCy Schubert // check returned error
930*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
931*7f2fe78bSCy Schubert
932*7f2fe78bSCy Schubert // make sure credentials were truly removed
933*7f2fe78bSCy Schubert if (!err) {
934*7f2fe78bSCy Schubert err = cc_ccache_new_credentials_iterator(ccache, &creds_iterator);
935*7f2fe78bSCy Schubert }
936*7f2fe78bSCy Schubert while (!err) {
937*7f2fe78bSCy Schubert err = cc_credentials_iterator_next(creds_iterator, &creds);
938*7f2fe78bSCy Schubert if (creds) {
939*7f2fe78bSCy Schubert if (compare_v5_creds_unions(in_creds->data, creds->data) == 0) {
940*7f2fe78bSCy Schubert break;
941*7f2fe78bSCy Schubert }
942*7f2fe78bSCy Schubert cc_credentials_release(creds);
943*7f2fe78bSCy Schubert creds = NULL;
944*7f2fe78bSCy Schubert }
945*7f2fe78bSCy Schubert }
946*7f2fe78bSCy Schubert
947*7f2fe78bSCy Schubert if (err == ccIteratorEnd) {
948*7f2fe78bSCy Schubert err = ccNoError;
949*7f2fe78bSCy Schubert }
950*7f2fe78bSCy Schubert else {
951*7f2fe78bSCy Schubert check_if((creds != NULL), "credentials not removed from ccache");
952*7f2fe78bSCy Schubert }
953*7f2fe78bSCy Schubert if (creds) { cc_credentials_release(creds); }
954*7f2fe78bSCy Schubert
955*7f2fe78bSCy Schubert #endif /* cc_ccache_remove_credentials */
956*7f2fe78bSCy Schubert
957*7f2fe78bSCy Schubert END_CHECK_ONCE;
958*7f2fe78bSCy Schubert
959*7f2fe78bSCy Schubert return err;
960*7f2fe78bSCy Schubert }
961*7f2fe78bSCy Schubert
962*7f2fe78bSCy Schubert
963*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
964*7f2fe78bSCy Schubert
965*7f2fe78bSCy Schubert
check_cc_ccache_new_credentials_iterator(void)966*7f2fe78bSCy Schubert int check_cc_ccache_new_credentials_iterator(void) {
967*7f2fe78bSCy Schubert cc_int32 err = 0;
968*7f2fe78bSCy Schubert cc_context_t context = NULL;
969*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
970*7f2fe78bSCy Schubert cc_ccache_t dup_ccache = NULL;
971*7f2fe78bSCy Schubert cc_credentials_iterator_t creds_iterator = NULL;
972*7f2fe78bSCy Schubert cc_string_t name = NULL;
973*7f2fe78bSCy Schubert
974*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_new_credentials_iterator");
975*7f2fe78bSCy Schubert
976*7f2fe78bSCy Schubert #ifndef cc_ccache_new_credentials_iterator
977*7f2fe78bSCy Schubert log_error("cc_ccache_new_credentials_iterator is not implemented yet");
978*7f2fe78bSCy Schubert failure_count++;
979*7f2fe78bSCy Schubert #else
980*7f2fe78bSCy Schubert
981*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
982*7f2fe78bSCy Schubert
983*7f2fe78bSCy Schubert if (!err) {
984*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
985*7f2fe78bSCy Schubert }
986*7f2fe78bSCy Schubert
987*7f2fe78bSCy Schubert if (!err) {
988*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAR.ORG", &ccache);
989*7f2fe78bSCy Schubert }
990*7f2fe78bSCy Schubert
991*7f2fe78bSCy Schubert // valid params
992*7f2fe78bSCy Schubert if (!err) {
993*7f2fe78bSCy Schubert check_once_cc_ccache_new_credentials_iterator(ccache, &creds_iterator, ccNoError, "valid params");
994*7f2fe78bSCy Schubert }
995*7f2fe78bSCy Schubert if (creds_iterator) {
996*7f2fe78bSCy Schubert cc_credentials_iterator_release(creds_iterator);
997*7f2fe78bSCy Schubert creds_iterator = NULL;
998*7f2fe78bSCy Schubert }
999*7f2fe78bSCy Schubert
1000*7f2fe78bSCy Schubert // NULL out param
1001*7f2fe78bSCy Schubert if (!err) {
1002*7f2fe78bSCy Schubert check_once_cc_ccache_new_credentials_iterator(ccache, NULL, ccErrBadParam, "NULL out iterator param");
1003*7f2fe78bSCy Schubert }
1004*7f2fe78bSCy Schubert if (creds_iterator) {
1005*7f2fe78bSCy Schubert cc_credentials_iterator_release(creds_iterator);
1006*7f2fe78bSCy Schubert creds_iterator = NULL;
1007*7f2fe78bSCy Schubert }
1008*7f2fe78bSCy Schubert
1009*7f2fe78bSCy Schubert // non-existent ccache
1010*7f2fe78bSCy Schubert if (ccache) {
1011*7f2fe78bSCy Schubert err = cc_ccache_get_name(ccache, &name);
1012*7f2fe78bSCy Schubert if (!err) {
1013*7f2fe78bSCy Schubert err = cc_context_open_ccache(context, name->data, &dup_ccache);
1014*7f2fe78bSCy Schubert }
1015*7f2fe78bSCy Schubert if (name) { cc_string_release(name); }
1016*7f2fe78bSCy Schubert if (dup_ccache) { cc_ccache_destroy(dup_ccache); }
1017*7f2fe78bSCy Schubert }
1018*7f2fe78bSCy Schubert
1019*7f2fe78bSCy Schubert if (!err) {
1020*7f2fe78bSCy Schubert check_once_cc_ccache_new_credentials_iterator(ccache, &creds_iterator, ccErrInvalidCCache, "invalid ccache");
1021*7f2fe78bSCy Schubert }
1022*7f2fe78bSCy Schubert
1023*7f2fe78bSCy Schubert if (creds_iterator) {
1024*7f2fe78bSCy Schubert cc_credentials_iterator_release(creds_iterator);
1025*7f2fe78bSCy Schubert creds_iterator = NULL;
1026*7f2fe78bSCy Schubert }
1027*7f2fe78bSCy Schubert if (ccache) { cc_ccache_release(ccache); }
1028*7f2fe78bSCy Schubert if (context) {
1029*7f2fe78bSCy Schubert destroy_all_ccaches(context);
1030*7f2fe78bSCy Schubert cc_context_release(context);
1031*7f2fe78bSCy Schubert }
1032*7f2fe78bSCy Schubert
1033*7f2fe78bSCy Schubert #endif /* cc_ccache_new_credentials_iterator */
1034*7f2fe78bSCy Schubert
1035*7f2fe78bSCy Schubert END_TEST_AND_RETURN
1036*7f2fe78bSCy Schubert }
1037*7f2fe78bSCy Schubert
1038*7f2fe78bSCy Schubert
check_once_cc_ccache_new_credentials_iterator(cc_ccache_t ccache,cc_credentials_iterator_t * iterator,cc_int32 expected_err,const char * description)1039*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_new_credentials_iterator(cc_ccache_t ccache, cc_credentials_iterator_t *iterator, cc_int32 expected_err, const char *description) {
1040*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
1041*7f2fe78bSCy Schubert
1042*7f2fe78bSCy Schubert cc_int32 possible_return_values[5] = {
1043*7f2fe78bSCy Schubert ccNoError,
1044*7f2fe78bSCy Schubert ccErrBadParam,
1045*7f2fe78bSCy Schubert ccErrNoMem,
1046*7f2fe78bSCy Schubert ccErrCCacheNotFound,
1047*7f2fe78bSCy Schubert ccErrInvalidCCache,
1048*7f2fe78bSCy Schubert };
1049*7f2fe78bSCy Schubert
1050*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
1051*7f2fe78bSCy Schubert
1052*7f2fe78bSCy Schubert #ifdef cc_ccache_new_credentials_iterator
1053*7f2fe78bSCy Schubert
1054*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
1055*7f2fe78bSCy Schubert
1056*7f2fe78bSCy Schubert err = cc_ccache_new_credentials_iterator(ccache, iterator);
1057*7f2fe78bSCy Schubert
1058*7f2fe78bSCy Schubert // check returned error
1059*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
1060*7f2fe78bSCy Schubert
1061*7f2fe78bSCy Schubert #endif /* cc_ccache_new_credentials_iterator */
1062*7f2fe78bSCy Schubert
1063*7f2fe78bSCy Schubert END_CHECK_ONCE;
1064*7f2fe78bSCy Schubert
1065*7f2fe78bSCy Schubert return err;
1066*7f2fe78bSCy Schubert }
1067*7f2fe78bSCy Schubert
1068*7f2fe78bSCy Schubert
1069*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
1070*7f2fe78bSCy Schubert
check_once_cc_ccache_get_change_time(cc_ccache_t ccache,cc_time_t * last_time,cc_int32 expected_err,const char * description)1071*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_get_change_time(cc_ccache_t ccache, cc_time_t *last_time, cc_int32 expected_err, const char *description) {
1072*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
1073*7f2fe78bSCy Schubert cc_time_t this_time = 0;
1074*7f2fe78bSCy Schubert
1075*7f2fe78bSCy Schubert cc_int32 possible_return_values[4] = {
1076*7f2fe78bSCy Schubert ccNoError,
1077*7f2fe78bSCy Schubert ccErrInvalidCCache,
1078*7f2fe78bSCy Schubert ccErrBadParam,
1079*7f2fe78bSCy Schubert ccErrCCacheNotFound,
1080*7f2fe78bSCy Schubert };
1081*7f2fe78bSCy Schubert
1082*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
1083*7f2fe78bSCy Schubert
1084*7f2fe78bSCy Schubert #ifdef cc_ccache_get_change_time
1085*7f2fe78bSCy Schubert
1086*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
1087*7f2fe78bSCy Schubert
1088*7f2fe78bSCy Schubert if (last_time == NULL) {
1089*7f2fe78bSCy Schubert err = cc_ccache_get_change_time(ccache, NULL); // passed NULL to compare against because intention is actually to pass bad param instead
1090*7f2fe78bSCy Schubert } else {
1091*7f2fe78bSCy Schubert err = cc_ccache_get_change_time(ccache, &this_time);
1092*7f2fe78bSCy Schubert }
1093*7f2fe78bSCy Schubert
1094*7f2fe78bSCy Schubert // check returned error
1095*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
1096*7f2fe78bSCy Schubert
1097*7f2fe78bSCy Schubert if ((!err) && last_time) {
1098*7f2fe78bSCy Schubert check_if(this_time <= *last_time, "change time didn't increase when expected");
1099*7f2fe78bSCy Schubert *last_time = this_time;
1100*7f2fe78bSCy Schubert }
1101*7f2fe78bSCy Schubert
1102*7f2fe78bSCy Schubert #endif /* cc_ccache_get_change_time */
1103*7f2fe78bSCy Schubert
1104*7f2fe78bSCy Schubert END_CHECK_ONCE;
1105*7f2fe78bSCy Schubert
1106*7f2fe78bSCy Schubert return err;
1107*7f2fe78bSCy Schubert }
1108*7f2fe78bSCy Schubert
1109*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
1110*7f2fe78bSCy Schubert
check_cc_ccache_get_change_time(void)1111*7f2fe78bSCy Schubert int check_cc_ccache_get_change_time(void) {
1112*7f2fe78bSCy Schubert cc_int32 err = 0;
1113*7f2fe78bSCy Schubert cc_context_t context = NULL;
1114*7f2fe78bSCy Schubert cc_ccache_t dummy_ccache = NULL;
1115*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
1116*7f2fe78bSCy Schubert cc_credentials_union creds_union;
1117*7f2fe78bSCy Schubert cc_credentials_iterator_t creds_iterator = NULL;
1118*7f2fe78bSCy Schubert cc_credentials_t credentials = NULL;
1119*7f2fe78bSCy Schubert cc_time_t last_time = 0;
1120*7f2fe78bSCy Schubert
1121*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_get_change_time");
1122*7f2fe78bSCy Schubert
1123*7f2fe78bSCy Schubert #ifndef cc_ccache_get_change_time
1124*7f2fe78bSCy Schubert log_error("cc_ccache_get_change_time is not implemented yet");
1125*7f2fe78bSCy Schubert failure_count++;
1126*7f2fe78bSCy Schubert #else
1127*7f2fe78bSCy Schubert
1128*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
1129*7f2fe78bSCy Schubert
1130*7f2fe78bSCy Schubert if (!err) {
1131*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
1132*7f2fe78bSCy Schubert }
1133*7f2fe78bSCy Schubert
1134*7f2fe78bSCy Schubert // create some ccaches (so that the one we keep around as 'ccache' is not default)
1135*7f2fe78bSCy Schubert if (!err) {
1136*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAR.ORG", &ccache);
1137*7f2fe78bSCy Schubert }
1138*7f2fe78bSCy Schubert if (ccache) {
1139*7f2fe78bSCy Schubert cc_ccache_release(ccache);
1140*7f2fe78bSCy Schubert }
1141*7f2fe78bSCy Schubert if (!err) {
1142*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAZ.ORG", &ccache);
1143*7f2fe78bSCy Schubert }
1144*7f2fe78bSCy Schubert
1145*7f2fe78bSCy Schubert // change it in all the ways it can change, checking after each
1146*7f2fe78bSCy Schubert
1147*7f2fe78bSCy Schubert // the ccache is created
1148*7f2fe78bSCy Schubert if (!err) {
1149*7f2fe78bSCy Schubert check_once_cc_ccache_get_change_time(ccache, &last_time, ccNoError, "new ccache (change time should be > 0)");
1150*7f2fe78bSCy Schubert }
1151*7f2fe78bSCy Schubert
1152*7f2fe78bSCy Schubert // the ccache is made default
1153*7f2fe78bSCy Schubert if (!err) {
1154*7f2fe78bSCy Schubert err = cc_ccache_set_default(ccache);
1155*7f2fe78bSCy Schubert }
1156*7f2fe78bSCy Schubert if (!err) {
1157*7f2fe78bSCy Schubert check_once_cc_ccache_get_change_time(ccache, &last_time, ccNoError, "non-default ccache became default");
1158*7f2fe78bSCy Schubert }
1159*7f2fe78bSCy Schubert
1160*7f2fe78bSCy Schubert // the ccache is made not-default
1161*7f2fe78bSCy Schubert if (!err) {
1162*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "something@ELSE.COM", &dummy_ccache);
1163*7f2fe78bSCy Schubert }
1164*7f2fe78bSCy Schubert if (!err) {
1165*7f2fe78bSCy Schubert err = cc_ccache_set_default(dummy_ccache);
1166*7f2fe78bSCy Schubert }
1167*7f2fe78bSCy Schubert if (dummy_ccache) {
1168*7f2fe78bSCy Schubert cc_ccache_release(dummy_ccache);
1169*7f2fe78bSCy Schubert }
1170*7f2fe78bSCy Schubert if (!err) {
1171*7f2fe78bSCy Schubert check_once_cc_ccache_get_change_time(ccache, &last_time, ccNoError, "default ccache became non-default");
1172*7f2fe78bSCy Schubert }
1173*7f2fe78bSCy Schubert
1174*7f2fe78bSCy Schubert // try with bad params
1175*7f2fe78bSCy Schubert
1176*7f2fe78bSCy Schubert // NULL out param
1177*7f2fe78bSCy Schubert if (!err) {
1178*7f2fe78bSCy Schubert check_once_cc_ccache_get_change_time(ccache, NULL, ccErrBadParam, "NULL out param for time");
1179*7f2fe78bSCy Schubert }
1180*7f2fe78bSCy Schubert
1181*7f2fe78bSCy Schubert // store a credential
1182*7f2fe78bSCy Schubert if (!err) {
1183*7f2fe78bSCy Schubert new_v5_creds_union(&creds_union, "BAR.ORG");
1184*7f2fe78bSCy Schubert err = cc_ccache_store_credentials(ccache, &creds_union);
1185*7f2fe78bSCy Schubert release_v5_creds_union(&creds_union);
1186*7f2fe78bSCy Schubert }
1187*7f2fe78bSCy Schubert check_once_cc_ccache_get_change_time(ccache, &last_time, ccNoError, "stored new credential");
1188*7f2fe78bSCy Schubert
1189*7f2fe78bSCy Schubert if (!err) {
1190*7f2fe78bSCy Schubert // change principal (fails with ccErrBadInternalMessage)
1191*7f2fe78bSCy Schubert err = cc_ccache_set_principal(ccache, cc_credentials_v5, "foo@BAR.ORG");
1192*7f2fe78bSCy Schubert if (err) {
1193*7f2fe78bSCy Schubert log_error("failed to change ccache's principal - %s (%d)", translate_ccapi_error(err), err);
1194*7f2fe78bSCy Schubert failure_count++;
1195*7f2fe78bSCy Schubert err = ccNoError;
1196*7f2fe78bSCy Schubert }
1197*7f2fe78bSCy Schubert }
1198*7f2fe78bSCy Schubert check_once_cc_context_get_change_time(context, &last_time, ccNoError, "after changing a principle");
1199*7f2fe78bSCy Schubert
1200*7f2fe78bSCy Schubert // remove a credential
1201*7f2fe78bSCy Schubert if (!err) {
1202*7f2fe78bSCy Schubert err = cc_ccache_new_credentials_iterator(ccache, &creds_iterator);
1203*7f2fe78bSCy Schubert }
1204*7f2fe78bSCy Schubert if (!err) {
1205*7f2fe78bSCy Schubert err = cc_credentials_iterator_next(creds_iterator, &credentials);
1206*7f2fe78bSCy Schubert }
1207*7f2fe78bSCy Schubert if (err == ccIteratorEnd) {
1208*7f2fe78bSCy Schubert err = ccNoError;
1209*7f2fe78bSCy Schubert }
1210*7f2fe78bSCy Schubert if (!err) {
1211*7f2fe78bSCy Schubert err = cc_ccache_remove_credentials(ccache, credentials);
1212*7f2fe78bSCy Schubert }
1213*7f2fe78bSCy Schubert check_once_cc_context_get_change_time(context, &last_time, ccNoError, "after removing a credential");
1214*7f2fe78bSCy Schubert
1215*7f2fe78bSCy Schubert
1216*7f2fe78bSCy Schubert // invalid ccache
1217*7f2fe78bSCy Schubert if (!err) {
1218*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
1219*7f2fe78bSCy Schubert }
1220*7f2fe78bSCy Schubert if (!err) {
1221*7f2fe78bSCy Schubert check_once_cc_ccache_get_change_time(ccache, &last_time, ccErrInvalidCCache, "getting change time on destroyed ccache");
1222*7f2fe78bSCy Schubert }
1223*7f2fe78bSCy Schubert
1224*7f2fe78bSCy Schubert if (ccache) { cc_ccache_release(ccache); }
1225*7f2fe78bSCy Schubert if (context) {
1226*7f2fe78bSCy Schubert destroy_all_ccaches(context);
1227*7f2fe78bSCy Schubert cc_context_release(context);
1228*7f2fe78bSCy Schubert }
1229*7f2fe78bSCy Schubert
1230*7f2fe78bSCy Schubert #endif /* cc_ccache_get_change_time */
1231*7f2fe78bSCy Schubert
1232*7f2fe78bSCy Schubert END_TEST_AND_RETURN
1233*7f2fe78bSCy Schubert }
1234*7f2fe78bSCy Schubert
1235*7f2fe78bSCy Schubert
1236*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
1237*7f2fe78bSCy Schubert
check_once_cc_ccache_get_last_default_time(cc_ccache_t ccache,cc_time_t * last_time,cc_int32 expected_err,const char * description)1238*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_get_last_default_time(cc_ccache_t ccache, cc_time_t *last_time, cc_int32 expected_err, const char *description) {
1239*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
1240*7f2fe78bSCy Schubert cc_time_t this_time = 0;
1241*7f2fe78bSCy Schubert
1242*7f2fe78bSCy Schubert cc_int32 possible_return_values[5] = {
1243*7f2fe78bSCy Schubert ccNoError,
1244*7f2fe78bSCy Schubert ccErrInvalidCCache,
1245*7f2fe78bSCy Schubert ccErrBadParam,
1246*7f2fe78bSCy Schubert ccErrNeverDefault,
1247*7f2fe78bSCy Schubert ccErrCCacheNotFound,
1248*7f2fe78bSCy Schubert };
1249*7f2fe78bSCy Schubert
1250*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
1251*7f2fe78bSCy Schubert
1252*7f2fe78bSCy Schubert #ifdef cc_ccache_get_last_default_time
1253*7f2fe78bSCy Schubert
1254*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
1255*7f2fe78bSCy Schubert
1256*7f2fe78bSCy Schubert if (last_time == NULL) {
1257*7f2fe78bSCy Schubert err = cc_ccache_get_last_default_time(ccache, NULL); // passed NULL to compare against because intention is actually to pass bad param instead
1258*7f2fe78bSCy Schubert } else {
1259*7f2fe78bSCy Schubert err = cc_ccache_get_last_default_time(ccache, &this_time);
1260*7f2fe78bSCy Schubert }
1261*7f2fe78bSCy Schubert
1262*7f2fe78bSCy Schubert // check returned error
1263*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
1264*7f2fe78bSCy Schubert
1265*7f2fe78bSCy Schubert if (!err && last_time) {
1266*7f2fe78bSCy Schubert check_if(this_time > *last_time, "last default time isn't as expected");
1267*7f2fe78bSCy Schubert *last_time = this_time;
1268*7f2fe78bSCy Schubert }
1269*7f2fe78bSCy Schubert
1270*7f2fe78bSCy Schubert #endif /* cc_ccache_get_last_default_time */
1271*7f2fe78bSCy Schubert
1272*7f2fe78bSCy Schubert END_CHECK_ONCE;
1273*7f2fe78bSCy Schubert
1274*7f2fe78bSCy Schubert return err;
1275*7f2fe78bSCy Schubert }
1276*7f2fe78bSCy Schubert
1277*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
1278*7f2fe78bSCy Schubert
check_cc_ccache_get_last_default_time(void)1279*7f2fe78bSCy Schubert int check_cc_ccache_get_last_default_time(void) {
1280*7f2fe78bSCy Schubert cc_int32 err = 0;
1281*7f2fe78bSCy Schubert cc_context_t context = NULL;
1282*7f2fe78bSCy Schubert cc_ccache_t ccache_1 = NULL;
1283*7f2fe78bSCy Schubert cc_ccache_t ccache_2 = NULL;
1284*7f2fe78bSCy Schubert cc_time_t last_time_1 = 0;
1285*7f2fe78bSCy Schubert cc_time_t last_time_2 = 0;
1286*7f2fe78bSCy Schubert cc_string_t name = NULL;
1287*7f2fe78bSCy Schubert
1288*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_get_last_default_time");
1289*7f2fe78bSCy Schubert
1290*7f2fe78bSCy Schubert #ifndef cc_ccache_get_last_default_time
1291*7f2fe78bSCy Schubert log_error("cc_ccache_get_last_default_time is not implemented yet");
1292*7f2fe78bSCy Schubert failure_count++;
1293*7f2fe78bSCy Schubert #else
1294*7f2fe78bSCy Schubert
1295*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
1296*7f2fe78bSCy Schubert
1297*7f2fe78bSCy Schubert if (!err) {
1298*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
1299*7f2fe78bSCy Schubert }
1300*7f2fe78bSCy Schubert
1301*7f2fe78bSCy Schubert // create 2 ccaches
1302*7f2fe78bSCy Schubert if (!err) {
1303*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@ONE.ORG", &ccache_1);
1304*7f2fe78bSCy Schubert }
1305*7f2fe78bSCy Schubert if (!err) {
1306*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@TWO.ORG", &ccache_2);
1307*7f2fe78bSCy Schubert }
1308*7f2fe78bSCy Schubert
1309*7f2fe78bSCy Schubert if (!err) {
1310*7f2fe78bSCy Schubert err = cc_ccache_get_change_time(ccache_1, &last_time_1);
1311*7f2fe78bSCy Schubert }
1312*7f2fe78bSCy Schubert
1313*7f2fe78bSCy Schubert // since we destroyed all ccaches before creating these two,
1314*7f2fe78bSCy Schubert // ccache_1 should be default and ccache_2 should never have been default
1315*7f2fe78bSCy Schubert if (!err) {
1316*7f2fe78bSCy Schubert check_once_cc_ccache_get_last_default_time(ccache_1, &last_time_1, ccNoError, "ccache_1 default at creation");
1317*7f2fe78bSCy Schubert check_once_cc_ccache_get_last_default_time(ccache_2, &last_time_2, ccErrNeverDefault, "ccache_2 never default");
1318*7f2fe78bSCy Schubert }
1319*7f2fe78bSCy Schubert
1320*7f2fe78bSCy Schubert // make ccache_2 default and check each of their times again
1321*7f2fe78bSCy Schubert if (!err) {
1322*7f2fe78bSCy Schubert err = cc_ccache_set_default(ccache_2);
1323*7f2fe78bSCy Schubert }
1324*7f2fe78bSCy Schubert if (!err) {
1325*7f2fe78bSCy Schubert err = cc_ccache_get_change_time(ccache_2, &last_time_2);
1326*7f2fe78bSCy Schubert }
1327*7f2fe78bSCy Schubert if (!err) {
1328*7f2fe78bSCy Schubert check_once_cc_ccache_get_last_default_time(ccache_1, &last_time_1, ccNoError, "ccache_1 no longer default");
1329*7f2fe78bSCy Schubert check_once_cc_ccache_get_last_default_time(ccache_2, &last_time_2, ccNoError, "ccache_2 newly default");
1330*7f2fe78bSCy Schubert }
1331*7f2fe78bSCy Schubert
1332*7f2fe78bSCy Schubert // NULL param
1333*7f2fe78bSCy Schubert if (!err) {
1334*7f2fe78bSCy Schubert check_once_cc_ccache_get_last_default_time(ccache_1, NULL, ccErrBadParam, "NULL out param");
1335*7f2fe78bSCy Schubert }
1336*7f2fe78bSCy Schubert
1337*7f2fe78bSCy Schubert // non-existent ccache
1338*7f2fe78bSCy Schubert if (ccache_2) {
1339*7f2fe78bSCy Schubert cc_ccache_release(ccache_2);
1340*7f2fe78bSCy Schubert ccache_2 = NULL;
1341*7f2fe78bSCy Schubert }
1342*7f2fe78bSCy Schubert if (!err) {
1343*7f2fe78bSCy Schubert err = cc_ccache_get_name(ccache_1, &name);
1344*7f2fe78bSCy Schubert }
1345*7f2fe78bSCy Schubert if (!err) {
1346*7f2fe78bSCy Schubert err = cc_context_open_ccache(context, name->data, &ccache_2);
1347*7f2fe78bSCy Schubert }
1348*7f2fe78bSCy Schubert if (!err) {
1349*7f2fe78bSCy Schubert cc_ccache_destroy(ccache_2);
1350*7f2fe78bSCy Schubert ccache_2 = NULL;
1351*7f2fe78bSCy Schubert }
1352*7f2fe78bSCy Schubert
1353*7f2fe78bSCy Schubert if (!err) {
1354*7f2fe78bSCy Schubert check_once_cc_ccache_get_last_default_time(ccache_1, &last_time_1, ccErrInvalidCCache, "destroyed ccache");
1355*7f2fe78bSCy Schubert }
1356*7f2fe78bSCy Schubert
1357*7f2fe78bSCy Schubert if (ccache_1) { cc_ccache_release(ccache_1); }
1358*7f2fe78bSCy Schubert
1359*7f2fe78bSCy Schubert if (context) {
1360*7f2fe78bSCy Schubert destroy_all_ccaches(context);
1361*7f2fe78bSCy Schubert cc_context_release(context);
1362*7f2fe78bSCy Schubert }
1363*7f2fe78bSCy Schubert
1364*7f2fe78bSCy Schubert #endif /* cc_ccache_get_last_default_time */
1365*7f2fe78bSCy Schubert
1366*7f2fe78bSCy Schubert END_TEST_AND_RETURN
1367*7f2fe78bSCy Schubert }
1368*7f2fe78bSCy Schubert
1369*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
1370*7f2fe78bSCy Schubert
check_cc_ccache_move(void)1371*7f2fe78bSCy Schubert int check_cc_ccache_move(void) {
1372*7f2fe78bSCy Schubert cc_int32 err = 0;
1373*7f2fe78bSCy Schubert cc_context_t context = NULL;
1374*7f2fe78bSCy Schubert cc_ccache_t source = NULL;
1375*7f2fe78bSCy Schubert cc_ccache_t destination = NULL;
1376*7f2fe78bSCy Schubert
1377*7f2fe78bSCy Schubert cc_credentials_union creds_union;
1378*7f2fe78bSCy Schubert unsigned int i = 0;
1379*7f2fe78bSCy Schubert
1380*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_move");
1381*7f2fe78bSCy Schubert
1382*7f2fe78bSCy Schubert #ifndef cc_ccache_move
1383*7f2fe78bSCy Schubert log_error("cc_ccache_move is not implemented yet");
1384*7f2fe78bSCy Schubert failure_count++;
1385*7f2fe78bSCy Schubert #else
1386*7f2fe78bSCy Schubert
1387*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
1388*7f2fe78bSCy Schubert
1389*7f2fe78bSCy Schubert if (!err) {
1390*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
1391*7f2fe78bSCy Schubert }
1392*7f2fe78bSCy Schubert
1393*7f2fe78bSCy Schubert // create 2 ccaches
1394*7f2fe78bSCy Schubert if (!err) {
1395*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@ONE.ORG", &source);
1396*7f2fe78bSCy Schubert }
1397*7f2fe78bSCy Schubert if (!err) {
1398*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@TWO.ORG", &destination);
1399*7f2fe78bSCy Schubert }
1400*7f2fe78bSCy Schubert
1401*7f2fe78bSCy Schubert // store credentials in each
1402*7f2fe78bSCy Schubert for (i = 0; !err && (i < 10); i++) {
1403*7f2fe78bSCy Schubert new_v5_creds_union(&creds_union, "ONE.ORG");
1404*7f2fe78bSCy Schubert err = cc_ccache_store_credentials(source, &creds_union);
1405*7f2fe78bSCy Schubert }
1406*7f2fe78bSCy Schubert for (i = 0; !err && (i < 10); i++) {
1407*7f2fe78bSCy Schubert new_v5_creds_union(&creds_union, "TWO.ORG");
1408*7f2fe78bSCy Schubert err = cc_ccache_store_credentials(destination, &creds_union);
1409*7f2fe78bSCy Schubert }
1410*7f2fe78bSCy Schubert
1411*7f2fe78bSCy Schubert // move source into destination
1412*7f2fe78bSCy Schubert if (!err) {
1413*7f2fe78bSCy Schubert check_once_cc_ccache_move(source, destination, ccNoError, "valid params");
1414*7f2fe78bSCy Schubert }
1415*7f2fe78bSCy Schubert
1416*7f2fe78bSCy Schubert // NULL param
1417*7f2fe78bSCy Schubert if (!err) {
1418*7f2fe78bSCy Schubert check_once_cc_ccache_move(destination, NULL, ccErrBadParam, "NULL destination param");
1419*7f2fe78bSCy Schubert }
1420*7f2fe78bSCy Schubert
1421*7f2fe78bSCy Schubert // non-existent ccache
1422*7f2fe78bSCy Schubert if (!err) {
1423*7f2fe78bSCy Schubert check_once_cc_ccache_move(destination, source, ccErrInvalidCCache, "recently moved source as destination param");
1424*7f2fe78bSCy Schubert }
1425*7f2fe78bSCy Schubert
1426*7f2fe78bSCy Schubert if (source) { cc_ccache_release(source); }
1427*7f2fe78bSCy Schubert if (destination) { cc_ccache_release(destination); }
1428*7f2fe78bSCy Schubert
1429*7f2fe78bSCy Schubert if (context) {
1430*7f2fe78bSCy Schubert destroy_all_ccaches(context);
1431*7f2fe78bSCy Schubert cc_context_release(context);
1432*7f2fe78bSCy Schubert }
1433*7f2fe78bSCy Schubert
1434*7f2fe78bSCy Schubert #endif /* cc_ccache_move */
1435*7f2fe78bSCy Schubert
1436*7f2fe78bSCy Schubert END_TEST_AND_RETURN
1437*7f2fe78bSCy Schubert
1438*7f2fe78bSCy Schubert
1439*7f2fe78bSCy Schubert }
1440*7f2fe78bSCy Schubert
check_once_cc_ccache_move(cc_ccache_t source,cc_ccache_t destination,cc_int32 expected_err,const char * description)1441*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_move(cc_ccache_t source, cc_ccache_t destination, cc_int32 expected_err, const char *description) {
1442*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
1443*7f2fe78bSCy Schubert cc_credentials_t dst_creds[10] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, };
1444*7f2fe78bSCy Schubert cc_credentials_t creds = NULL;
1445*7f2fe78bSCy Schubert cc_credentials_iterator_t cred_iterator = NULL;
1446*7f2fe78bSCy Schubert unsigned int i = 0;
1447*7f2fe78bSCy Schubert
1448*7f2fe78bSCy Schubert cc_string_t src_principal = NULL;
1449*7f2fe78bSCy Schubert cc_string_t dst_principal = NULL;
1450*7f2fe78bSCy Schubert
1451*7f2fe78bSCy Schubert cc_int32 possible_return_values[4] = {
1452*7f2fe78bSCy Schubert ccNoError,
1453*7f2fe78bSCy Schubert ccErrBadParam,
1454*7f2fe78bSCy Schubert ccErrInvalidCCache,
1455*7f2fe78bSCy Schubert ccErrCCacheNotFound,
1456*7f2fe78bSCy Schubert };
1457*7f2fe78bSCy Schubert
1458*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
1459*7f2fe78bSCy Schubert
1460*7f2fe78bSCy Schubert #ifdef cc_ccache_move
1461*7f2fe78bSCy Schubert
1462*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
1463*7f2fe78bSCy Schubert
1464*7f2fe78bSCy Schubert if (destination) {
1465*7f2fe78bSCy Schubert // verify all of destination's credentials are no longer there (save a list and call remove_cred for each, expecting an err in response)
1466*7f2fe78bSCy Schubert if (!err) {
1467*7f2fe78bSCy Schubert err = cc_ccache_new_credentials_iterator(destination, &cred_iterator);
1468*7f2fe78bSCy Schubert }
1469*7f2fe78bSCy Schubert while (!err && (i < 10)) {
1470*7f2fe78bSCy Schubert err = cc_credentials_iterator_next(cred_iterator, &creds);
1471*7f2fe78bSCy Schubert if (creds) {
1472*7f2fe78bSCy Schubert dst_creds[i++] = creds;
1473*7f2fe78bSCy Schubert }
1474*7f2fe78bSCy Schubert }
1475*7f2fe78bSCy Schubert if (err == ccIteratorEnd) {
1476*7f2fe78bSCy Schubert err = ccNoError;
1477*7f2fe78bSCy Schubert }
1478*7f2fe78bSCy Schubert if (cred_iterator) {
1479*7f2fe78bSCy Schubert cc_credentials_iterator_release(cred_iterator);
1480*7f2fe78bSCy Schubert cred_iterator = NULL;
1481*7f2fe78bSCy Schubert }
1482*7f2fe78bSCy Schubert
1483*7f2fe78bSCy Schubert // verify that destination's principal has changed to source's (strcmp)
1484*7f2fe78bSCy Schubert if (!err) {
1485*7f2fe78bSCy Schubert err = cc_ccache_get_principal(source, cc_credentials_v5, &src_principal);
1486*7f2fe78bSCy Schubert }
1487*7f2fe78bSCy Schubert }
1488*7f2fe78bSCy Schubert
1489*7f2fe78bSCy Schubert
1490*7f2fe78bSCy Schubert if (!err) {
1491*7f2fe78bSCy Schubert err = cc_ccache_move(source, destination);
1492*7f2fe78bSCy Schubert }
1493*7f2fe78bSCy Schubert
1494*7f2fe78bSCy Schubert // check returned error
1495*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
1496*7f2fe78bSCy Schubert
1497*7f2fe78bSCy Schubert
1498*7f2fe78bSCy Schubert if (!err) {
1499*7f2fe78bSCy Schubert // verify all of destination's credentials are no longer there (save a list and call remove_cred for each, expecting an err in response)
1500*7f2fe78bSCy Schubert i = 0;
1501*7f2fe78bSCy Schubert while (dst_creds[i] && (i < 10)) {
1502*7f2fe78bSCy Schubert err = cc_ccache_remove_credentials(destination, dst_creds[i]);
1503*7f2fe78bSCy Schubert check_if(!(!err || err == ccErrCredentialsNotFound || ccErrInvalidCredentials), "credentials in destination not removed as promised");
1504*7f2fe78bSCy Schubert cc_credentials_release(dst_creds[i]);
1505*7f2fe78bSCy Schubert i++;
1506*7f2fe78bSCy Schubert }
1507*7f2fe78bSCy Schubert err = ccNoError;
1508*7f2fe78bSCy Schubert }
1509*7f2fe78bSCy Schubert
1510*7f2fe78bSCy Schubert // verify that destination's principal has changed to source's (strcmp)
1511*7f2fe78bSCy Schubert if (!err) {
1512*7f2fe78bSCy Schubert err = cc_ccache_get_principal(destination, cc_credentials_v5, &dst_principal);
1513*7f2fe78bSCy Schubert }
1514*7f2fe78bSCy Schubert if (!err) {
1515*7f2fe78bSCy Schubert check_if(strcmp(src_principal->data, dst_principal->data), "destination principal not overwritten by source");
1516*7f2fe78bSCy Schubert }
1517*7f2fe78bSCy Schubert
1518*7f2fe78bSCy Schubert // verify that handles for source are no longer valid (get_change_time)
1519*7f2fe78bSCy Schubert if (src_principal) {
1520*7f2fe78bSCy Schubert cc_string_release(src_principal);
1521*7f2fe78bSCy Schubert src_principal = NULL;
1522*7f2fe78bSCy Schubert }
1523*7f2fe78bSCy Schubert if (!err) {
1524*7f2fe78bSCy Schubert err = cc_ccache_get_principal(source, cc_credentials_v5, &src_principal);
1525*7f2fe78bSCy Schubert check_if(err != ccErrInvalidCCache, "source ccache was not invalidated after move");
1526*7f2fe78bSCy Schubert }
1527*7f2fe78bSCy Schubert
1528*7f2fe78bSCy Schubert
1529*7f2fe78bSCy Schubert if (cred_iterator) { cc_credentials_iterator_release(cred_iterator); }
1530*7f2fe78bSCy Schubert if (src_principal) { cc_string_release(src_principal); }
1531*7f2fe78bSCy Schubert if (dst_principal) { cc_string_release(dst_principal); }
1532*7f2fe78bSCy Schubert
1533*7f2fe78bSCy Schubert #endif /* cc_ccache_move */
1534*7f2fe78bSCy Schubert
1535*7f2fe78bSCy Schubert END_CHECK_ONCE;
1536*7f2fe78bSCy Schubert
1537*7f2fe78bSCy Schubert return err;
1538*7f2fe78bSCy Schubert }
1539*7f2fe78bSCy Schubert
1540*7f2fe78bSCy Schubert
1541*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
1542*7f2fe78bSCy Schubert
check_cc_ccache_compare(void)1543*7f2fe78bSCy Schubert int check_cc_ccache_compare(void) {
1544*7f2fe78bSCy Schubert cc_int32 err = 0;
1545*7f2fe78bSCy Schubert cc_context_t context = NULL;
1546*7f2fe78bSCy Schubert cc_ccache_t ccache_a = NULL;
1547*7f2fe78bSCy Schubert cc_ccache_t ccache_b = NULL;
1548*7f2fe78bSCy Schubert cc_uint32 equal = 0;
1549*7f2fe78bSCy Schubert
1550*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_compare");
1551*7f2fe78bSCy Schubert
1552*7f2fe78bSCy Schubert #ifndef cc_ccache_compare
1553*7f2fe78bSCy Schubert log_error("cc_ccache_compare is not implemented yet");
1554*7f2fe78bSCy Schubert failure_count++;
1555*7f2fe78bSCy Schubert #else
1556*7f2fe78bSCy Schubert
1557*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
1558*7f2fe78bSCy Schubert
1559*7f2fe78bSCy Schubert if (!err) {
1560*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
1561*7f2fe78bSCy Schubert }
1562*7f2fe78bSCy Schubert if (!err) {
1563*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAR.ORG", &ccache_a);
1564*7f2fe78bSCy Schubert }
1565*7f2fe78bSCy Schubert if (!err) {
1566*7f2fe78bSCy Schubert err = cc_context_open_default_ccache(context, &ccache_b);
1567*7f2fe78bSCy Schubert }
1568*7f2fe78bSCy Schubert
1569*7f2fe78bSCy Schubert equal = 1;
1570*7f2fe78bSCy Schubert check_once_cc_ccache_compare(ccache_a, ccache_a, &equal, ccNoError, "compare ccache with same pointer");
1571*7f2fe78bSCy Schubert equal = 1;
1572*7f2fe78bSCy Schubert check_once_cc_ccache_compare(ccache_a, ccache_b, &equal, ccNoError, "compare different handles to same ccache");
1573*7f2fe78bSCy Schubert
1574*7f2fe78bSCy Schubert if (ccache_b) {
1575*7f2fe78bSCy Schubert cc_ccache_release(ccache_b);
1576*7f2fe78bSCy Schubert ccache_b = NULL;
1577*7f2fe78bSCy Schubert }
1578*7f2fe78bSCy Schubert if (!err) {
1579*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "baz@BAR.ORG", &ccache_b);
1580*7f2fe78bSCy Schubert }
1581*7f2fe78bSCy Schubert equal = 0;
1582*7f2fe78bSCy Schubert check_once_cc_ccache_compare(ccache_a, ccache_b, &equal, ccNoError, "compare different ccaches");
1583*7f2fe78bSCy Schubert check_once_cc_ccache_compare(ccache_a, NULL, &equal, ccErrBadParam, "NULL compare_to ccache");
1584*7f2fe78bSCy Schubert check_once_cc_ccache_compare(ccache_a, ccache_b, NULL, ccErrBadParam, "NULL out param");
1585*7f2fe78bSCy Schubert
1586*7f2fe78bSCy Schubert if (ccache_a) { cc_ccache_release(ccache_a); }
1587*7f2fe78bSCy Schubert if (ccache_b) { cc_ccache_release(ccache_b); }
1588*7f2fe78bSCy Schubert
1589*7f2fe78bSCy Schubert if (context) {
1590*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
1591*7f2fe78bSCy Schubert cc_context_release(context);
1592*7f2fe78bSCy Schubert }
1593*7f2fe78bSCy Schubert
1594*7f2fe78bSCy Schubert #endif /* cc_ccache_compare */
1595*7f2fe78bSCy Schubert
1596*7f2fe78bSCy Schubert END_TEST_AND_RETURN
1597*7f2fe78bSCy Schubert }
1598*7f2fe78bSCy Schubert
check_once_cc_ccache_compare(cc_ccache_t ccache,cc_ccache_t compare_to,cc_uint32 * equal,cc_int32 expected_err,const char * description)1599*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_compare(cc_ccache_t ccache, cc_ccache_t compare_to, cc_uint32 *equal, cc_int32 expected_err, const char *description) {
1600*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
1601*7f2fe78bSCy Schubert cc_uint32 actually_equal = 0;
1602*7f2fe78bSCy Schubert
1603*7f2fe78bSCy Schubert cc_int32 possible_return_values[4] = {
1604*7f2fe78bSCy Schubert ccNoError,
1605*7f2fe78bSCy Schubert ccErrInvalidContext,
1606*7f2fe78bSCy Schubert ccErrBadParam,
1607*7f2fe78bSCy Schubert ccErrServerUnavailable,
1608*7f2fe78bSCy Schubert };
1609*7f2fe78bSCy Schubert
1610*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
1611*7f2fe78bSCy Schubert
1612*7f2fe78bSCy Schubert #ifdef cc_ccache_compare
1613*7f2fe78bSCy Schubert
1614*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
1615*7f2fe78bSCy Schubert
1616*7f2fe78bSCy Schubert if (equal) {
1617*7f2fe78bSCy Schubert actually_equal = *equal;
1618*7f2fe78bSCy Schubert }
1619*7f2fe78bSCy Schubert
1620*7f2fe78bSCy Schubert err = cc_ccache_compare(ccache, compare_to, equal);
1621*7f2fe78bSCy Schubert
1622*7f2fe78bSCy Schubert if (!err && equal) {
1623*7f2fe78bSCy Schubert if (actually_equal) {
1624*7f2fe78bSCy Schubert check_if(actually_equal != *equal, "equal ccaches not considered equal");
1625*7f2fe78bSCy Schubert }
1626*7f2fe78bSCy Schubert else {
1627*7f2fe78bSCy Schubert check_if(actually_equal != *equal, "non-equal ccaches considered equal");
1628*7f2fe78bSCy Schubert }
1629*7f2fe78bSCy Schubert }
1630*7f2fe78bSCy Schubert
1631*7f2fe78bSCy Schubert // check returned error
1632*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
1633*7f2fe78bSCy Schubert
1634*7f2fe78bSCy Schubert #endif /* cc_ccache_compare */
1635*7f2fe78bSCy Schubert
1636*7f2fe78bSCy Schubert return err;
1637*7f2fe78bSCy Schubert }
1638*7f2fe78bSCy Schubert
1639*7f2fe78bSCy Schubert
1640*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
1641*7f2fe78bSCy Schubert
check_cc_ccache_get_kdc_time_offset(void)1642*7f2fe78bSCy Schubert int check_cc_ccache_get_kdc_time_offset(void) {
1643*7f2fe78bSCy Schubert cc_int32 err = 0;
1644*7f2fe78bSCy Schubert cc_context_t context = NULL;
1645*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
1646*7f2fe78bSCy Schubert cc_time_t time_offset = 0;
1647*7f2fe78bSCy Schubert
1648*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_get_kdc_time_offset");
1649*7f2fe78bSCy Schubert
1650*7f2fe78bSCy Schubert #ifndef cc_ccache_get_kdc_time_offset
1651*7f2fe78bSCy Schubert log_error("cc_ccache_get_kdc_time_offset is not implemented yet");
1652*7f2fe78bSCy Schubert failure_count++;
1653*7f2fe78bSCy Schubert #else
1654*7f2fe78bSCy Schubert
1655*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
1656*7f2fe78bSCy Schubert
1657*7f2fe78bSCy Schubert if (!err) {
1658*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
1659*7f2fe78bSCy Schubert }
1660*7f2fe78bSCy Schubert if (!err) {
1661*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAR.ORG", &ccache);
1662*7f2fe78bSCy Schubert }
1663*7f2fe78bSCy Schubert
1664*7f2fe78bSCy Schubert time_offset = 0;
1665*7f2fe78bSCy Schubert check_once_cc_ccache_get_kdc_time_offset(ccache, cc_credentials_v5, &time_offset, ccErrTimeOffsetNotSet, "brand new ccache (offset not yet set)");
1666*7f2fe78bSCy Schubert
1667*7f2fe78bSCy Schubert time_offset = 10;
1668*7f2fe78bSCy Schubert if (!err) {
1669*7f2fe78bSCy Schubert err = cc_ccache_set_kdc_time_offset(ccache, cc_credentials_v5, time_offset);
1670*7f2fe78bSCy Schubert }
1671*7f2fe78bSCy Schubert if (!err) {
1672*7f2fe78bSCy Schubert check_once_cc_ccache_get_kdc_time_offset(ccache, cc_credentials_v5, &time_offset, ccNoError, "offset set for v5");
1673*7f2fe78bSCy Schubert }
1674*7f2fe78bSCy Schubert
1675*7f2fe78bSCy Schubert check_once_cc_ccache_get_kdc_time_offset(ccache, cc_credentials_v5, NULL, ccErrBadParam, "NULL time_offset out param");
1676*7f2fe78bSCy Schubert
1677*7f2fe78bSCy Schubert if (ccache) { cc_ccache_release(ccache); }
1678*7f2fe78bSCy Schubert
1679*7f2fe78bSCy Schubert if (context) {
1680*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
1681*7f2fe78bSCy Schubert cc_context_release(context);
1682*7f2fe78bSCy Schubert }
1683*7f2fe78bSCy Schubert
1684*7f2fe78bSCy Schubert #endif /* cc_ccache_get_kdc_time_offset */
1685*7f2fe78bSCy Schubert
1686*7f2fe78bSCy Schubert END_TEST_AND_RETURN
1687*7f2fe78bSCy Schubert }
1688*7f2fe78bSCy Schubert
check_once_cc_ccache_get_kdc_time_offset(cc_ccache_t ccache,cc_int32 credentials_version,cc_time_t * time_offset,cc_int32 expected_err,const char * description)1689*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_get_kdc_time_offset(cc_ccache_t ccache, cc_int32 credentials_version, cc_time_t *time_offset, cc_int32 expected_err, const char *description) {
1690*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
1691*7f2fe78bSCy Schubert cc_time_t expected_offset;
1692*7f2fe78bSCy Schubert
1693*7f2fe78bSCy Schubert cc_int32 possible_return_values[7] = {
1694*7f2fe78bSCy Schubert ccNoError,
1695*7f2fe78bSCy Schubert ccErrTimeOffsetNotSet,
1696*7f2fe78bSCy Schubert ccErrCCacheNotFound,
1697*7f2fe78bSCy Schubert ccErrInvalidCCache,
1698*7f2fe78bSCy Schubert ccErrBadParam,
1699*7f2fe78bSCy Schubert ccErrServerUnavailable,
1700*7f2fe78bSCy Schubert ccErrBadCredentialsVersion,
1701*7f2fe78bSCy Schubert };
1702*7f2fe78bSCy Schubert
1703*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
1704*7f2fe78bSCy Schubert
1705*7f2fe78bSCy Schubert #ifdef cc_ccache_get_kdc_time_offset
1706*7f2fe78bSCy Schubert
1707*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
1708*7f2fe78bSCy Schubert
1709*7f2fe78bSCy Schubert if (time_offset) {
1710*7f2fe78bSCy Schubert expected_offset = *time_offset;
1711*7f2fe78bSCy Schubert }
1712*7f2fe78bSCy Schubert
1713*7f2fe78bSCy Schubert err = cc_ccache_get_kdc_time_offset(ccache, credentials_version, time_offset);
1714*7f2fe78bSCy Schubert
1715*7f2fe78bSCy Schubert // check returned error
1716*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
1717*7f2fe78bSCy Schubert
1718*7f2fe78bSCy Schubert if (!err && time_offset) {
1719*7f2fe78bSCy Schubert check_if(*time_offset != expected_offset, "kdc time offset doesn't match expected value");
1720*7f2fe78bSCy Schubert }
1721*7f2fe78bSCy Schubert
1722*7f2fe78bSCy Schubert #endif /* cc_ccache_get_kdc_time_offset */
1723*7f2fe78bSCy Schubert
1724*7f2fe78bSCy Schubert return err;
1725*7f2fe78bSCy Schubert }
1726*7f2fe78bSCy Schubert
1727*7f2fe78bSCy Schubert
1728*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
1729*7f2fe78bSCy Schubert
check_cc_ccache_set_kdc_time_offset(void)1730*7f2fe78bSCy Schubert int check_cc_ccache_set_kdc_time_offset(void) {
1731*7f2fe78bSCy Schubert cc_int32 err = 0;
1732*7f2fe78bSCy Schubert cc_context_t context = NULL;
1733*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
1734*7f2fe78bSCy Schubert
1735*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_set_kdc_time_offset");
1736*7f2fe78bSCy Schubert
1737*7f2fe78bSCy Schubert #ifndef cc_ccache_set_kdc_time_offset
1738*7f2fe78bSCy Schubert log_error("cc_ccache_set_kdc_time_offset is not implemented yet");
1739*7f2fe78bSCy Schubert failure_count++;
1740*7f2fe78bSCy Schubert #else
1741*7f2fe78bSCy Schubert
1742*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
1743*7f2fe78bSCy Schubert
1744*7f2fe78bSCy Schubert if (!err) {
1745*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
1746*7f2fe78bSCy Schubert }
1747*7f2fe78bSCy Schubert if (!err) {
1748*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAR.ORG", &ccache);
1749*7f2fe78bSCy Schubert }
1750*7f2fe78bSCy Schubert
1751*7f2fe78bSCy Schubert check_once_cc_ccache_set_kdc_time_offset(ccache, cc_credentials_v5, 0, ccNoError, "first time setting offset (v5)");
1752*7f2fe78bSCy Schubert
1753*7f2fe78bSCy Schubert if (ccache) { cc_ccache_release(ccache); }
1754*7f2fe78bSCy Schubert
1755*7f2fe78bSCy Schubert if (context) {
1756*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
1757*7f2fe78bSCy Schubert cc_context_release(context);
1758*7f2fe78bSCy Schubert }
1759*7f2fe78bSCy Schubert
1760*7f2fe78bSCy Schubert #endif /* cc_ccache_set_kdc_time_offset */
1761*7f2fe78bSCy Schubert
1762*7f2fe78bSCy Schubert END_TEST_AND_RETURN
1763*7f2fe78bSCy Schubert }
1764*7f2fe78bSCy Schubert
check_once_cc_ccache_set_kdc_time_offset(cc_ccache_t ccache,cc_int32 credentials_version,cc_time_t time_offset,cc_int32 expected_err,const char * description)1765*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_set_kdc_time_offset(cc_ccache_t ccache, cc_int32 credentials_version, cc_time_t time_offset, cc_int32 expected_err, const char *description) {
1766*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
1767*7f2fe78bSCy Schubert cc_time_t stored_offset = 0;
1768*7f2fe78bSCy Schubert
1769*7f2fe78bSCy Schubert cc_int32 possible_return_values[6] = {
1770*7f2fe78bSCy Schubert ccNoError,
1771*7f2fe78bSCy Schubert ccErrCCacheNotFound,
1772*7f2fe78bSCy Schubert ccErrInvalidCCache,
1773*7f2fe78bSCy Schubert ccErrBadParam,
1774*7f2fe78bSCy Schubert ccErrServerUnavailable,
1775*7f2fe78bSCy Schubert ccErrBadCredentialsVersion,
1776*7f2fe78bSCy Schubert };
1777*7f2fe78bSCy Schubert
1778*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
1779*7f2fe78bSCy Schubert
1780*7f2fe78bSCy Schubert #ifdef cc_ccache_set_kdc_time_offset
1781*7f2fe78bSCy Schubert
1782*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
1783*7f2fe78bSCy Schubert
1784*7f2fe78bSCy Schubert err = cc_ccache_set_kdc_time_offset(ccache, credentials_version, time_offset);
1785*7f2fe78bSCy Schubert
1786*7f2fe78bSCy Schubert // check returned error
1787*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
1788*7f2fe78bSCy Schubert
1789*7f2fe78bSCy Schubert if (!err) {
1790*7f2fe78bSCy Schubert err = cc_ccache_get_kdc_time_offset(ccache, credentials_version, &stored_offset);
1791*7f2fe78bSCy Schubert }
1792*7f2fe78bSCy Schubert
1793*7f2fe78bSCy Schubert if (!err) {
1794*7f2fe78bSCy Schubert check_if(time_offset != stored_offset, "kdc time offset doesn't match expected value");
1795*7f2fe78bSCy Schubert }
1796*7f2fe78bSCy Schubert
1797*7f2fe78bSCy Schubert #endif /* cc_ccache_set_kdc_time_offset */
1798*7f2fe78bSCy Schubert
1799*7f2fe78bSCy Schubert return err;
1800*7f2fe78bSCy Schubert }
1801*7f2fe78bSCy Schubert
1802*7f2fe78bSCy Schubert
1803*7f2fe78bSCy Schubert // ---------------------------------------------------------------------------
1804*7f2fe78bSCy Schubert
check_cc_ccache_clear_kdc_time_offset(void)1805*7f2fe78bSCy Schubert int check_cc_ccache_clear_kdc_time_offset(void) {
1806*7f2fe78bSCy Schubert cc_int32 err = 0;
1807*7f2fe78bSCy Schubert cc_context_t context = NULL;
1808*7f2fe78bSCy Schubert cc_ccache_t ccache = NULL;
1809*7f2fe78bSCy Schubert
1810*7f2fe78bSCy Schubert BEGIN_TEST("cc_ccache_clear_kdc_time_offset");
1811*7f2fe78bSCy Schubert
1812*7f2fe78bSCy Schubert #ifndef cc_ccache_clear_kdc_time_offset
1813*7f2fe78bSCy Schubert log_error("cc_ccache_clear_kdc_time_offset is not implemented yet");
1814*7f2fe78bSCy Schubert failure_count++;
1815*7f2fe78bSCy Schubert #else
1816*7f2fe78bSCy Schubert
1817*7f2fe78bSCy Schubert err = cc_initialize(&context, ccapi_version_3, NULL, NULL);
1818*7f2fe78bSCy Schubert
1819*7f2fe78bSCy Schubert if (!err) {
1820*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
1821*7f2fe78bSCy Schubert }
1822*7f2fe78bSCy Schubert if (!err) {
1823*7f2fe78bSCy Schubert err = cc_context_create_new_ccache(context, cc_credentials_v5, "foo@BAR.ORG", &ccache);
1824*7f2fe78bSCy Schubert }
1825*7f2fe78bSCy Schubert
1826*7f2fe78bSCy Schubert check_once_cc_ccache_clear_kdc_time_offset(ccache, cc_credentials_v5, ccNoError, "clearing an offset that was never set (v5)");
1827*7f2fe78bSCy Schubert
1828*7f2fe78bSCy Schubert err = cc_ccache_set_kdc_time_offset(ccache, cc_credentials_v5, 0);
1829*7f2fe78bSCy Schubert
1830*7f2fe78bSCy Schubert check_once_cc_ccache_clear_kdc_time_offset(ccache, cc_credentials_v5, ccNoError, "clearing v5");
1831*7f2fe78bSCy Schubert
1832*7f2fe78bSCy Schubert if (ccache) { cc_ccache_release(ccache); }
1833*7f2fe78bSCy Schubert
1834*7f2fe78bSCy Schubert if (context) {
1835*7f2fe78bSCy Schubert err = destroy_all_ccaches(context);
1836*7f2fe78bSCy Schubert cc_context_release(context);
1837*7f2fe78bSCy Schubert }
1838*7f2fe78bSCy Schubert
1839*7f2fe78bSCy Schubert #endif /* cc_ccache_clear_kdc_time_offset */
1840*7f2fe78bSCy Schubert
1841*7f2fe78bSCy Schubert END_TEST_AND_RETURN
1842*7f2fe78bSCy Schubert }
1843*7f2fe78bSCy Schubert
check_once_cc_ccache_clear_kdc_time_offset(cc_ccache_t ccache,cc_int32 credentials_version,cc_int32 expected_err,const char * description)1844*7f2fe78bSCy Schubert cc_int32 check_once_cc_ccache_clear_kdc_time_offset(cc_ccache_t ccache, cc_int32 credentials_version, cc_int32 expected_err, const char *description) {
1845*7f2fe78bSCy Schubert cc_int32 err = ccNoError;
1846*7f2fe78bSCy Schubert cc_time_t stored_offset = 0;
1847*7f2fe78bSCy Schubert
1848*7f2fe78bSCy Schubert cc_int32 possible_return_values[6] = {
1849*7f2fe78bSCy Schubert ccNoError,
1850*7f2fe78bSCy Schubert ccErrCCacheNotFound,
1851*7f2fe78bSCy Schubert ccErrInvalidCCache,
1852*7f2fe78bSCy Schubert ccErrBadParam,
1853*7f2fe78bSCy Schubert ccErrServerUnavailable,
1854*7f2fe78bSCy Schubert ccErrBadCredentialsVersion,
1855*7f2fe78bSCy Schubert };
1856*7f2fe78bSCy Schubert BEGIN_CHECK_ONCE(description);
1857*7f2fe78bSCy Schubert
1858*7f2fe78bSCy Schubert #ifdef cc_ccache_clear_kdc_time_offset
1859*7f2fe78bSCy Schubert
1860*7f2fe78bSCy Schubert #define possible_ret_val_count sizeof(possible_return_values)/sizeof(possible_return_values[0])
1861*7f2fe78bSCy Schubert
1862*7f2fe78bSCy Schubert err = cc_ccache_clear_kdc_time_offset(ccache, credentials_version);
1863*7f2fe78bSCy Schubert
1864*7f2fe78bSCy Schubert // check returned error
1865*7f2fe78bSCy Schubert check_err(err, expected_err, possible_return_values);
1866*7f2fe78bSCy Schubert
1867*7f2fe78bSCy Schubert if (!err) {
1868*7f2fe78bSCy Schubert err = cc_ccache_get_kdc_time_offset(ccache, credentials_version, &stored_offset);
1869*7f2fe78bSCy Schubert check_if(err != ccErrTimeOffsetNotSet, "time offset not cleared");
1870*7f2fe78bSCy Schubert }
1871*7f2fe78bSCy Schubert
1872*7f2fe78bSCy Schubert #endif /* cc_ccache_clear_kdc_time_offset */
1873*7f2fe78bSCy Schubert
1874*7f2fe78bSCy Schubert return err;
1875*7f2fe78bSCy Schubert }
1876