Line data Source code
1 : /*
2 : Authors:
3 : Pavel Březina <pbrezina@redhat.com>
4 :
5 : Copyright (C) 2014 Red Hat
6 :
7 : This program is free software; you can redistribute it and/or modify
8 : it under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3 of the License, or
10 : (at your option) any later version.
11 :
12 : This program is distributed in the hope that it will be useful,
13 : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : GNU General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with this program. If not, see <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : #include <dbus/dbus.h>
22 : #include <popt.h>
23 :
24 : #include "tests/cmocka/common_mock.h"
25 : #include "lib/sifp/sss_sifp.h"
26 : #include "lib/sifp/sss_sifp_dbus.h"
27 : #include "lib/sifp/sss_sifp_private.h"
28 :
29 : struct {
30 : sss_sifp_ctx *dbus_ctx;
31 : DBusMessage *reply;
32 : } test_ctx;
33 :
34 : DBusConnection *
35 46 : __wrap_dbus_bus_get(DBusBusType type, DBusError *error)
36 : {
37 : /* we won't use the connection anywhere, so we can just return NULL */
38 46 : return NULL;
39 : }
40 :
41 : DBusMessage *
42 12 : __wrap_dbus_connection_send_with_reply_and_block(DBusConnection *connection,
43 : DBusMessage *message,
44 : int timeout_milliseconds,
45 : DBusError *error)
46 : {
47 12 : if (message == NULL || error == NULL) {
48 0 : return NULL;
49 : }
50 :
51 12 : return sss_mock_ptr_type(DBusMessage *);
52 : }
53 :
54 12 : static void reply_variant_basic(DBusMessage *reply,
55 : const char *type,
56 : const void *val)
57 : {
58 : DBusMessageIter iter;
59 : DBusMessageIter variant_iter;
60 : dbus_bool_t bret;
61 :
62 12 : dbus_message_iter_init_append(reply, &iter);
63 :
64 :
65 12 : bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
66 : type, &variant_iter);
67 12 : assert_true(bret);
68 :
69 : /* Now add the value */
70 12 : bret = dbus_message_iter_append_basic(&variant_iter, type[0], val);
71 12 : assert_true(bret);
72 :
73 12 : bret = dbus_message_iter_close_container(&iter, &variant_iter);
74 12 : assert_true(bret);
75 12 : }
76 :
77 14 : static void reply_variant_array(DBusMessage *reply,
78 : const char *type,
79 : int num_vals,
80 : uint8_t *vals,
81 : unsigned int item_size)
82 : {
83 : DBusMessageIter iter;
84 : DBusMessageIter variant_iter;
85 : DBusMessageIter array_iter;
86 : dbus_bool_t bret;
87 : char array_type[3];
88 : int i;
89 : void *addr;
90 :
91 14 : array_type[0] = DBUS_TYPE_ARRAY;
92 14 : array_type[1] = type[0];
93 14 : array_type[2] = '\0';
94 :
95 14 : dbus_message_iter_init_append(reply, &iter);
96 :
97 :
98 14 : bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
99 : array_type, &variant_iter);
100 14 : assert_true(bret);
101 :
102 14 : bret = dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
103 : type, &array_iter);
104 14 : assert_true(bret);
105 :
106 47 : for (i = 0; i < num_vals; i++) {
107 33 : addr = vals + i*item_size;
108 33 : bret = dbus_message_iter_append_basic(&array_iter, type[0], addr);
109 33 : assert_true(bret);
110 : }
111 :
112 14 : bret = dbus_message_iter_close_container(&iter, &array_iter);
113 14 : assert_true(bret);
114 :
115 14 : bret = dbus_message_iter_close_container(&iter, &variant_iter);
116 14 : assert_true(bret);
117 14 : }
118 :
119 46 : static int test_setup(void **state)
120 : {
121 : sss_sifp_error ret;
122 :
123 46 : ret = sss_sifp_init(&test_ctx.dbus_ctx);
124 46 : assert_int_equal(ret, SSS_SIFP_OK);
125 :
126 46 : test_ctx.reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
127 46 : assert_non_null(test_ctx.reply);
128 46 : return 0;
129 : }
130 :
131 37 : static int test_teardown_parser(void **state)
132 : {
133 37 : sss_sifp_free(&test_ctx.dbus_ctx);
134 37 : assert_null(test_ctx.dbus_ctx);
135 :
136 37 : dbus_message_unref(test_ctx.reply);
137 37 : test_ctx.reply = NULL;
138 37 : return 0;
139 : }
140 :
141 9 : static int test_teardown_api(void **state)
142 : {
143 9 : sss_sifp_free(&test_ctx.dbus_ctx);
144 9 : assert_null(test_ctx.dbus_ctx);
145 :
146 : /* sss_sifp is responsible for freeing the reply */
147 9 : return 0;
148 : }
149 :
150 1 : void test_sss_sifp_strdup_valid(void **state)
151 : {
152 1 : const char *str = "test_string";
153 1 : char *dup = sss_sifp_strdup(test_ctx.dbus_ctx, str);
154 1 : assert_non_null(dup);
155 1 : assert_string_equal(str, dup);
156 :
157 1 : sss_sifp_free_string(test_ctx.dbus_ctx, &dup);
158 1 : assert_null(dup);
159 1 : }
160 :
161 1 : void test_sss_sifp_strdup_null(void **state)
162 : {
163 1 : char *dup = sss_sifp_strdup(test_ctx.dbus_ctx, NULL);
164 1 : assert_null(dup);
165 1 : }
166 :
167 1 : void test_sss_sifp_strcat_valid(void **state)
168 : {
169 1 : char *cat = sss_sifp_strcat(test_ctx.dbus_ctx, "hello ", "world");
170 1 : assert_non_null(cat);
171 1 : assert_string_equal("hello world", cat);
172 :
173 1 : sss_sifp_free_string(test_ctx.dbus_ctx, &cat);
174 1 : assert_null(cat);
175 1 : }
176 :
177 1 : void test_sss_sifp_strcat_left_null(void **state)
178 : {
179 1 : char *cat = sss_sifp_strcat(test_ctx.dbus_ctx, NULL, "world");
180 1 : assert_non_null(cat);
181 1 : assert_string_equal("world", cat);
182 :
183 1 : sss_sifp_free_string(test_ctx.dbus_ctx, &cat);
184 1 : assert_null(cat);
185 1 : }
186 :
187 1 : void test_sss_sifp_strcat_right_null(void **state)
188 : {
189 1 : char *cat = sss_sifp_strcat(test_ctx.dbus_ctx, "hello ", NULL);
190 1 : assert_non_null(cat);
191 1 : assert_string_equal("hello ", cat);
192 :
193 1 : sss_sifp_free_string(test_ctx.dbus_ctx, &cat);
194 1 : assert_null(cat);
195 1 : }
196 :
197 1 : void test_sss_sifp_strcat_both_null(void **state)
198 : {
199 1 : char *cat = sss_sifp_strcat(test_ctx.dbus_ctx, NULL, NULL);
200 1 : assert_null(cat);
201 1 : }
202 :
203 1 : void test_sss_sifp_parse_object_path_valid(void **state)
204 : {
205 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
206 1 : DBusMessage *reply = test_ctx.reply;
207 : dbus_bool_t bret;
208 : sss_sifp_error ret;
209 1 : const char *path_in = "/object/path";
210 1 : char *path_out = NULL;
211 :
212 : /* prepare message */
213 1 : bret = dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path_in,
214 : DBUS_TYPE_INVALID);
215 1 : assert_true(bret);
216 :
217 : /* test */
218 1 : ret = sss_sifp_parse_object_path(ctx, reply, &path_out);
219 1 : assert_int_equal(ret, SSS_SIFP_OK);
220 1 : assert_non_null(path_out);
221 1 : assert_string_equal(path_in, path_out);
222 :
223 1 : sss_sifp_free_string(ctx, &path_out);
224 1 : assert_null(path_out);
225 1 : }
226 :
227 1 : void test_sss_sifp_parse_object_path_invalid(void **state)
228 : {
229 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
230 1 : DBusMessage *reply = test_ctx.reply;
231 : dbus_bool_t bret;
232 : sss_sifp_error ret;
233 1 : uint16_t path_in = 10;
234 1 : char *path_out = NULL;
235 :
236 : /* prepare message */
237 1 : bret = dbus_message_append_args(reply, DBUS_TYPE_UINT16, &path_in,
238 : DBUS_TYPE_INVALID);
239 1 : assert_true(bret);
240 :
241 : /* test */
242 1 : ret = sss_sifp_parse_object_path(ctx, reply, &path_out);
243 1 : assert_int_not_equal(ret, SSS_SIFP_OK);
244 1 : assert_null(path_out);
245 1 : }
246 :
247 1 : void test_sss_sifp_parse_object_path_list_valid(void **state)
248 : {
249 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
250 1 : DBusMessage *reply = test_ctx.reply;
251 : dbus_bool_t bret;
252 : sss_sifp_error ret;
253 1 : char **path_out = NULL;
254 1 : const char *path_in[] = {"/object/path1", "/object/path2"};
255 1 : const char **paths = path_in;
256 1 : int path_in_len = 2;
257 : int i;
258 :
259 : /* prepare message */
260 1 : bret = dbus_message_append_args(reply, DBUS_TYPE_ARRAY,
261 : DBUS_TYPE_OBJECT_PATH,
262 : &paths, path_in_len,
263 : DBUS_TYPE_INVALID);
264 1 : assert_true(bret);
265 :
266 : /* test */
267 1 : ret = sss_sifp_parse_object_path_list(ctx, reply, &path_out);
268 1 : assert_int_equal(ret, SSS_SIFP_OK);
269 1 : assert_non_null(path_out);
270 :
271 3 : for (i = 0; path_out[i] != NULL; i++) {
272 2 : assert_true(i < path_in_len);
273 2 : assert_non_null(path_out[i]);
274 2 : assert_string_equal(path_in[i], path_out[i]);
275 : }
276 :
277 1 : sss_sifp_free_string_array(ctx, &path_out);
278 1 : assert_null(path_out);
279 1 : }
280 :
281 1 : void test_sss_sifp_parse_object_path_list_invalid(void **state)
282 : {
283 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
284 1 : DBusMessage *reply = test_ctx.reply;
285 : dbus_bool_t bret;
286 : sss_sifp_error ret;
287 1 : char **path_out = NULL;
288 1 : const char *path_in = "/object/path";
289 :
290 : /* prepare message */
291 1 : bret = dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path_in,
292 : DBUS_TYPE_INVALID);
293 1 : assert_true(bret);
294 :
295 : /* test */
296 1 : ret = sss_sifp_parse_object_path_list(ctx, reply, &path_out);
297 1 : assert_int_not_equal(ret, SSS_SIFP_OK);
298 1 : assert_null(path_out);
299 1 : }
300 :
301 1 : void test_sss_sifp_parse_attr_bool(void **state)
302 : {
303 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
304 1 : DBusMessage *reply = test_ctx.reply;
305 : sss_sifp_error ret;
306 1 : sss_sifp_attr **attrs = NULL;
307 1 : const char *name = "test-attr";
308 1 : dbus_bool_t in = 1;
309 : bool out;
310 :
311 : /* prepare message */
312 1 : reply_variant_basic(reply, DBUS_TYPE_BOOLEAN_AS_STRING, &in);
313 :
314 : /* test */
315 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
316 :
317 1 : assert_int_equal(ret, SSS_SIFP_OK);
318 1 : assert_non_null(attrs);
319 1 : assert_non_null(attrs[0]);
320 1 : assert_null(attrs[1]);
321 :
322 1 : assert_int_equal(attrs[0]->num_values, 1);
323 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_BOOL);
324 1 : assert_string_equal(attrs[0]->name, name);
325 :
326 1 : ret = sss_sifp_find_attr_as_bool(attrs, name, &out);
327 1 : assert_int_equal(ret, SSS_SIFP_OK);
328 1 : assert_true(in == out);
329 :
330 1 : sss_sifp_free_attrs(ctx, &attrs);
331 1 : assert_null(attrs);
332 1 : }
333 :
334 1 : void test_sss_sifp_parse_attr_int16(void **state)
335 : {
336 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
337 1 : DBusMessage *reply = test_ctx.reply;
338 : sss_sifp_error ret;
339 1 : sss_sifp_attr **attrs = NULL;
340 1 : const char *name = "test-attr";
341 1 : int16_t in = INT16_MIN;
342 : int16_t out;
343 :
344 : /* prepare message */
345 1 : reply_variant_basic(reply, DBUS_TYPE_INT16_AS_STRING, &in);
346 :
347 : /* test */
348 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
349 :
350 1 : assert_int_equal(ret, SSS_SIFP_OK);
351 1 : assert_non_null(attrs);
352 1 : assert_non_null(attrs[0]);
353 1 : assert_null(attrs[1]);
354 :
355 1 : assert_int_equal(attrs[0]->num_values, 1);
356 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT16);
357 1 : assert_string_equal(attrs[0]->name, name);
358 :
359 1 : ret = sss_sifp_find_attr_as_int16(attrs, name, &out);
360 1 : assert_int_equal(ret, SSS_SIFP_OK);
361 1 : assert_int_equal(in, out);
362 :
363 1 : sss_sifp_free_attrs(ctx, &attrs);
364 1 : assert_null(attrs);
365 1 : }
366 :
367 1 : void test_sss_sifp_parse_attr_uint16(void **state)
368 : {
369 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
370 1 : DBusMessage *reply = test_ctx.reply;
371 : sss_sifp_error ret;
372 1 : sss_sifp_attr **attrs = NULL;
373 1 : const char *name = "test-attr";
374 1 : uint16_t in = UINT16_MAX;
375 : uint16_t out;
376 :
377 : /* prepare message */
378 1 : reply_variant_basic(reply, DBUS_TYPE_UINT16_AS_STRING, &in);
379 :
380 : /* test */
381 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
382 :
383 1 : assert_int_equal(ret, SSS_SIFP_OK);
384 1 : assert_non_null(attrs);
385 1 : assert_non_null(attrs[0]);
386 1 : assert_null(attrs[1]);
387 :
388 1 : assert_int_equal(attrs[0]->num_values, 1);
389 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT16);
390 1 : assert_string_equal(attrs[0]->name, name);
391 :
392 1 : ret = sss_sifp_find_attr_as_uint16(attrs, name, &out);
393 1 : assert_int_equal(ret, SSS_SIFP_OK);
394 1 : assert_int_equal(in, out);
395 :
396 1 : sss_sifp_free_attrs(ctx, &attrs);
397 1 : assert_null(attrs);
398 1 : }
399 :
400 1 : void test_sss_sifp_parse_attr_int32(void **state)
401 : {
402 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
403 1 : DBusMessage *reply = test_ctx.reply;
404 : sss_sifp_error ret;
405 1 : sss_sifp_attr **attrs = NULL;
406 1 : const char *name = "test-attr";
407 1 : int32_t in = INT32_MIN;
408 : int32_t out;
409 :
410 : /* prepare message */
411 1 : reply_variant_basic(reply, DBUS_TYPE_INT32_AS_STRING, &in);
412 :
413 : /* test */
414 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
415 :
416 1 : assert_int_equal(ret, SSS_SIFP_OK);
417 1 : assert_non_null(attrs);
418 1 : assert_non_null(attrs[0]);
419 1 : assert_null(attrs[1]);
420 :
421 1 : assert_int_equal(attrs[0]->num_values, 1);
422 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT32);
423 1 : assert_string_equal(attrs[0]->name, name);
424 :
425 1 : ret = sss_sifp_find_attr_as_int32(attrs, name, &out);
426 1 : assert_int_equal(ret, SSS_SIFP_OK);
427 1 : assert_int_equal(in, out);
428 :
429 1 : sss_sifp_free_attrs(ctx, &attrs);
430 1 : assert_null(attrs);
431 1 : }
432 :
433 1 : void test_sss_sifp_parse_attr_uint32(void **state)
434 : {
435 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
436 1 : DBusMessage *reply = test_ctx.reply;
437 : sss_sifp_error ret;
438 1 : sss_sifp_attr **attrs = NULL;
439 1 : const char *name = "test-attr";
440 1 : uint32_t in = UINT32_MAX;
441 : uint32_t out;
442 :
443 : /* prepare message */
444 1 : reply_variant_basic(reply, DBUS_TYPE_UINT32_AS_STRING, &in);
445 :
446 : /* test */
447 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
448 :
449 1 : assert_int_equal(ret, SSS_SIFP_OK);
450 1 : assert_non_null(attrs);
451 1 : assert_non_null(attrs[0]);
452 1 : assert_null(attrs[1]);
453 :
454 1 : assert_int_equal(attrs[0]->num_values, 1);
455 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT32);
456 1 : assert_string_equal(attrs[0]->name, name);
457 :
458 1 : ret = sss_sifp_find_attr_as_uint32(attrs, name, &out);
459 1 : assert_int_equal(ret, SSS_SIFP_OK);
460 1 : assert_int_equal(in, out);
461 :
462 1 : sss_sifp_free_attrs(ctx, &attrs);
463 1 : assert_null(attrs);
464 :
465 1 : sss_sifp_free_attrs(ctx, &attrs);
466 1 : assert_null(attrs);
467 1 : }
468 :
469 1 : void test_sss_sifp_parse_attr_int64(void **state)
470 : {
471 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
472 1 : DBusMessage *reply = test_ctx.reply;
473 : sss_sifp_error ret;
474 1 : sss_sifp_attr **attrs = NULL;
475 1 : const char *name = "test-attr";
476 1 : int64_t in = INT64_MIN;
477 : int64_t out;
478 :
479 : /* prepare message */
480 1 : reply_variant_basic(reply, DBUS_TYPE_INT64_AS_STRING, &in);
481 :
482 : /* test */
483 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
484 :
485 1 : assert_int_equal(ret, SSS_SIFP_OK);
486 1 : assert_non_null(attrs);
487 1 : assert_non_null(attrs[0]);
488 1 : assert_null(attrs[1]);
489 :
490 1 : assert_int_equal(attrs[0]->num_values, 1);
491 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT64);
492 1 : assert_string_equal(attrs[0]->name, name);
493 :
494 1 : ret = sss_sifp_find_attr_as_int64(attrs, name, &out);
495 1 : assert_int_equal(ret, SSS_SIFP_OK);
496 1 : assert_int_equal(in, out);
497 :
498 1 : sss_sifp_free_attrs(ctx, &attrs);
499 1 : assert_null(attrs);
500 1 : }
501 :
502 1 : void test_sss_sifp_parse_attr_uint64(void **state)
503 : {
504 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
505 1 : DBusMessage *reply = test_ctx.reply;
506 : sss_sifp_error ret;
507 1 : sss_sifp_attr **attrs = NULL;
508 1 : const char *name = "test-attr";
509 1 : uint64_t in = UINT64_MAX;
510 : uint64_t out;
511 :
512 : /* prepare message */
513 1 : reply_variant_basic(reply, DBUS_TYPE_UINT64_AS_STRING, &in);
514 :
515 : /* test */
516 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
517 :
518 1 : assert_int_equal(ret, SSS_SIFP_OK);
519 1 : assert_non_null(attrs);
520 1 : assert_non_null(attrs[0]);
521 1 : assert_null(attrs[1]);
522 :
523 1 : assert_int_equal(attrs[0]->num_values, 1);
524 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT64);
525 1 : assert_string_equal(attrs[0]->name, name);
526 :
527 1 : ret = sss_sifp_find_attr_as_uint64(attrs, name, &out);
528 1 : assert_int_equal(ret, SSS_SIFP_OK);
529 1 : assert_int_equal(in, out);
530 :
531 1 : sss_sifp_free_attrs(ctx, &attrs);
532 1 : assert_null(attrs);
533 1 : }
534 :
535 1 : void test_sss_sifp_parse_attr_string(void **state)
536 : {
537 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
538 1 : DBusMessage *reply = test_ctx.reply;
539 : sss_sifp_error ret;
540 1 : sss_sifp_attr **attrs = NULL;
541 1 : const char *name = "test-attr";
542 1 : const char *in = "test value";
543 : const char *out;
544 :
545 : /* prepare message */
546 1 : reply_variant_basic(reply, DBUS_TYPE_STRING_AS_STRING, &in);
547 :
548 : /* test */
549 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
550 :
551 1 : assert_int_equal(ret, SSS_SIFP_OK);
552 1 : assert_non_null(attrs);
553 1 : assert_non_null(attrs[0]);
554 1 : assert_null(attrs[1]);
555 :
556 1 : assert_int_equal(attrs[0]->num_values, 1);
557 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING);
558 1 : assert_string_equal(attrs[0]->name, name);
559 :
560 1 : ret = sss_sifp_find_attr_as_string(attrs, name, &out);
561 1 : assert_int_equal(ret, SSS_SIFP_OK);
562 1 : assert_string_equal(in, out);
563 :
564 1 : sss_sifp_free_attrs(ctx, &attrs);
565 1 : assert_null(attrs);
566 1 : }
567 :
568 1 : void test_sss_sifp_parse_attr_object_path(void **state)
569 : {
570 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
571 1 : DBusMessage *reply = test_ctx.reply;
572 : sss_sifp_error ret;
573 1 : sss_sifp_attr **attrs = NULL;
574 1 : const char *name = "test-attr";
575 1 : const char *in = "/object/path";
576 : const char *out;
577 :
578 : /* prepare message */
579 1 : reply_variant_basic(reply, DBUS_TYPE_OBJECT_PATH_AS_STRING, &in);
580 :
581 : /* test */
582 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
583 :
584 1 : assert_int_equal(ret, SSS_SIFP_OK);
585 1 : assert_non_null(attrs);
586 1 : assert_non_null(attrs[0]);
587 1 : assert_null(attrs[1]);
588 :
589 1 : assert_int_equal(attrs[0]->num_values, 1);
590 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING);
591 1 : assert_string_equal(attrs[0]->name, name);
592 :
593 1 : ret = sss_sifp_find_attr_as_string(attrs, name, &out);
594 1 : assert_int_equal(ret, SSS_SIFP_OK);
595 1 : assert_string_equal(in, out);
596 :
597 1 : sss_sifp_free_attrs(ctx, &attrs);
598 1 : assert_null(attrs);
599 1 : }
600 :
601 1 : void test_sss_sifp_parse_attr_string_dict(void **state)
602 : {
603 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
604 1 : DBusMessage *reply = test_ctx.reply;
605 : DBusMessageIter iter;
606 : DBusMessageIter var_iter;
607 : DBusMessageIter array_iter;
608 : DBusMessageIter dict_iter;
609 : dbus_bool_t bret;
610 : sss_sifp_error ret;
611 1 : sss_sifp_attr **attrs = NULL;
612 1 : const char *name = "test-attr";
613 : struct {
614 : const char *key;
615 : const char *value;
616 1 : } data = {"key", "value"};
617 : hash_table_t *out;
618 : hash_key_t key;
619 : hash_value_t value;
620 : char **values;
621 : int hret;
622 :
623 : /* prepare message */
624 1 : dbus_message_iter_init_append(reply, &iter);
625 :
626 1 : bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
627 : DBUS_TYPE_ARRAY_AS_STRING
628 : DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
629 : DBUS_TYPE_STRING_AS_STRING
630 : DBUS_TYPE_STRING_AS_STRING
631 : DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
632 : &var_iter);
633 1 : assert_true(bret);
634 :
635 1 : bret = dbus_message_iter_open_container(&var_iter, DBUS_TYPE_ARRAY,
636 : DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
637 : DBUS_TYPE_STRING_AS_STRING
638 : DBUS_TYPE_STRING_AS_STRING
639 : DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
640 : &array_iter);
641 1 : assert_true(bret);
642 :
643 1 : bret = dbus_message_iter_open_container(&array_iter,
644 : DBUS_TYPE_DICT_ENTRY,
645 : NULL, &dict_iter);
646 1 : assert_true(bret);
647 :
648 1 : bret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING,
649 : &data.key);
650 1 : assert_true(bret);
651 :
652 1 : bret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING,
653 : &data.value);
654 1 : assert_true(bret);
655 :
656 1 : bret = dbus_message_iter_close_container(&array_iter, &dict_iter);
657 1 : assert_true(bret);
658 :
659 1 : bret = dbus_message_iter_close_container(&var_iter, &array_iter);
660 1 : assert_true(bret);
661 :
662 1 : bret = dbus_message_iter_close_container(&iter, &var_iter);
663 1 : assert_true(bret);
664 :
665 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
666 1 : assert_int_equal(ret, SSS_SIFP_OK);
667 1 : assert_non_null(attrs);
668 1 : assert_non_null(attrs[0]);
669 1 : assert_null(attrs[1]);
670 :
671 1 : assert_int_equal(attrs[0]->num_values, 1);
672 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING_DICT);
673 1 : assert_string_equal(attrs[0]->name, name);
674 :
675 1 : ret = sss_sifp_find_attr_as_string_dict(attrs, name, &out);
676 1 : assert_int_equal(ret, SSS_SIFP_OK);
677 1 : assert_int_equal(hash_count(out), 1);
678 :
679 1 : key.type = HASH_KEY_STRING;
680 1 : key.str = discard_const(data.key);
681 1 : hret = hash_lookup(out, &key, &value);
682 1 : assert_int_equal(hret, HASH_SUCCESS);
683 1 : assert_int_equal(value.type, HASH_VALUE_PTR);
684 1 : assert_non_null(value.ptr);
685 1 : values = value.ptr;
686 1 : assert_non_null(values[0]);
687 1 : assert_string_equal(values[0], data.value);
688 1 : assert_null(values[1]);
689 :
690 1 : sss_sifp_free_attrs(ctx, &attrs);
691 1 : assert_null(attrs);
692 1 : }
693 :
694 1 : void test_sss_sifp_parse_attr_bool_array(void **state)
695 : {
696 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
697 1 : DBusMessage *reply = test_ctx.reply;
698 : sss_sifp_error ret;
699 1 : sss_sifp_attr **attrs = NULL;
700 1 : const char *name = "test-attr";
701 1 : unsigned int num_values = 5;
702 1 : dbus_bool_t in_array[] = {1, 1, 0, 0, 1};
703 1 : dbus_bool_t *in = in_array;
704 : unsigned int out_num;
705 : bool *out;
706 : unsigned int i;
707 :
708 : /* prepare message */
709 1 : reply_variant_array(reply, DBUS_TYPE_BOOLEAN_AS_STRING, num_values,
710 : (uint8_t*)in, sizeof(dbus_bool_t));
711 :
712 : /* test */
713 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
714 :
715 1 : assert_int_equal(ret, SSS_SIFP_OK);
716 1 : assert_non_null(attrs);
717 1 : assert_non_null(attrs[0]);
718 1 : assert_null(attrs[1]);
719 :
720 1 : assert_int_equal(attrs[0]->num_values, num_values);
721 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_BOOL);
722 1 : assert_string_equal(attrs[0]->name, name);
723 :
724 1 : ret = sss_sifp_find_attr_as_bool_array(attrs, name, &out_num, &out);
725 1 : assert_int_equal(ret, SSS_SIFP_OK);
726 1 : assert_int_equal(num_values, out_num);
727 :
728 6 : for (i = 0; i < num_values; i++) {
729 5 : assert_true(in[i] == out[i]);
730 : }
731 :
732 1 : sss_sifp_free_attrs(ctx, &attrs);
733 1 : assert_null(attrs);
734 1 : }
735 :
736 1 : void test_sss_sifp_parse_attr_bool_array_empty(void **state)
737 : {
738 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
739 1 : DBusMessage *reply = test_ctx.reply;
740 : sss_sifp_error ret;
741 1 : sss_sifp_attr **attrs = NULL;
742 1 : const char *name = "test-attr";
743 1 : unsigned int num_values = 0;
744 : unsigned int out_num;
745 : bool *out;
746 :
747 : /* prepare message */
748 1 : reply_variant_array(reply, DBUS_TYPE_BOOLEAN_AS_STRING, num_values,
749 : NULL, sizeof(dbus_bool_t));
750 :
751 : /* test */
752 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
753 :
754 1 : assert_int_equal(ret, SSS_SIFP_OK);
755 1 : assert_non_null(attrs);
756 1 : assert_non_null(attrs[0]);
757 1 : assert_null(attrs[1]);
758 :
759 1 : assert_int_equal(attrs[0]->num_values, num_values);
760 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_BOOL);
761 1 : assert_string_equal(attrs[0]->name, name);
762 :
763 1 : ret = sss_sifp_find_attr_as_bool_array(attrs, name, &out_num, &out);
764 1 : assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
765 1 : assert_int_equal(num_values, out_num);
766 1 : assert_null(out);
767 :
768 1 : sss_sifp_free_attrs(ctx, &attrs);
769 1 : assert_null(attrs);
770 1 : }
771 :
772 0 : void test_sss_sifp_parse_attr_int16_array(void **state)
773 : {
774 0 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
775 0 : DBusMessage *reply = test_ctx.reply;
776 : sss_sifp_error ret;
777 0 : sss_sifp_attr **attrs = NULL;
778 0 : const char *name = "test-attr";
779 0 : unsigned int num_values = 5;
780 0 : int16_t in_array[] = {10, 15, -10, -15, 5559};
781 0 : int16_t *in = in_array;
782 : unsigned int out_num;
783 : int16_t *out;
784 : unsigned int i;
785 :
786 : /* prepare message */
787 0 : reply_variant_array(reply, DBUS_TYPE_INT16_AS_STRING, num_values,
788 : (uint8_t*)in, sizeof(int16_t));
789 :
790 : /* test */
791 0 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
792 :
793 0 : assert_int_equal(ret, SSS_SIFP_OK);
794 0 : assert_non_null(attrs);
795 0 : assert_non_null(attrs[0]);
796 0 : assert_null(attrs[1]);
797 :
798 0 : assert_int_equal(attrs[0]->num_values, num_values);
799 0 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT16);
800 0 : assert_string_equal(attrs[0]->name, name);
801 :
802 0 : ret = sss_sifp_find_attr_as_int16_array(attrs, name, &out_num, &out);
803 0 : assert_int_equal(ret, SSS_SIFP_OK);
804 0 : assert_int_equal(num_values, out_num);
805 :
806 0 : for (i = 0; i < num_values; i++) {
807 0 : assert_int_equal(in[i], out[i]);
808 : }
809 :
810 0 : sss_sifp_free_attrs(ctx, &attrs);
811 0 : assert_null(attrs);
812 0 : }
813 :
814 0 : void test_sss_sifp_parse_attr_int16_array_empty(void **state)
815 : {
816 0 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
817 0 : DBusMessage *reply = test_ctx.reply;
818 : sss_sifp_error ret;
819 0 : sss_sifp_attr **attrs = NULL;
820 0 : const char *name = "test-attr";
821 0 : unsigned int num_values = 0;
822 : unsigned int out_num;
823 : int16_t *out;
824 :
825 : /* prepare message */
826 0 : reply_variant_array(reply, DBUS_TYPE_INT16_AS_STRING, num_values,
827 : NULL, sizeof(int16_t));
828 :
829 : /* test */
830 0 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
831 :
832 0 : assert_int_equal(ret, SSS_SIFP_OK);
833 0 : assert_non_null(attrs);
834 0 : assert_non_null(attrs[0]);
835 0 : assert_null(attrs[1]);
836 :
837 0 : assert_int_equal(attrs[0]->num_values, num_values);
838 0 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT16);
839 0 : assert_string_equal(attrs[0]->name, name);
840 :
841 0 : ret = sss_sifp_find_attr_as_int16_array(attrs, name, &out_num, &out);
842 0 : assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
843 0 : assert_int_equal(num_values, out_num);
844 0 : assert_null(out);
845 :
846 0 : sss_sifp_free_attrs(ctx, &attrs);
847 0 : assert_null(attrs);
848 0 : }
849 :
850 0 : void test_sss_sifp_parse_attr_uint16_array(void **state)
851 : {
852 0 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
853 0 : DBusMessage *reply = test_ctx.reply;
854 : sss_sifp_error ret;
855 0 : sss_sifp_attr **attrs = NULL;
856 0 : const char *name = "test-attr";
857 0 : unsigned int num_values = 5;
858 0 : uint16_t in_array[] = {10, 15, 8885, 3224, 5559};
859 0 : uint16_t *in = in_array;
860 : unsigned int out_num;
861 : uint16_t *out;
862 : unsigned int i;
863 :
864 : /* prepare message */
865 0 : reply_variant_array(reply, DBUS_TYPE_UINT16_AS_STRING, num_values,
866 : (uint8_t*)in, sizeof(uint16_t));
867 :
868 : /* test */
869 0 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
870 :
871 0 : assert_int_equal(ret, SSS_SIFP_OK);
872 0 : assert_non_null(attrs);
873 0 : assert_non_null(attrs[0]);
874 0 : assert_null(attrs[1]);
875 :
876 0 : assert_int_equal(attrs[0]->num_values, num_values);
877 0 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT16);
878 0 : assert_string_equal(attrs[0]->name, name);
879 :
880 0 : ret = sss_sifp_find_attr_as_uint16_array(attrs, name, &out_num, &out);
881 0 : assert_int_equal(ret, SSS_SIFP_OK);
882 0 : assert_int_equal(num_values, out_num);
883 :
884 0 : for (i = 0; i < num_values; i++) {
885 0 : assert_int_equal(in[i], out[i]);
886 : }
887 :
888 0 : sss_sifp_free_attrs(ctx, &attrs);
889 0 : assert_null(attrs);
890 0 : }
891 :
892 0 : void test_sss_sifp_parse_attr_uint16_array_empty(void **state)
893 : {
894 0 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
895 0 : DBusMessage *reply = test_ctx.reply;
896 : sss_sifp_error ret;
897 0 : sss_sifp_attr **attrs = NULL;
898 0 : const char *name = "test-attr";
899 0 : unsigned int num_values = 0;
900 : unsigned int out_num;
901 : uint16_t *out;
902 :
903 : /* prepare message */
904 0 : reply_variant_array(reply, DBUS_TYPE_UINT16_AS_STRING, num_values,
905 : NULL, sizeof(uint16_t));
906 :
907 : /* test */
908 0 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
909 :
910 0 : assert_int_equal(ret, SSS_SIFP_OK);
911 0 : assert_non_null(attrs);
912 0 : assert_non_null(attrs[0]);
913 0 : assert_null(attrs[1]);
914 :
915 0 : assert_int_equal(attrs[0]->num_values, num_values);
916 0 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT16);
917 0 : assert_string_equal(attrs[0]->name, name);
918 :
919 0 : ret = sss_sifp_find_attr_as_uint16_array(attrs, name, &out_num, &out);
920 0 : assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
921 0 : assert_int_equal(num_values, out_num);
922 0 : assert_null(out);
923 :
924 0 : sss_sifp_free_attrs(ctx, &attrs);
925 0 : assert_null(attrs);
926 0 : }
927 :
928 1 : void test_sss_sifp_parse_attr_int32_array(void **state)
929 : {
930 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
931 1 : DBusMessage *reply = test_ctx.reply;
932 : sss_sifp_error ret;
933 1 : sss_sifp_attr **attrs = NULL;
934 1 : const char *name = "test-attr";
935 1 : unsigned int num_values = 5;
936 1 : int32_t in_array[] = {10, 15, -10, -15, 5559};
937 1 : int32_t *in = in_array;
938 : unsigned int out_num;
939 : int32_t *out;
940 : unsigned int i;
941 :
942 : /* prepare message */
943 1 : reply_variant_array(reply, DBUS_TYPE_INT32_AS_STRING, num_values,
944 : (uint8_t*)in, sizeof(int32_t));
945 :
946 : /* test */
947 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
948 :
949 1 : assert_int_equal(ret, SSS_SIFP_OK);
950 1 : assert_non_null(attrs);
951 1 : assert_non_null(attrs[0]);
952 1 : assert_null(attrs[1]);
953 :
954 1 : assert_int_equal(attrs[0]->num_values, num_values);
955 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT32);
956 1 : assert_string_equal(attrs[0]->name, name);
957 :
958 1 : ret = sss_sifp_find_attr_as_int32_array(attrs, name, &out_num, &out);
959 1 : assert_int_equal(ret, SSS_SIFP_OK);
960 1 : assert_int_equal(num_values, out_num);
961 :
962 6 : for (i = 0; i < num_values; i++) {
963 5 : assert_int_equal(in[i], out[i]);
964 : }
965 :
966 1 : sss_sifp_free_attrs(ctx, &attrs);
967 1 : assert_null(attrs);
968 1 : }
969 :
970 1 : void test_sss_sifp_parse_attr_int32_array_empty(void **state)
971 : {
972 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
973 1 : DBusMessage *reply = test_ctx.reply;
974 : sss_sifp_error ret;
975 1 : sss_sifp_attr **attrs = NULL;
976 1 : const char *name = "test-attr";
977 1 : unsigned int num_values = 0;
978 : unsigned int out_num;
979 : int32_t *out;
980 :
981 : /* prepare message */
982 1 : reply_variant_array(reply, DBUS_TYPE_INT32_AS_STRING, num_values,
983 : NULL, sizeof(int32_t));
984 :
985 : /* test */
986 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
987 :
988 1 : assert_int_equal(ret, SSS_SIFP_OK);
989 1 : assert_non_null(attrs);
990 1 : assert_non_null(attrs[0]);
991 1 : assert_null(attrs[1]);
992 :
993 1 : assert_int_equal(attrs[0]->num_values, num_values);
994 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT32);
995 1 : assert_string_equal(attrs[0]->name, name);
996 :
997 1 : ret = sss_sifp_find_attr_as_int32_array(attrs, name, &out_num, &out);
998 1 : assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
999 1 : assert_int_equal(num_values, out_num);
1000 1 : assert_null(out);
1001 :
1002 1 : sss_sifp_free_attrs(ctx, &attrs);
1003 1 : assert_null(attrs);
1004 1 : }
1005 :
1006 1 : void test_sss_sifp_parse_attr_uint32_array(void **state)
1007 : {
1008 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1009 1 : DBusMessage *reply = test_ctx.reply;
1010 : sss_sifp_error ret;
1011 1 : sss_sifp_attr **attrs = NULL;
1012 1 : const char *name = "test-attr";
1013 1 : unsigned int num_values = 5;
1014 1 : uint32_t in_array[] = {10, 15, 8885, 3224, 5559};
1015 1 : uint32_t *in = in_array;
1016 : unsigned int out_num;
1017 : uint32_t *out;
1018 : unsigned int i;
1019 :
1020 : /* prepare message */
1021 1 : reply_variant_array(reply, DBUS_TYPE_UINT32_AS_STRING, num_values,
1022 : (uint8_t*)in, sizeof(uint32_t));
1023 :
1024 : /* test */
1025 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
1026 :
1027 1 : assert_int_equal(ret, SSS_SIFP_OK);
1028 1 : assert_non_null(attrs);
1029 1 : assert_non_null(attrs[0]);
1030 1 : assert_null(attrs[1]);
1031 :
1032 1 : assert_int_equal(attrs[0]->num_values, num_values);
1033 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT32);
1034 1 : assert_string_equal(attrs[0]->name, name);
1035 :
1036 1 : ret = sss_sifp_find_attr_as_uint32_array(attrs, name, &out_num, &out);
1037 1 : assert_int_equal(ret, SSS_SIFP_OK);
1038 1 : assert_int_equal(num_values, out_num);
1039 :
1040 6 : for (i = 0; i < num_values; i++) {
1041 5 : assert_int_equal(in[i], out[i]);
1042 : }
1043 :
1044 1 : sss_sifp_free_attrs(ctx, &attrs);
1045 1 : assert_null(attrs);
1046 1 : }
1047 :
1048 1 : void test_sss_sifp_parse_attr_uint32_array_empty(void **state)
1049 : {
1050 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1051 1 : DBusMessage *reply = test_ctx.reply;
1052 : sss_sifp_error ret;
1053 1 : sss_sifp_attr **attrs = NULL;
1054 1 : const char *name = "test-attr";
1055 1 : unsigned int num_values = 0;
1056 : unsigned int out_num;
1057 : uint32_t *out;
1058 :
1059 : /* prepare message */
1060 1 : reply_variant_array(reply, DBUS_TYPE_UINT32_AS_STRING, num_values,
1061 : NULL, sizeof(uint32_t));
1062 :
1063 : /* test */
1064 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
1065 :
1066 1 : assert_int_equal(ret, SSS_SIFP_OK);
1067 1 : assert_non_null(attrs);
1068 1 : assert_non_null(attrs[0]);
1069 1 : assert_null(attrs[1]);
1070 :
1071 1 : assert_int_equal(attrs[0]->num_values, num_values);
1072 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT32);
1073 1 : assert_string_equal(attrs[0]->name, name);
1074 :
1075 1 : ret = sss_sifp_find_attr_as_uint32_array(attrs, name, &out_num, &out);
1076 1 : assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
1077 1 : assert_int_equal(num_values, out_num);
1078 1 : assert_null(out);
1079 :
1080 1 : sss_sifp_free_attrs(ctx, &attrs);
1081 1 : assert_null(attrs);
1082 1 : }
1083 :
1084 1 : void test_sss_sifp_parse_attr_int64_array(void **state)
1085 : {
1086 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1087 1 : DBusMessage *reply = test_ctx.reply;
1088 : sss_sifp_error ret;
1089 1 : sss_sifp_attr **attrs = NULL;
1090 1 : const char *name = "test-attr";
1091 1 : unsigned int num_values = 5;
1092 1 : int64_t in_array[] = {10, 15, -10, -15, 5559};
1093 1 : int64_t *in = in_array;
1094 : unsigned int out_num;
1095 : int64_t *out;
1096 : unsigned int i;
1097 :
1098 : /* prepare message */
1099 1 : reply_variant_array(reply, DBUS_TYPE_INT64_AS_STRING, num_values,
1100 : (uint8_t*)in, sizeof(int64_t));
1101 :
1102 : /* test */
1103 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
1104 :
1105 1 : assert_int_equal(ret, SSS_SIFP_OK);
1106 1 : assert_non_null(attrs);
1107 1 : assert_non_null(attrs[0]);
1108 1 : assert_null(attrs[1]);
1109 :
1110 1 : assert_int_equal(attrs[0]->num_values, num_values);
1111 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT64);
1112 1 : assert_string_equal(attrs[0]->name, name);
1113 :
1114 1 : ret = sss_sifp_find_attr_as_int64_array(attrs, name, &out_num, &out);
1115 1 : assert_int_equal(ret, SSS_SIFP_OK);
1116 1 : assert_int_equal(num_values, out_num);
1117 :
1118 6 : for (i = 0; i < num_values; i++) {
1119 5 : assert_int_equal(in[i], out[i]);
1120 : }
1121 :
1122 1 : sss_sifp_free_attrs(ctx, &attrs);
1123 1 : assert_null(attrs);
1124 1 : }
1125 :
1126 1 : void test_sss_sifp_parse_attr_int64_array_empty(void **state)
1127 : {
1128 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1129 1 : DBusMessage *reply = test_ctx.reply;
1130 : sss_sifp_error ret;
1131 1 : sss_sifp_attr **attrs = NULL;
1132 1 : const char *name = "test-attr";
1133 1 : unsigned int num_values = 0;
1134 : unsigned int out_num;
1135 : int64_t *out;
1136 :
1137 : /* prepare message */
1138 1 : reply_variant_array(reply, DBUS_TYPE_INT64_AS_STRING, num_values,
1139 : NULL, sizeof(int64_t));
1140 :
1141 : /* test */
1142 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
1143 :
1144 1 : assert_int_equal(ret, SSS_SIFP_OK);
1145 1 : assert_non_null(attrs);
1146 1 : assert_non_null(attrs[0]);
1147 1 : assert_null(attrs[1]);
1148 :
1149 1 : assert_int_equal(attrs[0]->num_values, num_values);
1150 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_INT64);
1151 1 : assert_string_equal(attrs[0]->name, name);
1152 :
1153 1 : ret = sss_sifp_find_attr_as_int64_array(attrs, name, &out_num, &out);
1154 1 : assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
1155 1 : assert_int_equal(num_values, out_num);
1156 1 : assert_null(out);
1157 :
1158 1 : sss_sifp_free_attrs(ctx, &attrs);
1159 1 : assert_null(attrs);
1160 1 : }
1161 :
1162 1 : void test_sss_sifp_parse_attr_uint64_array(void **state)
1163 : {
1164 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1165 1 : DBusMessage *reply = test_ctx.reply;
1166 : sss_sifp_error ret;
1167 1 : sss_sifp_attr **attrs = NULL;
1168 1 : const char *name = "test-attr";
1169 1 : unsigned int num_values = 5;
1170 1 : uint64_t in_array[] = {10, 15, 8885, 3224, 5559};
1171 1 : uint64_t *in = in_array;
1172 : unsigned int out_num;
1173 : uint64_t *out;
1174 : unsigned int i;
1175 :
1176 : /* prepare message */
1177 1 : reply_variant_array(reply, DBUS_TYPE_UINT64_AS_STRING, num_values,
1178 : (uint8_t*)in, sizeof(uint64_t));
1179 :
1180 : /* test */
1181 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
1182 :
1183 1 : assert_int_equal(ret, SSS_SIFP_OK);
1184 1 : assert_non_null(attrs);
1185 1 : assert_non_null(attrs[0]);
1186 1 : assert_null(attrs[1]);
1187 :
1188 1 : assert_int_equal(attrs[0]->num_values, num_values);
1189 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT64);
1190 1 : assert_string_equal(attrs[0]->name, name);
1191 :
1192 1 : ret = sss_sifp_find_attr_as_uint64_array(attrs, name, &out_num, &out);
1193 1 : assert_int_equal(ret, SSS_SIFP_OK);
1194 1 : assert_int_equal(num_values, out_num);
1195 :
1196 6 : for (i = 0; i < num_values; i++) {
1197 5 : assert_int_equal(in[i], out[i]);
1198 : }
1199 :
1200 1 : sss_sifp_free_attrs(ctx, &attrs);
1201 1 : assert_null(attrs);
1202 1 : }
1203 :
1204 1 : void test_sss_sifp_parse_attr_uint64_array_empty(void **state)
1205 : {
1206 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1207 1 : DBusMessage *reply = test_ctx.reply;
1208 : sss_sifp_error ret;
1209 1 : sss_sifp_attr **attrs = NULL;
1210 1 : const char *name = "test-attr";
1211 1 : unsigned int num_values = 0;
1212 : unsigned int out_num;
1213 : uint64_t *out;
1214 :
1215 : /* prepare message */
1216 1 : reply_variant_array(reply, DBUS_TYPE_UINT64_AS_STRING, num_values,
1217 : NULL, sizeof(uint64_t));
1218 :
1219 : /* test */
1220 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
1221 :
1222 1 : assert_int_equal(ret, SSS_SIFP_OK);
1223 1 : assert_non_null(attrs);
1224 1 : assert_non_null(attrs[0]);
1225 1 : assert_null(attrs[1]);
1226 :
1227 1 : assert_int_equal(attrs[0]->num_values, num_values);
1228 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT64);
1229 1 : assert_string_equal(attrs[0]->name, name);
1230 :
1231 1 : ret = sss_sifp_find_attr_as_uint64_array(attrs, name, &out_num, &out);
1232 1 : assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
1233 1 : assert_int_equal(num_values, out_num);
1234 1 : assert_null(out);
1235 :
1236 1 : sss_sifp_free_attrs(ctx, &attrs);
1237 1 : assert_null(attrs);
1238 1 : }
1239 :
1240 1 : void test_sss_sifp_parse_attr_string_array(void **state)
1241 : {
1242 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1243 1 : DBusMessage *reply = test_ctx.reply;
1244 : sss_sifp_error ret;
1245 1 : sss_sifp_attr **attrs = NULL;
1246 1 : const char *name = "test-attr";
1247 1 : unsigned int num_values = 6;
1248 1 : const char *in_array[] = {"I", "don't", "like", "writing", "unit", "tests"};
1249 1 : const char **in = in_array;
1250 : unsigned int out_num;
1251 : const char * const *out;
1252 : unsigned int i;
1253 :
1254 : /* prepare message */
1255 1 : reply_variant_array(reply, DBUS_TYPE_STRING_AS_STRING, num_values,
1256 : (uint8_t*)in, sizeof(const char*));
1257 :
1258 : /* test */
1259 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
1260 :
1261 1 : assert_int_equal(ret, SSS_SIFP_OK);
1262 1 : assert_non_null(attrs);
1263 1 : assert_non_null(attrs[0]);
1264 1 : assert_null(attrs[1]);
1265 :
1266 1 : assert_int_equal(attrs[0]->num_values, num_values);
1267 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING);
1268 1 : assert_string_equal(attrs[0]->name, name);
1269 :
1270 1 : ret = sss_sifp_find_attr_as_string_array(attrs, name, &out_num, &out);
1271 1 : assert_int_equal(ret, SSS_SIFP_OK);
1272 1 : assert_int_equal(num_values, out_num);
1273 :
1274 7 : for (i = 0; i < num_values; i++) {
1275 6 : assert_string_equal(in[i], out[i]);
1276 : }
1277 :
1278 1 : sss_sifp_free_attrs(ctx, &attrs);
1279 1 : assert_null(attrs);
1280 1 : }
1281 :
1282 1 : void test_sss_sifp_parse_attr_string_array_empty(void **state)
1283 : {
1284 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1285 1 : DBusMessage *reply = test_ctx.reply;
1286 : sss_sifp_error ret;
1287 1 : sss_sifp_attr **attrs = NULL;
1288 1 : const char *name = "test-attr";
1289 1 : unsigned int num_values = 0;
1290 : unsigned int out_num;
1291 : const char * const *out;
1292 :
1293 : /* prepare message */
1294 1 : reply_variant_array(reply, DBUS_TYPE_STRING_AS_STRING, num_values,
1295 : NULL, sizeof(const char*));
1296 :
1297 : /* test */
1298 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
1299 :
1300 1 : assert_int_equal(ret, SSS_SIFP_OK);
1301 1 : assert_non_null(attrs);
1302 1 : assert_non_null(attrs[0]);
1303 1 : assert_null(attrs[1]);
1304 :
1305 1 : assert_int_equal(attrs[0]->num_values, num_values);
1306 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING);
1307 1 : assert_string_equal(attrs[0]->name, name);
1308 :
1309 1 : ret = sss_sifp_find_attr_as_string_array(attrs, name, &out_num, &out);
1310 1 : assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
1311 1 : assert_int_equal(num_values, out_num);
1312 1 : assert_null(out);
1313 :
1314 1 : sss_sifp_free_attrs(ctx, &attrs);
1315 1 : assert_null(attrs);
1316 1 : }
1317 :
1318 1 : void test_sss_sifp_parse_attr_object_path_array(void **state)
1319 : {
1320 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1321 1 : DBusMessage *reply = test_ctx.reply;
1322 : sss_sifp_error ret;
1323 1 : sss_sifp_attr **attrs = NULL;
1324 1 : const char *name = "test-attr";
1325 1 : unsigned int num_values = 2;
1326 1 : const char *in_array[] = {"/object/path1", "/object/path2"};
1327 1 : const char **in = in_array;
1328 : unsigned int out_num;
1329 : const char * const *out;
1330 : unsigned int i;
1331 :
1332 : /* prepare message */
1333 1 : reply_variant_array(reply, DBUS_TYPE_OBJECT_PATH_AS_STRING, num_values,
1334 : (uint8_t*)in, sizeof(const char*));
1335 :
1336 : /* test */
1337 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
1338 :
1339 1 : assert_int_equal(ret, SSS_SIFP_OK);
1340 1 : assert_non_null(attrs);
1341 1 : assert_non_null(attrs[0]);
1342 1 : assert_null(attrs[1]);
1343 :
1344 1 : assert_int_equal(attrs[0]->num_values, num_values);
1345 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING);
1346 1 : assert_string_equal(attrs[0]->name, name);
1347 :
1348 1 : ret = sss_sifp_find_attr_as_string_array(attrs, name, &out_num, &out);
1349 1 : assert_int_equal(ret, SSS_SIFP_OK);
1350 1 : assert_int_equal(num_values, out_num);
1351 :
1352 3 : for (i = 0; i < num_values; i++) {
1353 2 : assert_string_equal(in[i], out[i]);
1354 : }
1355 :
1356 1 : sss_sifp_free_attrs(ctx, &attrs);
1357 1 : assert_null(attrs);
1358 1 : }
1359 :
1360 1 : void test_sss_sifp_parse_attr_object_path_array_empty(void **state)
1361 : {
1362 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1363 1 : DBusMessage *reply = test_ctx.reply;
1364 : sss_sifp_error ret;
1365 1 : sss_sifp_attr **attrs = NULL;
1366 1 : const char *name = "test-attr";
1367 1 : unsigned int num_values = 0;
1368 : unsigned int out_num;
1369 : const char * const *out;
1370 :
1371 : /* prepare message */
1372 1 : reply_variant_array(reply, DBUS_TYPE_OBJECT_PATH_AS_STRING, num_values,
1373 : NULL, sizeof(const char*));
1374 :
1375 : /* test */
1376 1 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
1377 :
1378 1 : assert_int_equal(ret, SSS_SIFP_OK);
1379 1 : assert_non_null(attrs);
1380 1 : assert_non_null(attrs[0]);
1381 1 : assert_null(attrs[1]);
1382 :
1383 1 : assert_int_equal(attrs[0]->num_values, num_values);
1384 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING);
1385 1 : assert_string_equal(attrs[0]->name, name);
1386 :
1387 1 : ret = sss_sifp_find_attr_as_string_array(attrs, name, &out_num, &out);
1388 1 : assert_int_equal(ret, SSS_SIFP_ATTR_NULL);
1389 1 : assert_int_equal(num_values, out_num);
1390 1 : assert_null(out);
1391 :
1392 1 : sss_sifp_free_attrs(ctx, &attrs);
1393 1 : assert_null(attrs);
1394 1 : }
1395 :
1396 1 : void test_sss_sifp_parse_attr_string_dict_array(void **state)
1397 : {
1398 1 : return;
1399 :
1400 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1401 : DBusMessage *reply = test_ctx.reply;
1402 : DBusMessageIter iter;
1403 : DBusMessageIter var_iter;
1404 : DBusMessageIter array_iter;
1405 : DBusMessageIter dict_iter;
1406 : DBusMessageIter val_iter;
1407 : dbus_bool_t bret;
1408 : sss_sifp_error ret;
1409 : sss_sifp_attr **attrs = NULL;
1410 : const char *name = "test-attr";
1411 : static struct {
1412 : const char *key;
1413 : const char *values[];
1414 : } data = {"key", {"value1", "value2", "value3"}};
1415 : unsigned int num_values = 3;
1416 : hash_table_t *out;
1417 : hash_key_t key;
1418 : hash_value_t value;
1419 : char **values;
1420 : unsigned int i;
1421 : int hret;
1422 :
1423 : /* prepare message */
1424 : dbus_message_iter_init_append(reply, &iter);
1425 :
1426 : bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
1427 : DBUS_TYPE_ARRAY_AS_STRING
1428 : DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
1429 : DBUS_TYPE_STRING_AS_STRING
1430 : DBUS_TYPE_ARRAY_AS_STRING
1431 : DBUS_TYPE_STRING_AS_STRING
1432 : DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
1433 : &var_iter);
1434 : assert_true(bret);
1435 :
1436 : bret = dbus_message_iter_open_container(&var_iter, DBUS_TYPE_ARRAY,
1437 : DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
1438 : DBUS_TYPE_STRING_AS_STRING
1439 : DBUS_TYPE_ARRAY_AS_STRING
1440 : DBUS_TYPE_STRING_AS_STRING
1441 : DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
1442 : &array_iter);
1443 : assert_true(bret);
1444 :
1445 : bret = dbus_message_iter_open_container(&array_iter,
1446 : DBUS_TYPE_DICT_ENTRY,
1447 : NULL, &dict_iter);
1448 : assert_true(bret);
1449 :
1450 : bret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING,
1451 : &data.key);
1452 : assert_true(bret);
1453 :
1454 : bret = dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_ARRAY,
1455 : DBUS_TYPE_STRING_AS_STRING,
1456 : &val_iter);
1457 : assert_true(bret);
1458 :
1459 : for (i = 0; i < num_values; i++) {
1460 : bret = dbus_message_iter_append_basic(&val_iter, DBUS_TYPE_STRING,
1461 : &data.values[i]);
1462 : assert_true(bret);
1463 : }
1464 :
1465 : bret = dbus_message_iter_close_container(&dict_iter, &val_iter);
1466 : assert_true(bret);
1467 :
1468 : bret = dbus_message_iter_close_container(&array_iter, &dict_iter);
1469 : assert_true(bret);
1470 :
1471 : bret = dbus_message_iter_close_container(&var_iter, &array_iter);
1472 : assert_true(bret);
1473 :
1474 : bret = dbus_message_iter_close_container(&iter, &var_iter);
1475 : assert_true(bret);
1476 :
1477 : ret = sss_sifp_parse_attr(ctx, name, reply, &attrs);
1478 : assert_int_equal(ret, SSS_SIFP_OK);
1479 : assert_non_null(attrs);
1480 : assert_non_null(attrs[0]);
1481 : assert_null(attrs[1]);
1482 :
1483 : assert_int_equal(attrs[0]->num_values, 1);
1484 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_STRING_DICT);
1485 : assert_string_equal(attrs[0]->name, name);
1486 :
1487 : ret = sss_sifp_find_attr_as_string_dict(attrs, name, &out);
1488 : assert_int_equal(ret, SSS_SIFP_OK);
1489 : assert_int_equal(hash_count(out), 1);
1490 :
1491 : key.type = HASH_KEY_STRING;
1492 : key.str = discard_const(data.key);
1493 : hret = hash_lookup(out, &key, &value);
1494 : assert_int_equal(hret, HASH_SUCCESS);
1495 : assert_int_equal(value.type, HASH_VALUE_PTR);
1496 : assert_non_null(value.ptr);
1497 : values = value.ptr;
1498 :
1499 : for (i = 0; i < num_values; i++) {
1500 : assert_non_null(values[i]);
1501 : assert_string_equal(values[i], data.values[i]);
1502 : }
1503 : assert_null(values[i]);
1504 :
1505 :
1506 : sss_sifp_free_attrs(ctx, &attrs);
1507 : assert_null(attrs);
1508 : }
1509 :
1510 1 : void test_sss_sifp_parse_attr_list(void **state)
1511 : {
1512 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1513 1 : DBusMessage *reply = test_ctx.reply;
1514 : DBusMessageIter iter;
1515 : DBusMessageIter array_iter;
1516 : DBusMessageIter dict_iter;
1517 : DBusMessageIter var_iter;
1518 : dbus_bool_t bret;
1519 : sss_sifp_error ret;
1520 1 : sss_sifp_attr **attrs = NULL;
1521 : struct {
1522 : const char *name;
1523 : uint32_t value;
1524 1 : } data[] = {{"attr1", 1}, {"attr2", 2}, {"attr3", 3}, {NULL, 0}};
1525 : uint32_t out;
1526 : int i;
1527 :
1528 : /* prepare message */
1529 1 : dbus_message_iter_init_append(reply, &iter);
1530 :
1531 1 : bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
1532 : DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
1533 : DBUS_TYPE_STRING_AS_STRING
1534 : DBUS_TYPE_VARIANT_AS_STRING
1535 : DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
1536 : &array_iter);
1537 1 : assert_true(bret);
1538 :
1539 4 : for (i = 0; data[i].name != NULL; i++) {
1540 3 : bret = dbus_message_iter_open_container(&array_iter,
1541 : DBUS_TYPE_DICT_ENTRY,
1542 : NULL, &dict_iter);
1543 3 : assert_true(bret);
1544 :
1545 3 : bret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING,
1546 3 : &data[i].name);
1547 3 : assert_true(bret);
1548 :
1549 3 : bret = dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_VARIANT,
1550 : DBUS_TYPE_UINT32_AS_STRING,
1551 : &var_iter);
1552 3 : assert_true(bret);
1553 :
1554 3 : bret = dbus_message_iter_append_basic(&var_iter, DBUS_TYPE_UINT32,
1555 3 : &data[i].value);
1556 3 : assert_true(bret);
1557 :
1558 3 : bret = dbus_message_iter_close_container(&dict_iter, &var_iter);
1559 3 : assert_true(bret);
1560 :
1561 3 : bret = dbus_message_iter_close_container(&array_iter, &dict_iter);
1562 3 : assert_true(bret);
1563 : }
1564 :
1565 1 : bret = dbus_message_iter_close_container(&iter, &array_iter);
1566 1 : assert_true(bret);
1567 :
1568 1 : ret = sss_sifp_parse_attr_list(ctx, reply, &attrs);
1569 1 : assert_int_equal(ret, SSS_SIFP_OK);
1570 1 : assert_non_null(attrs);
1571 :
1572 4 : for (i = 0; data[i].name != NULL; i++) {
1573 3 : assert_non_null(attrs[i]);
1574 3 : assert_int_equal(attrs[i]->num_values, 1);
1575 3 : assert_int_equal(attrs[i]->type, SSS_SIFP_ATTR_TYPE_UINT32);
1576 3 : assert_string_equal(attrs[i]->name, data[i].name);
1577 :
1578 3 : ret = sss_sifp_find_attr_as_uint32(attrs, data[i].name, &out);
1579 3 : assert_int_equal(ret, SSS_SIFP_OK);
1580 3 : assert_int_equal(data[i].value, out);
1581 : }
1582 :
1583 1 : assert_null(attrs[i]);
1584 :
1585 1 : sss_sifp_free_attrs(ctx, &attrs);
1586 1 : assert_null(attrs);
1587 1 : }
1588 :
1589 1 : void test_sss_sifp_parse_attr_list_empty(void **state)
1590 : {
1591 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1592 1 : DBusMessage *reply = test_ctx.reply;
1593 : DBusMessageIter iter;
1594 : DBusMessageIter array_iter;
1595 : dbus_bool_t bret;
1596 : sss_sifp_error ret;
1597 1 : sss_sifp_attr **attrs = NULL;
1598 :
1599 : /* prepare message */
1600 1 : dbus_message_iter_init_append(reply, &iter);
1601 :
1602 1 : bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
1603 : DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
1604 : DBUS_TYPE_STRING_AS_STRING
1605 : DBUS_TYPE_VARIANT_AS_STRING
1606 : DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
1607 : &array_iter);
1608 1 : assert_true(bret);
1609 :
1610 1 : bret = dbus_message_iter_close_container(&iter, &array_iter);
1611 1 : assert_true(bret);
1612 :
1613 1 : ret = sss_sifp_parse_attr_list(ctx, reply, &attrs);
1614 1 : assert_int_equal(ret, SSS_SIFP_OK);
1615 1 : assert_non_null(attrs);
1616 1 : assert_null(attrs[0]);
1617 :
1618 1 : sss_sifp_free_attrs(ctx, &attrs);
1619 1 : assert_null(attrs);
1620 1 : }
1621 :
1622 1 : void test_sss_sifp_get_iface_for_object(void **state)
1623 : {
1624 : int i;
1625 1 : const char *iface = NULL;
1626 : static struct {
1627 : const char *path;
1628 : const char *iface;
1629 : } data[] = {{SSS_SIFP_PATH_IFP "/Components/Monitor",
1630 : SSS_SIFP_IFACE_COMPONENTS},
1631 : {SSS_SIFP_PATH_IFP "/Domains/LDAP",
1632 : SSS_SIFP_IFACE_DOMAINS},
1633 : {SSS_SIFP_PATH_IFP "/Services/NSS",
1634 : SSS_SIFP_IFACE_SERVICES},
1635 : {SSS_SIFP_PATH_IFP "/Users/2154",
1636 : SSS_SIFP_IFACE_USERS},
1637 : {SSS_SIFP_PATH_IFP "/Groups/3441",
1638 : SSS_SIFP_IFACE_GROUPS},
1639 : {NULL, NULL}};
1640 :
1641 6 : for (i = 0; data[i].path != NULL; i++) {
1642 5 : iface = sss_sifp_get_iface_for_object(data[i].path);
1643 5 : assert_non_null(iface);
1644 5 : assert_string_equal(data[i].iface, iface);
1645 : }
1646 1 : }
1647 :
1648 1 : void test_sss_sifp_fetch_attr(void **state)
1649 : {
1650 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1651 1 : DBusMessage *reply = test_ctx.reply;
1652 : sss_sifp_error ret;
1653 1 : sss_sifp_attr **attrs = NULL;
1654 1 : const char *name = "test-attr";
1655 1 : uint32_t in = UINT32_MAX;
1656 : uint32_t out;
1657 :
1658 : /* prepare message */
1659 1 : reply_variant_basic(reply, DBUS_TYPE_UINT32_AS_STRING, &in);
1660 1 : will_return(__wrap_dbus_connection_send_with_reply_and_block, reply);
1661 :
1662 : /* test */
1663 1 : ret = sss_sifp_fetch_attr(ctx, "/test/object", "test.com", name, &attrs);
1664 :
1665 1 : assert_int_equal(ret, SSS_SIFP_OK);
1666 1 : assert_non_null(attrs);
1667 1 : assert_non_null(attrs[0]);
1668 1 : assert_null(attrs[1]);
1669 :
1670 1 : assert_int_equal(attrs[0]->num_values, 1);
1671 1 : assert_int_equal(attrs[0]->type, SSS_SIFP_ATTR_TYPE_UINT32);
1672 1 : assert_string_equal(attrs[0]->name, name);
1673 :
1674 1 : ret = sss_sifp_find_attr_as_uint32(attrs, name, &out);
1675 1 : assert_int_equal(ret, SSS_SIFP_OK);
1676 1 : assert_int_equal(in, out);
1677 :
1678 1 : sss_sifp_free_attrs(ctx, &attrs);
1679 1 : assert_null(attrs);
1680 1 : }
1681 :
1682 1 : void test_sss_sifp_fetch_all_attrs(void **state)
1683 : {
1684 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1685 1 : DBusMessage *reply = test_ctx.reply;
1686 : DBusMessageIter iter;
1687 : DBusMessageIter array_iter;
1688 : DBusMessageIter dict_iter;
1689 : DBusMessageIter var_iter;
1690 : dbus_bool_t bret;
1691 : sss_sifp_error ret;
1692 1 : sss_sifp_attr **attrs = NULL;
1693 : struct {
1694 : const char *name;
1695 : uint32_t value;
1696 1 : } data[] = {{"attr1", 1}, {"attr2", 2}, {"attr3", 3}, {NULL, 0}};
1697 : uint32_t out;
1698 : int i;
1699 :
1700 : /* prepare message */
1701 1 : dbus_message_iter_init_append(reply, &iter);
1702 :
1703 1 : bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
1704 : DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
1705 : DBUS_TYPE_STRING_AS_STRING
1706 : DBUS_TYPE_VARIANT_AS_STRING
1707 : DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
1708 : &array_iter);
1709 1 : assert_true(bret);
1710 :
1711 4 : for (i = 0; data[i].name != NULL; i++) {
1712 3 : bret = dbus_message_iter_open_container(&array_iter,
1713 : DBUS_TYPE_DICT_ENTRY,
1714 : NULL, &dict_iter);
1715 3 : assert_true(bret);
1716 :
1717 3 : bret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING,
1718 3 : &data[i].name);
1719 3 : assert_true(bret);
1720 :
1721 3 : bret = dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_VARIANT,
1722 : DBUS_TYPE_UINT32_AS_STRING,
1723 : &var_iter);
1724 3 : assert_true(bret);
1725 :
1726 3 : bret = dbus_message_iter_append_basic(&var_iter, DBUS_TYPE_UINT32,
1727 3 : &data[i].value);
1728 3 : assert_true(bret);
1729 :
1730 3 : bret = dbus_message_iter_close_container(&dict_iter, &var_iter);
1731 3 : assert_true(bret);
1732 :
1733 3 : bret = dbus_message_iter_close_container(&array_iter, &dict_iter);
1734 3 : assert_true(bret);
1735 : }
1736 :
1737 1 : bret = dbus_message_iter_close_container(&iter, &array_iter);
1738 1 : assert_true(bret);
1739 1 : will_return(__wrap_dbus_connection_send_with_reply_and_block, reply);
1740 :
1741 1 : ret = sss_sifp_fetch_all_attrs(ctx, "/test/object", "test.com", &attrs);
1742 1 : assert_int_equal(ret, SSS_SIFP_OK);
1743 1 : assert_non_null(attrs);
1744 :
1745 4 : for (i = 0; data[i].name != NULL; i++) {
1746 3 : assert_non_null(attrs[i]);
1747 3 : assert_int_equal(attrs[i]->num_values, 1);
1748 3 : assert_int_equal(attrs[i]->type, SSS_SIFP_ATTR_TYPE_UINT32);
1749 3 : assert_string_equal(attrs[i]->name, data[i].name);
1750 :
1751 3 : ret = sss_sifp_find_attr_as_uint32(attrs, data[i].name, &out);
1752 3 : assert_int_equal(ret, SSS_SIFP_OK);
1753 3 : assert_int_equal(data[i].value, out);
1754 : }
1755 :
1756 1 : assert_null(attrs[i]);
1757 :
1758 1 : sss_sifp_free_attrs(ctx, &attrs);
1759 1 : assert_null(attrs);
1760 1 : }
1761 :
1762 1 : void test_sss_sifp_fetch_object(void **state)
1763 : {
1764 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1765 1 : DBusMessage *reply = test_ctx.reply;
1766 : DBusMessageIter iter;
1767 : DBusMessageIter array_iter;
1768 : DBusMessageIter dict_iter;
1769 : DBusMessageIter var_iter;
1770 1 : const char *path = "/test/object";
1771 1 : const char *iface = "test.com";
1772 : dbus_bool_t bret;
1773 : sss_sifp_error ret;
1774 1 : sss_sifp_object *object = NULL;
1775 : struct {
1776 : const char *name;
1777 : const char *value;
1778 1 : } data[] = {{"name", "test-object"}, {"a1", "a"}, {"a2", "b"}, {NULL, 0}};
1779 : const char *out;
1780 : int i;
1781 :
1782 : /* prepare message */
1783 1 : dbus_message_iter_init_append(reply, &iter);
1784 :
1785 1 : bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
1786 : DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
1787 : DBUS_TYPE_STRING_AS_STRING
1788 : DBUS_TYPE_VARIANT_AS_STRING
1789 : DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
1790 : &array_iter);
1791 1 : assert_true(bret);
1792 :
1793 4 : for (i = 0; data[i].name != NULL; i++) {
1794 3 : bret = dbus_message_iter_open_container(&array_iter,
1795 : DBUS_TYPE_DICT_ENTRY,
1796 : NULL, &dict_iter);
1797 3 : assert_true(bret);
1798 :
1799 3 : bret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING,
1800 3 : &data[i].name);
1801 3 : assert_true(bret);
1802 :
1803 3 : bret = dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_VARIANT,
1804 : DBUS_TYPE_STRING_AS_STRING,
1805 : &var_iter);
1806 3 : assert_true(bret);
1807 :
1808 3 : bret = dbus_message_iter_append_basic(&var_iter, DBUS_TYPE_STRING,
1809 3 : &data[i].value);
1810 3 : assert_true(bret);
1811 :
1812 3 : bret = dbus_message_iter_close_container(&dict_iter, &var_iter);
1813 3 : assert_true(bret);
1814 :
1815 3 : bret = dbus_message_iter_close_container(&array_iter, &dict_iter);
1816 3 : assert_true(bret);
1817 : }
1818 :
1819 1 : bret = dbus_message_iter_close_container(&iter, &array_iter);
1820 1 : assert_true(bret);
1821 1 : will_return(__wrap_dbus_connection_send_with_reply_and_block, reply);
1822 :
1823 1 : ret = sss_sifp_fetch_object(ctx, path, iface, &object);
1824 1 : assert_int_equal(ret, SSS_SIFP_OK);
1825 1 : assert_non_null(object);
1826 1 : assert_non_null(object->attrs);
1827 1 : assert_non_null(object->name);
1828 1 : assert_non_null(object->object_path);
1829 1 : assert_non_null(object->interface);
1830 :
1831 1 : assert_string_equal(object->name, "test-object");
1832 1 : assert_string_equal(object->object_path, path);
1833 1 : assert_string_equal(object->interface, iface);
1834 :
1835 4 : for (i = 0; data[i].name != NULL; i++) {
1836 3 : assert_non_null(object->attrs[i]);
1837 3 : assert_int_equal(object->attrs[i]->num_values, 1);
1838 3 : assert_int_equal(object->attrs[i]->type, SSS_SIFP_ATTR_TYPE_STRING);
1839 3 : assert_string_equal(object->attrs[i]->name, data[i].name);
1840 :
1841 3 : ret = sss_sifp_find_attr_as_string(object->attrs, data[i].name, &out);
1842 3 : assert_int_equal(ret, SSS_SIFP_OK);
1843 3 : assert_string_equal(data[i].value, out);
1844 : }
1845 :
1846 1 : assert_null(object->attrs[i]);
1847 :
1848 1 : sss_sifp_free_object(ctx, &object);
1849 1 : assert_null(object);
1850 1 : }
1851 :
1852 1 : void test_sss_sifp_invoke_list_zeroargs(void **state)
1853 : {
1854 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1855 1 : DBusMessage *reply = test_ctx.reply;
1856 : dbus_bool_t bret;
1857 : sss_sifp_error ret;
1858 1 : char **path_out = NULL;
1859 1 : const char *path_in[] = {"/object/path1", "/object/path2"};
1860 1 : const char **paths = path_in;
1861 1 : int path_in_len = 2;
1862 : int i;
1863 :
1864 : /* prepare message */
1865 1 : bret = dbus_message_append_args(reply, DBUS_TYPE_ARRAY,
1866 : DBUS_TYPE_OBJECT_PATH,
1867 : &paths, path_in_len,
1868 : DBUS_TYPE_INVALID);
1869 1 : assert_true(bret);
1870 1 : will_return(__wrap_dbus_connection_send_with_reply_and_block, reply);
1871 :
1872 : /* test */
1873 1 : ret = sss_sifp_invoke_list(ctx, "MyMethod", &path_out, DBUS_TYPE_INVALID);
1874 1 : assert_int_equal(ret, SSS_SIFP_OK);
1875 1 : assert_non_null(path_out);
1876 :
1877 3 : for (i = 0; path_out[i] != NULL; i++) {
1878 2 : assert_true(i < path_in_len);
1879 2 : assert_non_null(path_out[i]);
1880 2 : assert_string_equal(path_in[i], path_out[i]);
1881 : }
1882 :
1883 1 : sss_sifp_free_string_array(ctx, &path_out);
1884 1 : assert_null(path_out);
1885 1 : }
1886 :
1887 1 : void test_sss_sifp_invoke_list_withargs(void **state)
1888 : {
1889 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1890 1 : DBusMessage *reply = test_ctx.reply;
1891 : dbus_bool_t bret;
1892 : sss_sifp_error ret;
1893 1 : char **path_out = NULL;
1894 1 : const char *path_in[] = {"/object/path1", "/object/path2"};
1895 1 : const char **paths = path_in;
1896 1 : const char *arg = "first-arg";
1897 1 : int path_in_len = 2;
1898 : int i;
1899 :
1900 : /* prepare message */
1901 1 : bret = dbus_message_append_args(reply, DBUS_TYPE_ARRAY,
1902 : DBUS_TYPE_OBJECT_PATH,
1903 : &paths, path_in_len,
1904 : DBUS_TYPE_INVALID);
1905 1 : assert_true(bret);
1906 1 : will_return(__wrap_dbus_connection_send_with_reply_and_block, reply);
1907 :
1908 : /* test */
1909 1 : ret = sss_sifp_invoke_list(ctx, "MyMethod", &path_out,
1910 : DBUS_TYPE_STRING, &arg,
1911 : DBUS_TYPE_INVALID);
1912 1 : assert_int_equal(ret, SSS_SIFP_OK);
1913 1 : assert_non_null(path_out);
1914 :
1915 3 : for (i = 0; path_out[i] != NULL; i++) {
1916 2 : assert_true(i < path_in_len);
1917 2 : assert_non_null(path_out[i]);
1918 2 : assert_string_equal(path_in[i], path_out[i]);
1919 : }
1920 :
1921 1 : sss_sifp_free_string_array(ctx, &path_out);
1922 1 : assert_null(path_out);
1923 1 : }
1924 :
1925 1 : void test_sss_sifp_invoke_find_zeroargs(void **state)
1926 : {
1927 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1928 1 : DBusMessage *reply = test_ctx.reply;
1929 : dbus_bool_t bret;
1930 : sss_sifp_error ret;
1931 1 : const char *path_in = "/object/path";
1932 1 : char *path_out = NULL;
1933 :
1934 : /* prepare message */
1935 1 : bret = dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path_in,
1936 : DBUS_TYPE_INVALID);
1937 1 : assert_true(bret);
1938 1 : will_return(__wrap_dbus_connection_send_with_reply_and_block, reply);
1939 :
1940 : /* test */
1941 1 : ret = sss_sifp_invoke_find(ctx, "MyMethod", &path_out, DBUS_TYPE_INVALID);
1942 1 : assert_int_equal(ret, SSS_SIFP_OK);
1943 1 : assert_non_null(path_out);
1944 1 : assert_string_equal(path_in, path_out);
1945 :
1946 1 : sss_sifp_free_string(ctx, &path_out);
1947 1 : assert_null(path_out);
1948 1 : }
1949 :
1950 1 : void test_sss_sifp_invoke_find_withargs(void **state)
1951 : {
1952 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1953 1 : DBusMessage *reply = test_ctx.reply;
1954 : dbus_bool_t bret;
1955 : sss_sifp_error ret;
1956 1 : const char *path_in = "/object/path";
1957 1 : char *path_out = NULL;
1958 1 : const char *arg = "first-arg";
1959 :
1960 : /* prepare message */
1961 1 : bret = dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path_in,
1962 : DBUS_TYPE_INVALID);
1963 1 : assert_true(bret);
1964 1 : will_return(__wrap_dbus_connection_send_with_reply_and_block, reply);
1965 :
1966 : /* test */
1967 1 : ret = sss_sifp_invoke_find(ctx, "MyMethod", &path_out,
1968 : DBUS_TYPE_STRING, &arg,
1969 : DBUS_TYPE_INVALID);
1970 1 : assert_int_equal(ret, SSS_SIFP_OK);
1971 1 : assert_non_null(path_out);
1972 1 : assert_string_equal(path_in, path_out);
1973 :
1974 1 : sss_sifp_free_string(ctx, &path_out);
1975 1 : assert_null(path_out);
1976 1 : }
1977 :
1978 1 : void test_sss_sifp_list_domains(void **state)
1979 : {
1980 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
1981 1 : DBusMessage *msg_paths = NULL;
1982 1 : DBusMessage *msg_ldap = NULL;
1983 1 : DBusMessage *msg_ipa = NULL;
1984 : dbus_bool_t bret;
1985 : sss_sifp_error ret;
1986 1 : const char *in[] = {SSS_SIFP_PATH_IFP "/Domains/LDAP",
1987 : SSS_SIFP_PATH_IFP "/Domains/IPA"};
1988 1 : const char **paths = in;
1989 1 : const char *names[] = {"LDAP", "IPA"};
1990 1 : char **out = NULL;
1991 1 : int in_len = 2;
1992 : int i;
1993 :
1994 1 : msg_paths = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
1995 1 : assert_non_null(msg_paths);
1996 :
1997 1 : msg_ldap = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
1998 1 : assert_non_null(msg_ldap);
1999 :
2000 1 : msg_ipa = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
2001 1 : assert_non_null(msg_ipa);
2002 :
2003 : /* prepare message */
2004 1 : bret = dbus_message_append_args(msg_paths, DBUS_TYPE_ARRAY,
2005 : DBUS_TYPE_OBJECT_PATH,
2006 : &paths, in_len,
2007 : DBUS_TYPE_INVALID);
2008 1 : assert_true(bret);
2009 :
2010 1 : reply_variant_basic(msg_ldap, DBUS_TYPE_STRING_AS_STRING, &names[0]);
2011 1 : reply_variant_basic(msg_ipa, DBUS_TYPE_STRING_AS_STRING, &names[1]);
2012 :
2013 1 : will_return(__wrap_dbus_connection_send_with_reply_and_block, msg_paths);
2014 1 : will_return(__wrap_dbus_connection_send_with_reply_and_block, msg_ldap);
2015 1 : will_return(__wrap_dbus_connection_send_with_reply_and_block, msg_ipa);
2016 :
2017 : /* test */
2018 1 : ret = sss_sifp_list_domains(ctx, &out);
2019 1 : assert_int_equal(ret, SSS_SIFP_OK);
2020 1 : assert_non_null(out);
2021 :
2022 3 : for (i = 0; i < in_len; i++) {
2023 2 : assert_non_null(out[i]);
2024 2 : assert_string_equal(out[i], names[i]);
2025 : }
2026 :
2027 1 : assert_null(out[i]);
2028 :
2029 1 : sss_sifp_free_string_array(ctx, &out);
2030 1 : assert_null(out);
2031 :
2032 : /* messages are unrefed in the library */
2033 1 : }
2034 :
2035 1 : void test_sss_sifp_fetch_domain_by_name(void **state)
2036 : {
2037 1 : sss_sifp_ctx *ctx = test_ctx.dbus_ctx;
2038 1 : DBusMessage *msg_path = NULL;
2039 1 : DBusMessage *msg_props = NULL;
2040 : DBusMessageIter iter;
2041 : DBusMessageIter array_iter;
2042 : DBusMessageIter dict_iter;
2043 : DBusMessageIter var_iter;
2044 : dbus_bool_t bret;
2045 : sss_sifp_error ret;
2046 1 : const char *in =SSS_SIFP_PATH_IFP "/Domains/LDAP";
2047 1 : const char *name = "LDAP";
2048 1 : const char *prop = NULL;
2049 1 : sss_sifp_object *out = NULL;
2050 : struct {
2051 : const char *name;
2052 : const char *value;
2053 1 : } props[] = {{"name", name}, {"a1", "a"}, {"a2", "b"}, {NULL, 0}};
2054 : int i;
2055 :
2056 :
2057 1 : msg_path = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
2058 1 : assert_non_null(msg_path);
2059 :
2060 1 : msg_props = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
2061 1 : assert_non_null(msg_props);
2062 :
2063 : /* prepare message */
2064 1 : bret = dbus_message_append_args(msg_path, DBUS_TYPE_OBJECT_PATH, &in,
2065 : DBUS_TYPE_INVALID);
2066 1 : assert_true(bret);
2067 :
2068 1 : dbus_message_iter_init_append(msg_props, &iter);
2069 :
2070 1 : bret = dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
2071 : DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
2072 : DBUS_TYPE_STRING_AS_STRING
2073 : DBUS_TYPE_VARIANT_AS_STRING
2074 : DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
2075 : &array_iter);
2076 1 : assert_true(bret);
2077 :
2078 4 : for (i = 0; props[i].name != NULL; i++) {
2079 3 : bret = dbus_message_iter_open_container(&array_iter,
2080 : DBUS_TYPE_DICT_ENTRY,
2081 : NULL, &dict_iter);
2082 3 : assert_true(bret);
2083 :
2084 3 : bret = dbus_message_iter_append_basic(&dict_iter, DBUS_TYPE_STRING,
2085 3 : &props[i].name);
2086 3 : assert_true(bret);
2087 :
2088 3 : bret = dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_VARIANT,
2089 : DBUS_TYPE_STRING_AS_STRING,
2090 : &var_iter);
2091 3 : assert_true(bret);
2092 :
2093 3 : bret = dbus_message_iter_append_basic(&var_iter, DBUS_TYPE_STRING,
2094 3 : &props[i].value);
2095 3 : assert_true(bret);
2096 :
2097 3 : bret = dbus_message_iter_close_container(&dict_iter, &var_iter);
2098 3 : assert_true(bret);
2099 :
2100 3 : bret = dbus_message_iter_close_container(&array_iter, &dict_iter);
2101 3 : assert_true(bret);
2102 : }
2103 :
2104 1 : bret = dbus_message_iter_close_container(&iter, &array_iter);
2105 1 : assert_true(bret);
2106 :
2107 1 : will_return(__wrap_dbus_connection_send_with_reply_and_block, msg_path);
2108 1 : will_return(__wrap_dbus_connection_send_with_reply_and_block, msg_props);
2109 :
2110 : /* test */
2111 1 : ret = sss_sifp_fetch_domain_by_name(ctx, name, &out);
2112 1 : assert_int_equal(ret, SSS_SIFP_OK);
2113 1 : assert_non_null(out);
2114 1 : assert_non_null(out->attrs);
2115 1 : assert_non_null(out->name);
2116 1 : assert_non_null(out->object_path);
2117 1 : assert_non_null(out->interface);
2118 :
2119 1 : assert_string_equal(out->name, name);
2120 1 : assert_string_equal(out->object_path, in);
2121 1 : assert_string_equal(out->interface, SSS_SIFP_IFACE_DOMAINS);
2122 :
2123 4 : for (i = 0; props[i].name != NULL; i++) {
2124 3 : assert_non_null(out->attrs[i]);
2125 3 : assert_int_equal(out->attrs[i]->num_values, 1);
2126 3 : assert_int_equal(out->attrs[i]->type, SSS_SIFP_ATTR_TYPE_STRING);
2127 3 : assert_string_equal(out->attrs[i]->name, props[i].name);
2128 :
2129 3 : ret = sss_sifp_find_attr_as_string(out->attrs, props[i].name, &prop);
2130 3 : assert_int_equal(ret, SSS_SIFP_OK);
2131 3 : assert_string_equal(props[i].value, prop);
2132 : }
2133 :
2134 1 : assert_null(out->attrs[i]);
2135 :
2136 1 : sss_sifp_free_object(ctx, &out);
2137 1 : assert_null(out);
2138 :
2139 : /* messages are unrefed in the library */
2140 1 : }
2141 :
2142 1 : int main(int argc, const char *argv[])
2143 : {
2144 : int rv;
2145 1 : int no_cleanup = 0;
2146 : poptContext pc;
2147 : int opt;
2148 7 : struct poptOption long_options[] = {
2149 : POPT_AUTOHELP
2150 5 : SSSD_DEBUG_OPTS
2151 : {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
2152 1 : _("Do not delete the test database after a test run"), NULL },
2153 : POPT_TABLEEND
2154 : };
2155 :
2156 1 : const struct CMUnitTest tests[] = {
2157 : cmocka_unit_test_setup_teardown(test_sss_sifp_strdup_valid,
2158 : test_setup, test_teardown_parser),
2159 : cmocka_unit_test_setup_teardown(test_sss_sifp_strdup_null,
2160 : test_setup, test_teardown_parser),
2161 : cmocka_unit_test_setup_teardown(test_sss_sifp_strcat_valid,
2162 : test_setup, test_teardown_parser),
2163 : cmocka_unit_test_setup_teardown(test_sss_sifp_strcat_left_null,
2164 : test_setup, test_teardown_parser),
2165 : cmocka_unit_test_setup_teardown(test_sss_sifp_strcat_right_null,
2166 : test_setup, test_teardown_parser),
2167 : cmocka_unit_test_setup_teardown(test_sss_sifp_strcat_both_null,
2168 : test_setup, test_teardown_parser),
2169 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_object_path_valid,
2170 : test_setup, test_teardown_parser),
2171 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_object_path_invalid,
2172 : test_setup, test_teardown_parser),
2173 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_object_path_list_valid,
2174 : test_setup, test_teardown_parser),
2175 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_object_path_list_invalid,
2176 : test_setup, test_teardown_parser),
2177 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_bool,
2178 : test_setup, test_teardown_parser),
2179 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_int16,
2180 : test_setup, test_teardown_parser),
2181 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_uint16,
2182 : test_setup, test_teardown_parser),
2183 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_int32,
2184 : test_setup, test_teardown_parser),
2185 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_uint32,
2186 : test_setup, test_teardown_parser),
2187 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_int64,
2188 : test_setup, test_teardown_parser),
2189 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_uint64,
2190 : test_setup, test_teardown_parser),
2191 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_string,
2192 : test_setup, test_teardown_parser),
2193 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_object_path,
2194 : test_setup, test_teardown_parser),
2195 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_string_dict,
2196 : test_setup, test_teardown_parser),
2197 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_bool_array,
2198 : test_setup, test_teardown_parser),
2199 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_bool_array_empty,
2200 : test_setup, test_teardown_parser),
2201 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_int32_array,
2202 : test_setup, test_teardown_parser),
2203 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_int32_array_empty,
2204 : test_setup, test_teardown_parser),
2205 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_uint32_array,
2206 : test_setup, test_teardown_parser),
2207 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_uint32_array_empty,
2208 : test_setup, test_teardown_parser),
2209 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_int64_array,
2210 : test_setup, test_teardown_parser),
2211 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_int64_array_empty,
2212 : test_setup, test_teardown_parser),
2213 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_uint64_array,
2214 : test_setup, test_teardown_parser),
2215 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_uint64_array_empty,
2216 : test_setup, test_teardown_parser),
2217 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_string_array,
2218 : test_setup, test_teardown_parser),
2219 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_string_array_empty,
2220 : test_setup, test_teardown_parser),
2221 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_object_path_array,
2222 : test_setup, test_teardown_parser),
2223 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_object_path_array_empty,
2224 : test_setup, test_teardown_parser),
2225 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_string_dict_array,
2226 : test_setup, test_teardown_parser),
2227 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_list,
2228 : test_setup, test_teardown_parser),
2229 : cmocka_unit_test_setup_teardown(test_sss_sifp_parse_attr_list_empty,
2230 : test_setup, test_teardown_parser),
2231 : cmocka_unit_test(test_sss_sifp_get_iface_for_object),
2232 : cmocka_unit_test_setup_teardown(test_sss_sifp_fetch_attr,
2233 : test_setup, test_teardown_api),
2234 : cmocka_unit_test_setup_teardown(test_sss_sifp_fetch_all_attrs,
2235 : test_setup, test_teardown_api),
2236 : cmocka_unit_test_setup_teardown(test_sss_sifp_fetch_object,
2237 : test_setup, test_teardown_api),
2238 : cmocka_unit_test_setup_teardown(test_sss_sifp_invoke_list_zeroargs,
2239 : test_setup, test_teardown_api),
2240 : cmocka_unit_test_setup_teardown(test_sss_sifp_invoke_list_withargs,
2241 : test_setup, test_teardown_api),
2242 : cmocka_unit_test_setup_teardown(test_sss_sifp_invoke_find_zeroargs,
2243 : test_setup, test_teardown_api),
2244 : cmocka_unit_test_setup_teardown(test_sss_sifp_invoke_find_withargs,
2245 : test_setup, test_teardown_api),
2246 : cmocka_unit_test_setup_teardown(test_sss_sifp_list_domains,
2247 : test_setup, test_teardown_api),
2248 : cmocka_unit_test_setup_teardown(test_sss_sifp_fetch_domain_by_name,
2249 : test_setup, test_teardown_api),
2250 : };
2251 :
2252 : /* Set debug level to invalid value so we can deside if -d 0 was used. */
2253 1 : debug_level = SSSDBG_INVALID;
2254 :
2255 1 : pc = poptGetContext(argv[0], argc, argv, long_options, 0);
2256 1 : while((opt = poptGetNextOpt(pc)) != -1) {
2257 : switch(opt) {
2258 : default:
2259 0 : fprintf(stderr, "\nInvalid option %s: %s\n\n",
2260 : poptBadOption(pc, 0), poptStrerror(opt));
2261 0 : poptPrintUsage(pc, stderr, 0);
2262 0 : return 1;
2263 : }
2264 : }
2265 1 : poptFreeContext(pc);
2266 :
2267 1 : DEBUG_CLI_INIT(debug_level);
2268 :
2269 1 : rv = cmocka_run_group_tests(tests, NULL, NULL);
2270 :
2271 1 : return rv;
2272 : }
|