2 * Test suite for Kerberos error handling routines.
4 * The canonical version of this file is maintained in the rra-c-util package,
5 * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
7 * Written by Russ Allbery <eagle@eyrie.org>
8 * Copyright 2010, 2011, 2013, 2014
9 * The Board of Trustees of the Leland Stanford Junior University
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
32 # include <portable/krb5.h>
34 #include <portable/system.h>
36 #include <tests/tap/basic.h>
37 #include <tests/tap/process.h>
38 #include <util/macros.h>
40 # include <util/messages-krb5.h>
42 #include <util/messages.h>
43 #include <util/xmalloc.h>
46 /* Skip the whole test if not built with Kerberos support. */
51 skip_all("not built with Kerberos support");
60 test_warn(void *data UNUSED)
66 code = krb5_init_context(&ctx);
68 die_krb5(ctx, code, "cannot create context");
69 code = krb5_parse_name(ctx, "foo@bar@EXAMPLE.COM", &princ);
71 warn_krb5(ctx, code, "principal parse failed");
73 die("unexpected success parsing principal");
78 test_die(void *data UNUSED)
84 code = krb5_init_context(&ctx);
86 die_krb5(ctx, code, "cannot create context");
87 code = krb5_parse_name(ctx, "foo@bar@EXAMPLE.COM", &princ);
89 die_krb5(ctx, code, "principal parse failed");
91 die("unexpected success parsing principal");
103 krb5_error_code code;
104 krb5_principal princ;
110 /* First, we have to get what the correct error message is. */
111 code = krb5_init_context(&ctx);
113 bail("cannot create context");
114 code = krb5_parse_name(ctx, "foo@bar@EXAMPLE.COM", &princ);
115 message = krb5_get_error_message(ctx, code);
117 xasprintf(&wanted, "principal parse failed: %s\n", message);
118 is_function_output(test_warn, NULL, 0, wanted, "warn_krb5");
119 is_function_output(test_die, NULL, 1, wanted, "die_krb5");
122 message_program_name = "msg-test";
123 xasprintf(&wanted, "msg-test: principal parse failed: %s\n", message);
124 is_function_output(test_warn, NULL, 0, wanted, "warn_krb5 with name");
125 is_function_output(test_die, NULL, 1, wanted, "die_krb5 with name");
128 message_handlers_warn(0);
129 is_function_output(test_warn, NULL, 0, "", "warn_krb5 with no handlers");
130 message_handlers_die(0);
131 is_function_output(test_die, NULL, 1, "", "warn_krb5 with no handlers");
133 krb5_free_error_message(ctx, message);
134 krb5_free_context(ctx);
138 #endif /* HAVE_KRB5 */