9 #include "lib/krb5_wrap/krb5_samba.h"
12 static int setup_krb5_context(void **state
)
14 krb5_context context
= NULL
;
17 code
= krb5_init_context(&context
);
18 assert_return_code(code
, code
);
25 static int teardown_krb5_context(void **state
)
27 krb5_context context
= *state
;
29 if (context
!= NULL
) {
30 krb5_free_context(context
);
35 static void test_smb_krb5_kt_open(void **state
)
37 krb5_context context
= *state
;
38 krb5_keytab keytab
= NULL
;
40 char keytab_template
[] = "/tmp/keytab.XXXXXX";
43 fd
= mkstemp(keytab_template
);
44 assert_return_code(fd
, errno
);
45 unlink(keytab_template
);
47 code
= smb_krb5_kt_open(context
,
51 assert_int_equal(code
, 0);
53 krb5_kt_close(context
, keytab
);
57 static void test_smb_krb5_kt_open_file(void **state
)
59 krb5_context context
= *state
;
60 krb5_keytab keytab
= NULL
;
62 char keytab_template
[] = "/tmp/keytab.XXXXXX";
63 char keytab_file
[6 + strlen(keytab_template
)];
66 fd
= mkstemp(keytab_template
);
67 assert_return_code(fd
, errno
);
68 unlink(keytab_template
);
70 snprintf(keytab_file
, sizeof(keytab_file
), "FILE:%s", keytab_template
);
72 code
= smb_krb5_kt_open(context
,
76 assert_int_equal(code
, 0);
78 krb5_kt_close(context
, keytab
);
82 static void test_smb_krb5_kt_open_fail(void **state
)
84 krb5_context context
= *state
;
85 krb5_keytab keytab
= NULL
;
88 code
= smb_krb5_kt_open(context
,
92 assert_int_equal(code
, KRB5_KT_BADNAME
);
93 code
= smb_krb5_kt_open(context
,
97 assert_int_equal(code
, KRB5_KT_BADNAME
);
99 code
= smb_krb5_kt_open(context
,
103 assert_int_equal(code
, KRB5_KT_BADNAME
);
105 code
= smb_krb5_kt_open(context
,
109 assert_int_equal(code
, KRB5_KT_BADNAME
);
112 static void test_smb_krb5_kt_open_relative_memory(void **state
)
114 krb5_context context
= *state
;
115 krb5_keytab keytab
= NULL
;
116 krb5_error_code code
;
118 code
= smb_krb5_kt_open_relative(context
,
122 assert_int_equal(code
, 0);
124 krb5_kt_close(context
, keytab
);
128 const struct CMUnitTest tests
[] = {
129 cmocka_unit_test_setup_teardown(test_smb_krb5_kt_open
,
131 teardown_krb5_context
),
132 cmocka_unit_test_setup_teardown(test_smb_krb5_kt_open_file
,
134 teardown_krb5_context
),
135 cmocka_unit_test_setup_teardown(test_smb_krb5_kt_open_fail
,
137 teardown_krb5_context
),
138 cmocka_unit_test_setup_teardown(test_smb_krb5_kt_open_relative_memory
,
140 teardown_krb5_context
),
143 cmocka_set_message_output(CM_OUTPUT_SUBUNIT
);
144 return cmocka_run_group_tests(tests
, NULL
, NULL
);