Line data Source code
1 : /*
2 : Authors:
3 : Sumit Bose <sbose@redhat.com>
4 :
5 : Copyright (C) 2013 Red Hat
6 :
7 : SSSD tests: Unit tests for libsss_idmap
8 :
9 : This program is free software; you can redistribute it and/or modify
10 : it under the terms of the GNU General Public License as published by
11 : the Free Software Foundation; either version 3 of the License, or
12 : (at your option) any later version.
13 :
14 : This program is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU General Public License for more details.
18 :
19 : You should have received a copy of the GNU General Public License
20 : along with this program. If not, see <http://www.gnu.org/licenses/>.
21 : */
22 :
23 : #include <popt.h>
24 :
25 : #include "tests/cmocka/common_mock.h"
26 :
27 : #include "lib/idmap/sss_idmap.h"
28 :
29 : #define TEST_RANGE_MIN 200000
30 : #define TEST_RANGE_MAX 399999
31 : #define TEST_DOM_NAME "test.dom"
32 : #define TEST_DOM_SID "S-1-5-21-123-456-789"
33 : #define TEST_FIRST_RID 0
34 : #define TEST_EXT_MAPPING true
35 :
36 : #define TEST_2_RANGE_MIN 600000
37 : #define TEST_2_RANGE_MAX 799999
38 : #define TEST_2_DOM_NAME "test2.dom"
39 : #define TEST_2_DOM_SID "S-1-5-21-987-654-321"
40 : #define TEST_2_FIRST_RID 1000000
41 : #define TEST_2_EXT_MAPPING true
42 :
43 : #define TEST_OFFSET 1000000
44 : #define TEST_OFFSET_STR "1000000"
45 :
46 : struct test_ctx {
47 : TALLOC_CTX *mem_idmap;
48 : struct sss_idmap_ctx *idmap_ctx;
49 : };
50 :
51 108 : static void *idmap_talloc(size_t size, void *pvt)
52 : {
53 108 : return talloc_size(pvt, size);
54 : }
55 :
56 32 : static void idmap_free(void *ptr, void *pvt)
57 : {
58 32 : talloc_free(ptr);
59 32 : }
60 :
61 7 : static int test_sss_idmap_setup(void **state)
62 : {
63 : struct test_ctx *test_ctx;
64 : enum idmap_error_code err;
65 :
66 7 : assert_true(leak_check_setup());
67 :
68 7 : test_ctx = talloc_zero(global_talloc_context, struct test_ctx);
69 7 : assert_non_null(test_ctx);
70 :
71 7 : check_leaks_push(test_ctx);
72 :
73 7 : test_ctx->mem_idmap = talloc_new(test_ctx);
74 7 : assert_non_null(test_ctx->mem_idmap);
75 :
76 7 : err = sss_idmap_init(idmap_talloc, test_ctx->mem_idmap, idmap_free,
77 : &test_ctx->idmap_ctx);
78 7 : assert_int_equal(err, IDMAP_SUCCESS);
79 :
80 7 : *state = test_ctx;
81 7 : return 0;
82 : }
83 :
84 8 : static int setup_ranges(struct test_ctx *test_ctx, bool external_mapping,
85 : bool second_domain)
86 : {
87 : struct sss_idmap_range range;
88 : enum idmap_error_code err;
89 : const char *name;
90 : const char *sid;
91 :
92 8 : assert_non_null(test_ctx);
93 :
94 8 : if (second_domain) {
95 2 : range.min = TEST_2_RANGE_MIN;
96 2 : range.max = TEST_2_RANGE_MAX;
97 2 : name = TEST_2_DOM_NAME;
98 2 : sid = TEST_2_DOM_SID;
99 : } else {
100 6 : range.min = TEST_RANGE_MIN;
101 6 : range.max = TEST_RANGE_MAX;
102 6 : name = TEST_DOM_NAME;
103 6 : sid = TEST_DOM_SID;
104 : }
105 :
106 8 : err = sss_idmap_add_domain_ex(test_ctx->idmap_ctx, name, sid, &range, NULL,
107 : 0, external_mapping);
108 8 : assert_int_equal(err, IDMAP_SUCCESS);
109 :
110 8 : range.min += TEST_OFFSET;
111 8 : range.max += TEST_OFFSET;
112 :
113 8 : err = sss_idmap_add_domain_ex(test_ctx->idmap_ctx, name, sid, &range, NULL,
114 : TEST_OFFSET, external_mapping);
115 8 : assert_int_equal(err, IDMAP_SUCCESS);
116 8 : return 0;
117 : }
118 :
119 2 : static int test_sss_idmap_setup_with_domains(void **state) {
120 : struct test_ctx *test_ctx;
121 :
122 2 : test_sss_idmap_setup(state);
123 :
124 2 : test_ctx = talloc_get_type(*state, struct test_ctx);
125 2 : assert_non_null(test_ctx);
126 :
127 2 : setup_ranges(test_ctx, false, false);
128 2 : return 0;
129 : }
130 :
131 2 : static int test_sss_idmap_setup_with_external_mappings(void **state) {
132 : struct test_ctx *test_ctx;
133 :
134 2 : test_sss_idmap_setup(state);
135 :
136 2 : test_ctx = talloc_get_type(*state, struct test_ctx);
137 2 : assert_non_null(test_ctx);
138 :
139 2 : setup_ranges(test_ctx, true, false);
140 2 : return 0;
141 : }
142 :
143 2 : static int test_sss_idmap_setup_with_both(void **state) {
144 : struct test_ctx *test_ctx;
145 :
146 2 : test_sss_idmap_setup(state);
147 :
148 2 : test_ctx = talloc_get_type(*state, struct test_ctx);
149 2 : assert_non_null(test_ctx);
150 :
151 2 : setup_ranges(test_ctx, false, false);
152 2 : setup_ranges(test_ctx, true, true);
153 2 : return 0;
154 : }
155 :
156 7 : static int test_sss_idmap_teardown(void **state)
157 : {
158 : struct test_ctx *test_ctx;
159 :
160 7 : test_ctx = talloc_get_type(*state, struct test_ctx);
161 :
162 7 : assert_non_null(test_ctx);
163 :
164 7 : talloc_free(test_ctx->idmap_ctx);
165 7 : talloc_free(test_ctx->mem_idmap);
166 7 : assert_true(check_leaks_pop(test_ctx) == true);
167 7 : talloc_free(test_ctx);
168 7 : assert_true(leak_check_teardown());
169 7 : return 0;
170 : }
171 :
172 1 : void test_add_domain(void **state)
173 : {
174 : struct test_ctx *test_ctx;
175 : enum idmap_error_code err;
176 : struct sss_idmap_range range;
177 :
178 1 : test_ctx = talloc_get_type(*state, struct test_ctx);
179 :
180 1 : assert_non_null(test_ctx);
181 :
182 1 : range.min = TEST_RANGE_MIN;
183 1 : range.max = TEST_RANGE_MAX;
184 :
185 1 : err = sss_idmap_add_domain(test_ctx->idmap_ctx, TEST_DOM_NAME, TEST_DOM_SID,
186 : &range);
187 1 : assert_int_equal(err, IDMAP_SUCCESS);
188 :
189 1 : err = sss_idmap_add_domain(test_ctx->idmap_ctx, TEST_DOM_NAME, TEST_DOM_SID,
190 : &range);
191 1 : assert_int_equal(err, IDMAP_COLLISION);
192 :
193 1 : err = sss_idmap_add_domain_ex(test_ctx->idmap_ctx, TEST_DOM_NAME,
194 : TEST_DOM_SID, &range, NULL, 0, false);
195 1 : assert_int_equal(err, IDMAP_COLLISION);
196 :
197 1 : range.min = TEST_RANGE_MIN + TEST_OFFSET;
198 1 : range.max = TEST_RANGE_MAX + TEST_OFFSET;
199 1 : err = sss_idmap_add_domain_ex(test_ctx->idmap_ctx, TEST_DOM_NAME,
200 : TEST_DOM_SID, &range, NULL, 0, false);
201 1 : assert_int_equal(err, IDMAP_COLLISION);
202 :
203 1 : err = sss_idmap_add_domain_ex(test_ctx->idmap_ctx, TEST_DOM_NAME"X",
204 : TEST_DOM_SID, &range, NULL, TEST_OFFSET,
205 : false);
206 1 : assert_int_equal(err, IDMAP_COLLISION);
207 :
208 1 : err = sss_idmap_add_domain_ex(test_ctx->idmap_ctx, TEST_DOM_NAME,
209 : TEST_DOM_SID"1", &range, NULL, TEST_OFFSET,
210 : false);
211 1 : assert_int_equal(err, IDMAP_COLLISION);
212 :
213 1 : err = sss_idmap_add_domain_ex(test_ctx->idmap_ctx, TEST_DOM_NAME,
214 : TEST_DOM_SID, &range, NULL, TEST_OFFSET,
215 : true);
216 1 : assert_int_equal(err, IDMAP_COLLISION);
217 :
218 1 : err = sss_idmap_add_domain_ex(test_ctx->idmap_ctx, TEST_DOM_NAME,
219 : TEST_DOM_SID, &range, NULL, TEST_OFFSET,
220 : false);
221 1 : assert_int_equal(err, IDMAP_SUCCESS);
222 :
223 1 : range.min = TEST_RANGE_MIN + 2 * TEST_OFFSET;
224 1 : range.max = TEST_RANGE_MAX + 2 * TEST_OFFSET;
225 1 : err = sss_idmap_add_domain_ex(test_ctx->idmap_ctx, TEST_DOM_NAME"-nosid",
226 : NULL, &range, NULL, TEST_OFFSET,
227 : false);
228 1 : assert_int_equal(err, IDMAP_SID_INVALID);
229 :
230 1 : err = sss_idmap_add_domain_ex(test_ctx->idmap_ctx, TEST_DOM_NAME"-nosid",
231 : NULL, &range, NULL, TEST_OFFSET,
232 : true);
233 1 : assert_int_equal(err, IDMAP_SUCCESS);
234 1 : }
235 :
236 1 : void test_map_id(void **state)
237 : {
238 : struct test_ctx *test_ctx;
239 : enum idmap_error_code err;
240 : uint32_t id;
241 1 : char *sid = NULL;
242 :
243 1 : test_ctx = talloc_get_type(*state, struct test_ctx);
244 :
245 1 : assert_non_null(test_ctx);
246 :
247 1 : err = sss_idmap_sid_to_unix(test_ctx->idmap_ctx, TEST_DOM_SID"1-1", &id);
248 1 : assert_int_equal(err, IDMAP_NO_DOMAIN);
249 :
250 1 : err = sss_idmap_sid_to_unix(test_ctx->idmap_ctx, TEST_DOM_SID"-400000",
251 : &id);
252 1 : assert_int_equal(err, IDMAP_NO_RANGE);
253 :
254 1 : err = sss_idmap_unix_to_sid(test_ctx->idmap_ctx, TEST_OFFSET - 1, &sid);
255 1 : assert_int_equal(err, IDMAP_NO_DOMAIN);
256 :
257 1 : err = sss_idmap_sid_to_unix(test_ctx->idmap_ctx, TEST_DOM_SID"-0", &id);
258 1 : assert_int_equal(err, IDMAP_SUCCESS);
259 1 : assert_int_equal(id, TEST_RANGE_MIN);
260 :
261 1 : err = sss_idmap_unix_to_sid(test_ctx->idmap_ctx, id, &sid);
262 1 : assert_int_equal(err, IDMAP_SUCCESS);
263 1 : assert_string_equal(sid, TEST_DOM_SID"-0");
264 1 : sss_idmap_free_sid(test_ctx->idmap_ctx, sid);
265 :
266 1 : err = sss_idmap_sid_to_unix(test_ctx->idmap_ctx,
267 : TEST_DOM_SID"-"TEST_OFFSET_STR, &id);
268 1 : assert_int_equal(err, IDMAP_SUCCESS);
269 1 : assert_int_equal(id, TEST_RANGE_MIN+TEST_OFFSET);
270 :
271 1 : err = sss_idmap_unix_to_sid(test_ctx->idmap_ctx, id, &sid);
272 1 : assert_int_equal(err, IDMAP_SUCCESS);
273 1 : assert_string_equal(sid, TEST_DOM_SID"-"TEST_OFFSET_STR);
274 1 : sss_idmap_free_sid(test_ctx->idmap_ctx, sid);
275 1 : }
276 :
277 1 : void test_map_id_external(void **state)
278 : {
279 : struct test_ctx *test_ctx;
280 : enum idmap_error_code err;
281 : uint32_t id;
282 1 : char *sid = NULL;
283 :
284 1 : test_ctx = talloc_get_type(*state, struct test_ctx);
285 :
286 1 : assert_non_null(test_ctx);
287 :
288 1 : err = sss_idmap_sid_to_unix(test_ctx->idmap_ctx, TEST_DOM_SID"1-1", &id);
289 1 : assert_int_equal(err, IDMAP_NO_DOMAIN);
290 :
291 1 : err = sss_idmap_sid_to_unix(test_ctx->idmap_ctx, TEST_DOM_SID"-400000",
292 : &id);
293 1 : assert_int_equal(err, IDMAP_EXTERNAL);
294 :
295 1 : err = sss_idmap_unix_to_sid(test_ctx->idmap_ctx, TEST_OFFSET - 1, &sid);
296 1 : assert_int_equal(err, IDMAP_NO_DOMAIN);
297 :
298 1 : err = sss_idmap_sid_to_unix(test_ctx->idmap_ctx, TEST_DOM_SID"-0", &id);
299 1 : assert_int_equal(err, IDMAP_EXTERNAL);
300 :
301 1 : err = sss_idmap_unix_to_sid(test_ctx->idmap_ctx, TEST_RANGE_MIN, &sid);
302 1 : assert_int_equal(err, IDMAP_EXTERNAL);
303 :
304 1 : err = sss_idmap_sid_to_unix(test_ctx->idmap_ctx,
305 : TEST_DOM_SID"-"TEST_OFFSET_STR, &id);
306 1 : assert_int_equal(err, IDMAP_EXTERNAL);
307 :
308 1 : err = sss_idmap_unix_to_sid(test_ctx->idmap_ctx,
309 : TEST_RANGE_MIN + TEST_OFFSET, &sid);
310 1 : assert_int_equal(err, IDMAP_EXTERNAL);
311 1 : }
312 :
313 2 : void test_check_sid_id(void **state)
314 : {
315 : struct test_ctx *test_ctx;
316 : enum idmap_error_code err;
317 :
318 2 : test_ctx = talloc_get_type(*state, struct test_ctx);
319 :
320 2 : assert_non_null(test_ctx);
321 :
322 2 : err = sss_idmap_check_sid_unix(test_ctx->idmap_ctx, TEST_DOM_SID"-400000",
323 : TEST_RANGE_MIN-1);
324 2 : assert_int_equal(err, IDMAP_NO_RANGE);
325 :
326 2 : err = sss_idmap_check_sid_unix(test_ctx->idmap_ctx, TEST_DOM_SID"-400000",
327 : TEST_RANGE_MIN);
328 2 : assert_int_equal(err, IDMAP_SUCCESS);
329 :
330 2 : err = sss_idmap_check_sid_unix(test_ctx->idmap_ctx, TEST_DOM_SID"1-400000",
331 : TEST_RANGE_MIN);
332 2 : assert_int_equal(err, IDMAP_SID_UNKNOWN);
333 :
334 2 : err = sss_idmap_check_sid_unix(test_ctx->idmap_ctx, TEST_DOM_SID"-400000",
335 : TEST_RANGE_MAX + TEST_OFFSET);
336 2 : assert_int_equal(err, IDMAP_SUCCESS);
337 :
338 2 : err = sss_idmap_check_sid_unix(test_ctx->idmap_ctx, TEST_DOM_SID"-400000",
339 : TEST_RANGE_MAX + TEST_OFFSET + 1);
340 2 : assert_int_equal(err, IDMAP_NO_RANGE);
341 2 : }
342 :
343 1 : void test_has_algorithmic(void **state)
344 : {
345 : struct test_ctx *test_ctx;
346 : bool use_id_mapping;
347 : enum idmap_error_code err;
348 :
349 1 : test_ctx = talloc_get_type(*state, struct test_ctx);
350 :
351 1 : assert_non_null(test_ctx);
352 :
353 1 : err = sss_idmap_domain_has_algorithmic_mapping(NULL, NULL, &use_id_mapping);
354 1 : assert_int_equal(err, IDMAP_SID_INVALID);
355 :
356 1 : err = sss_idmap_domain_has_algorithmic_mapping(NULL, TEST_DOM_SID,
357 : &use_id_mapping);
358 1 : assert_int_equal(err, IDMAP_CONTEXT_INVALID);
359 :
360 1 : err = sss_idmap_domain_has_algorithmic_mapping(test_ctx->idmap_ctx, NULL,
361 : &use_id_mapping);
362 1 : assert_int_equal(err, IDMAP_SID_INVALID);
363 :
364 1 : err = sss_idmap_domain_has_algorithmic_mapping(test_ctx->idmap_ctx,
365 : TEST_DOM_SID"1",
366 : &use_id_mapping);
367 1 : assert_int_equal(err, IDMAP_SID_UNKNOWN);
368 :
369 1 : err = sss_idmap_domain_has_algorithmic_mapping(test_ctx->idmap_ctx,
370 : TEST_DOM_SID,
371 : &use_id_mapping);
372 1 : assert_int_equal(err, IDMAP_SUCCESS);
373 1 : assert_true(use_id_mapping);
374 :
375 1 : err = sss_idmap_domain_has_algorithmic_mapping(test_ctx->idmap_ctx,
376 : TEST_2_DOM_SID,
377 : &use_id_mapping);
378 1 : assert_int_equal(err, IDMAP_SUCCESS);
379 1 : assert_false(use_id_mapping);
380 1 : }
381 :
382 1 : void test_has_algorithmic_by_name(void **state)
383 : {
384 : struct test_ctx *test_ctx;
385 : bool use_id_mapping;
386 : enum idmap_error_code err;
387 :
388 1 : test_ctx = talloc_get_type(*state, struct test_ctx);
389 :
390 1 : assert_non_null(test_ctx);
391 :
392 1 : err = sss_idmap_domain_by_name_has_algorithmic_mapping(NULL, NULL, &use_id_mapping);
393 1 : assert_int_equal(err, IDMAP_ERROR);
394 :
395 1 : err = sss_idmap_domain_by_name_has_algorithmic_mapping(NULL, TEST_DOM_SID,
396 : &use_id_mapping);
397 1 : assert_int_equal(err, IDMAP_CONTEXT_INVALID);
398 :
399 1 : err = sss_idmap_domain_by_name_has_algorithmic_mapping(test_ctx->idmap_ctx, NULL,
400 : &use_id_mapping);
401 1 : assert_int_equal(err, IDMAP_ERROR);
402 :
403 1 : err = sss_idmap_domain_by_name_has_algorithmic_mapping(test_ctx->idmap_ctx,
404 : TEST_DOM_NAME"1",
405 : &use_id_mapping);
406 1 : assert_int_equal(err, IDMAP_NAME_UNKNOWN);
407 :
408 1 : err = sss_idmap_domain_by_name_has_algorithmic_mapping(test_ctx->idmap_ctx,
409 : TEST_DOM_NAME,
410 : &use_id_mapping);
411 1 : assert_int_equal(err, IDMAP_SUCCESS);
412 1 : assert_true(use_id_mapping);
413 :
414 1 : err = sss_idmap_domain_by_name_has_algorithmic_mapping(test_ctx->idmap_ctx,
415 : TEST_2_DOM_NAME,
416 : &use_id_mapping);
417 1 : assert_int_equal(err, IDMAP_SUCCESS);
418 1 : assert_false(use_id_mapping);
419 1 : }
420 :
421 1 : void test_sss_idmap_check_collision_ex(void **state)
422 : {
423 : enum idmap_error_code err;
424 1 : struct sss_idmap_range r1 = {TEST_RANGE_MIN, TEST_RANGE_MAX};
425 1 : struct sss_idmap_range r2 = {TEST_2_RANGE_MIN, TEST_2_RANGE_MAX};
426 :
427 1 : err = sss_idmap_check_collision_ex(TEST_DOM_NAME, TEST_DOM_SID, &r1,
428 : TEST_FIRST_RID, NULL,
429 : TEST_EXT_MAPPING,
430 : TEST_2_DOM_NAME, TEST_2_DOM_SID, &r2,
431 : TEST_2_FIRST_RID, NULL,
432 : TEST_2_EXT_MAPPING);
433 1 : assert_int_equal(err, IDMAP_SUCCESS);
434 :
435 : /* Same name, different SID */
436 1 : err = sss_idmap_check_collision_ex(TEST_DOM_NAME, TEST_DOM_SID, &r1,
437 : TEST_FIRST_RID, NULL,
438 : TEST_EXT_MAPPING,
439 : TEST_DOM_NAME, TEST_2_DOM_SID, &r2,
440 : TEST_2_FIRST_RID, NULL,
441 : TEST_2_EXT_MAPPING);
442 1 : assert_int_equal(err, IDMAP_COLLISION);
443 :
444 : /* Same SID, different name */
445 1 : err = sss_idmap_check_collision_ex(TEST_DOM_NAME, TEST_DOM_SID, &r1,
446 : TEST_FIRST_RID, NULL,
447 : TEST_EXT_MAPPING,
448 : TEST_2_DOM_NAME, TEST_DOM_SID, &r2,
449 : TEST_2_FIRST_RID, NULL,
450 : TEST_2_EXT_MAPPING);
451 1 : assert_int_equal(err, IDMAP_COLLISION);
452 :
453 : /* Same SID and name, no overlaps */
454 1 : err = sss_idmap_check_collision_ex(TEST_DOM_NAME, TEST_DOM_SID, &r1,
455 : TEST_FIRST_RID, NULL,
456 : TEST_EXT_MAPPING,
457 : TEST_DOM_NAME, TEST_DOM_SID, &r2,
458 : TEST_2_FIRST_RID, NULL,
459 : TEST_2_EXT_MAPPING);
460 1 : assert_int_equal(err, IDMAP_SUCCESS);
461 :
462 : /* Same SID and name, different mappings */
463 1 : err = sss_idmap_check_collision_ex(TEST_DOM_NAME, TEST_DOM_SID, &r1,
464 : TEST_FIRST_RID, NULL,
465 : TEST_EXT_MAPPING,
466 : TEST_DOM_NAME, TEST_DOM_SID, &r2,
467 : TEST_2_FIRST_RID, NULL,
468 : !TEST_EXT_MAPPING);
469 1 : assert_int_equal(err, IDMAP_COLLISION);
470 :
471 : /* Same SID and name, Overlapping RID range */
472 1 : err = sss_idmap_check_collision_ex(TEST_DOM_NAME, TEST_DOM_SID, &r1,
473 : TEST_FIRST_RID, NULL,
474 : false,
475 : TEST_DOM_NAME, TEST_DOM_SID, &r2,
476 : TEST_FIRST_RID, NULL,
477 : false);
478 1 : assert_int_equal(err, IDMAP_COLLISION);
479 :
480 : /* Different SID and name, Overlapping RID range */
481 1 : err = sss_idmap_check_collision_ex(TEST_DOM_NAME, TEST_DOM_SID, &r1,
482 : TEST_FIRST_RID, NULL,
483 : false,
484 : TEST_2_DOM_NAME, TEST_2_DOM_SID, &r2,
485 : TEST_FIRST_RID, NULL,
486 : false);
487 1 : assert_int_equal(err, IDMAP_SUCCESS);
488 :
489 :
490 : /* Overlapping ranges with no external mapping */
491 1 : err = sss_idmap_check_collision_ex(TEST_DOM_NAME, TEST_DOM_SID, &r1,
492 : TEST_FIRST_RID, NULL,
493 : false,
494 : TEST_2_DOM_NAME, TEST_2_DOM_SID, &r1,
495 : TEST_2_FIRST_RID, NULL,
496 : false);
497 1 : assert_int_equal(err, IDMAP_COLLISION);
498 :
499 : /* Overlapping ranges with external mapping */
500 1 : err = sss_idmap_check_collision_ex(TEST_DOM_NAME, TEST_DOM_SID, &r1,
501 : TEST_FIRST_RID, NULL,
502 : true,
503 : TEST_2_DOM_NAME, TEST_2_DOM_SID, &r1,
504 : TEST_2_FIRST_RID, NULL,
505 : true);
506 1 : assert_int_equal(err, IDMAP_SUCCESS);
507 1 : }
508 :
509 1 : int main(int argc, const char *argv[])
510 : {
511 : poptContext pc;
512 : int opt;
513 6 : struct poptOption long_options[] = {
514 : POPT_AUTOHELP
515 5 : SSSD_DEBUG_OPTS
516 : POPT_TABLEEND
517 : };
518 :
519 1 : const struct CMUnitTest tests[] = {
520 : cmocka_unit_test_setup_teardown(test_add_domain,
521 : test_sss_idmap_setup,
522 : test_sss_idmap_teardown),
523 : cmocka_unit_test_setup_teardown(test_map_id,
524 : test_sss_idmap_setup_with_domains,
525 : test_sss_idmap_teardown),
526 : cmocka_unit_test_setup_teardown(test_map_id_external,
527 : test_sss_idmap_setup_with_external_mappings,
528 : test_sss_idmap_teardown),
529 : cmocka_unit_test_setup_teardown(test_check_sid_id,
530 : test_sss_idmap_setup_with_domains,
531 : test_sss_idmap_teardown),
532 : cmocka_unit_test_setup_teardown(test_check_sid_id,
533 : test_sss_idmap_setup_with_external_mappings,
534 : test_sss_idmap_teardown),
535 : cmocka_unit_test_setup_teardown(test_has_algorithmic,
536 : test_sss_idmap_setup_with_both,
537 : test_sss_idmap_teardown),
538 : cmocka_unit_test_setup_teardown(test_has_algorithmic_by_name,
539 : test_sss_idmap_setup_with_both,
540 : test_sss_idmap_teardown),
541 : cmocka_unit_test(test_sss_idmap_check_collision_ex),
542 : };
543 :
544 : /* Set debug level to invalid value so we can deside if -d 0 was used. */
545 1 : debug_level = SSSDBG_INVALID;
546 :
547 1 : pc = poptGetContext(argv[0], argc, argv, long_options, 0);
548 1 : while((opt = poptGetNextOpt(pc)) != -1) {
549 : switch(opt) {
550 : default:
551 0 : fprintf(stderr, "\nInvalid option %s: %s\n\n",
552 : poptBadOption(pc, 0), poptStrerror(opt));
553 0 : poptPrintUsage(pc, stderr, 0);
554 0 : return 1;
555 : }
556 : }
557 1 : poptFreeContext(pc);
558 :
559 1 : DEBUG_CLI_INIT(debug_level);
560 :
561 1 : tests_set_cwd();
562 :
563 1 : return cmocka_run_group_tests(tests, NULL, NULL);
564 : }
|