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 <http://www.eyrie.org/~eagle/software/rra-c-util/>.
7 * Written by Russ Allbery <eagle@eyrie.org>
8 * Copyright 2010, 2011, 2013
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.
31 #include <portable/krb5.h>
32 #include <portable/system.h>
34 #include <tests/tap/basic.h>
35 #include <tests/tap/process.h>
36 #include <util/macros.h>
37 #include <util/messages-krb5.h>
38 #include <util/messages.h>
39 #include <util/xmalloc.h>
46 test_warn(void *data UNUSED)
52 code = krb5_init_context(&ctx);
54 die_krb5(ctx, code, "cannot create context");
55 code = krb5_parse_name(ctx, "foo@bar@EXAMPLE.COM", &princ);
57 warn_krb5(ctx, code, "principal parse failed");
59 die("unexpected success parsing principal");
64 test_die(void *data UNUSED)
70 code = krb5_init_context(&ctx);
72 die_krb5(ctx, code, "cannot create context");
73 code = krb5_parse_name(ctx, "foo@bar@EXAMPLE.COM", &princ);
75 die_krb5(ctx, code, "principal parse failed");
77 die("unexpected success parsing principal");
96 /* First, we have to get what the correct error message is. */
97 code = krb5_init_context(&ctx);
99 bail("cannot create context");
100 code = krb5_parse_name(ctx, "foo@bar@EXAMPLE.COM", &princ);
101 message = krb5_get_error_message(ctx, code);
103 xasprintf(&wanted, "principal parse failed: %s\n", message);
104 is_function_output(test_warn, NULL, 0, wanted, "warn_krb5");
105 is_function_output(test_die, NULL, 1, wanted, "die_krb5");
108 message_program_name = "msg-test";
109 xasprintf(&wanted, "msg-test: principal parse failed: %s\n", message);
110 is_function_output(test_warn, NULL, 0, wanted, "warn_krb5 with name");
111 is_function_output(test_die, NULL, 1, wanted, "die_krb5 with name");
114 message_handlers_warn(0);
115 is_function_output(test_warn, NULL, 0, "", "warn_krb5 with no handlers");
116 message_handlers_die(0);
117 is_function_output(test_die, NULL, 1, "", "warn_krb5 with no handlers");
119 krb5_free_error_message(ctx, message);
120 krb5_free_context(ctx);