Debian Codegraph @

tests/k5start/keyring-t

raw
1 #!/usr/bin/perl -w
2 #
3 # Tests for k5start support of keyrings.
4 #
5 # Written by Russ Allbery <[email protected]>
6 # Copyright 2021 Russ Allbery <[email protected]>
7 # Copyright 2011, 2014
8 # The Board of Trustees of the Leland Stanford Junior University
9 #
10 # SPDX-License-Identifier: MIT
11
12 use Test::More;
13
14 # The full path to the newly-built k5start client.
15 our $K5START = "$ENV{C_TAP_BUILD}/../commands/k5start";
16
17 # The path to our data directory, which contains the keytab to use to test.
18 our $DATA = "$ENV{C_TAP_BUILD}/data";
19
20 # Load our test utility programs.
21 require "$ENV{C_TAP_SOURCE}/libtest.pl";
22
23 # Decide whether we have the configuration to run the tests.
24 my $principal;
25 if (not -f "$DATA/test.keytab" or not -f "$DATA/test.principal") {
26 plan skip_all => 'no keytab configuration';
27 } else {
28 $principal = contents ("$DATA/test.principal");
29 $ENV{KRB5CCNAME} = 'KEYRING:test';
30 unless (kinit ("$DATA/test.keytab", $principal) && !-f 'KEYRING:test'
31 && klist ()) {
32 plan skip_all => 'cannot use keyring caches';
33 }
34 my ($out, $err, $status) = command ($K5START, '-k', 'KEYRING:test', '-H1');
35 if ($status != 0 && $err =~ /unknown ccache type/) {
36 plan skip_all => 'Heimdal does not support keyring caches';
37 }
38 plan tests => 14;
39 }
40
41 # Basic authentication test.
42 my ($out, $err, $status) = command ($K5START, '-Uf', "$DATA/test.keytab");
43 is ($status, 0, 'Basic k5start command succeeds');
44 is ($err, '', ' with no errors');
45 like ($out, qr/^Kerberos initialization for \Q$principal\E(\@\S+)?\n\z/,
46 ' and the right output');
47 my ($default, $service) = klist ();
48 like ($default, qr/^\Q$principal\E(\@\S+)?\z/, ' for the right principal');
49 like ($service, qr%^krbtgt/%, ' and the right service');
50 system ('kdestroy');
51
52 # We should get an error if we try to use a non-FILE keyring with -o, -g, or
53 # -m.
54 for my $flag (qw/-o -g -m/) {
55 ($out, $err, $status)
56 = command ($K5START, $flag, 640, '-Uf', "$DATA/test.keytab");
57 is ($status, 1, "k5start $flag with keyring fails");
58 is ($err, "k5start: cache type KEYRING not allowed with -o, -g, or -m\n",
59 ' with correct error');
60 is ($out, '', ' and no output');
61 }
62 system ('kdestroy');