Debian Codegraph @

tests/krenew/afs-t

raw
1 #!/usr/bin/perl -w
2 #
3 # Tests for krenew with AFS.
4 #
5 # Written by Russ Allbery <[email protected]>
6 # Copyright 2021 Russ Allbery <[email protected]>
7 # Copyright 2008-2009
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 krenew client.
15 our $KRENEW = "$ENV{C_TAP_BUILD}/../commands/krenew";
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 # The path to a shell script that just prints something out.
21 our $FAKE_AKLOG = "$ENV{C_TAP_SOURCE}/data/fake-aklog";
22
23 # Load our test utility programs.
24 require "$ENV{C_TAP_SOURCE}/libtest.pl";
25
26 # Decide whether we have the configuration to run the tests.
27 my ($principal, $out, $err, $status);
28 if (not -f "$DATA/test.keytab" or not -f "$DATA/test.principal") {
29 plan skip_all => 'no keytab configuration';
30 exit 0;
31 } elsif (not tokens ()) {
32 plan skip_all => 'no current AFS tokens';
33 exit 0;
34 } else {
35 $principal = contents ("$DATA/test.principal");
36 $ENV{KRB5CCNAME} = 'krb5cc_test';
37 unlink 'krb5cc_test';
38 unless (kinit ("$DATA/test.keytab", $principal, '-r', '2h', '-l', '1h')) {
39 plan skip_all => 'cannot get renewable tickets';
40 exit 0;
41 }
42 ($out, $err, $status) = command ($KRENEW, '-t', '--', 'tokens');
43 if ($err eq "krenew: cannot create PAG: AFS support is not available\n") {
44 plan skip_all => 'not built with AFS support';
45 exit 0;
46 } else {
47 plan tests => 15;
48 }
49 }
50
51 # Now, see if we can renew tickets and get a token.
52 is ($status, 0, 'krenew -t succeeds');
53 is ($err, '', ' with no errors');
54 like ($out, qr/^(User\'s \([^\)]+\) )?(\S+ )?[Tt]okens for /m,
55 ' and the right output');
56
57 # Set the token program to something that doesn't obtain tokens. Everything
58 # should still work, but we should have no tokens.
59 $ENV{AKLOG} = '/bin/true';
60 ($out, $err, $status) = command ($KRENEW, '-t', '--', 'tokens');
61 is ($status, 0, 'krenew -t succeeds with no aklog');
62 is ($err, '', ' with no errors');
63 unlike ($out, qr/^(User\'s \([^\)]+\) )?(\S+ )?[Tt]okens for /m,
64 ' and we have no tokens');
65 delete $ENV{AKLOG};
66
67 # Make sure that we run the right aklog program. We need to pass -K to reduce
68 # the wakeup period or krenew will want tickets that last longer than an hour
69 # (the default -K interval when running a command).
70 $ENV{AKLOG} = $FAKE_AKLOG;
71 ($out, $err, $status) = command ($KRENEW, '-K', 10, '-t', '--', 'true');
72 is ($status, 0, 'krenew -t succeeds with fake aklog');
73 is ($err, '', ' with no errors');
74 is ($out, "Running fake aklog\n", ' and we ran the fake aklog');
75 delete $ENV{AKLOG};
76
77 # AKLOG should override KINIT_PROG.
78 $ENV{KINIT_PROG} = $FAKE_AKLOG;
79 $ENV{AKLOG} = '/bin/true';
80 ($out, $err, $status) = command ($KRENEW, '-t', '--', 'true');
81 is ($status, 0, 'krenew -t succeeds with /bin/true aklog');
82 is ($err, '', ' with no errors');
83 is ($out, '', ' and we did not run KINIT_PROG');
84 delete $ENV{AKLOG};
85 delete $ENV{KINIT_PROG};
86
87 # KINIT_PROG should still work.
88 $ENV{KINIT_PROG} = $FAKE_AKLOG;
89 ($out, $err, $status) = command ($KRENEW, '-K', 10, '-t', '--', 'true');
90 is ($status, 0, 'krenew -t succeeds with KINIT_PROG');
91 is ($err, '', ' with no errors');
92 is ($out, "Running fake aklog\n", ' and we ran the fake aklog');
93 delete $ENV{KINIT_PROG};
94
95 unlink 'krb5cc_test';