s3:smbd: remove deprecated handling of "profile acls = yes"
[Samba.git] / testsuite / unittests / test_krb5_samba.c
blob8b7e843b85fcb8dca944d93f02e1cde50d0a39ee
1 #include <stdarg.h>
2 #include <stddef.h>
3 #include <setjmp.h>
4 #include <cmocka.h>
6 #include <krb5.h>
8 #include "includes.h"
9 #include "lib/krb5_wrap/krb5_samba.h"
12 static int setup_krb5_context(void **state)
14 krb5_context context = NULL;
15 krb5_error_code code;
17 code = krb5_init_context(&context);
18 assert_return_code(code, code);
20 *state = context;
22 return 0;
25 static int teardown_krb5_context(void **state)
27 krb5_context context = *state;
29 if (context != NULL) {
30 krb5_free_context(context);
32 return 0;
35 static void test_smb_krb5_kt_open(void **state)
37 krb5_context context = *state;
38 krb5_keytab keytab = NULL;
39 krb5_error_code code;
40 char keytab_template[] = "/tmp/keytab.XXXXXX";
41 int fd;
43 fd = mkstemp(keytab_template);
44 assert_return_code(fd, errno);
45 unlink(keytab_template);
47 code = smb_krb5_kt_open(context,
48 keytab_template,
49 false,
50 &keytab);
51 assert_int_equal(code, 0);
53 krb5_kt_close(context, keytab);
54 close(fd);
57 static void test_smb_krb5_kt_open_file(void **state)
59 krb5_context context = *state;
60 krb5_keytab keytab = NULL;
61 krb5_error_code code;
62 char keytab_template[] = "/tmp/keytab.XXXXXX";
63 char keytab_file[6 + strlen(keytab_template)];
64 int fd;
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,
73 keytab_file,
74 false,
75 &keytab);
76 assert_int_equal(code, 0);
78 krb5_kt_close(context, keytab);
79 close(fd);
82 static void test_smb_krb5_kt_open_fail(void **state)
84 krb5_context context = *state;
85 krb5_keytab keytab = NULL;
86 krb5_error_code code;
88 code = smb_krb5_kt_open(context,
89 NULL,
90 false,
91 &keytab);
92 assert_int_equal(code, KRB5_KT_BADNAME);
93 code = smb_krb5_kt_open(context,
94 "wurst",
95 false,
96 &keytab);
97 assert_int_equal(code, KRB5_KT_BADNAME);
99 code = smb_krb5_kt_open(context,
100 "FILE:wurst",
101 false,
102 &keytab);
103 assert_int_equal(code, KRB5_KT_BADNAME);
105 code = smb_krb5_kt_open(context,
106 "WRFILE:wurst",
107 false,
108 &keytab);
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,
119 NULL,
120 true,
121 &keytab);
122 assert_int_equal(code, 0);
124 krb5_kt_close(context, keytab);
127 int main(void) {
128 const struct CMUnitTest tests[] = {
129 cmocka_unit_test_setup_teardown(test_smb_krb5_kt_open,
130 setup_krb5_context,
131 teardown_krb5_context),
132 cmocka_unit_test_setup_teardown(test_smb_krb5_kt_open_file,
133 setup_krb5_context,
134 teardown_krb5_context),
135 cmocka_unit_test_setup_teardown(test_smb_krb5_kt_open_fail,
136 setup_krb5_context,
137 teardown_krb5_context),
138 cmocka_unit_test_setup_teardown(test_smb_krb5_kt_open_relative_memory,
139 setup_krb5_context,
140 teardown_krb5_context),
143 cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
144 return cmocka_run_group_tests(tests, NULL, NULL);