| 1 |
#!/usr/bin/perl -w |
| 2 |
# |
| 3 |
# Tests for k5start 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 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 |
# 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 |
# Don't overwrite the user's ticket cache. |
| 27 |
$ENV{KRB5CCNAME} = 'krb5cc_test'; |
| 28 |
|
| 29 |
# Decide whether we have the configuration to run the tests. |
| 30 |
my ($principal, $out, $err, $status); |
| 31 |
if (not -f "$DATA/test.keytab" or not -f "$DATA/test.principal") { |
| 32 |
plan skip_all => 'no keytab configuration'; |
| 33 |
exit 0; |
| 34 |
} elsif (not tokens ()) { |
| 35 |
plan skip_all => 'no current AFS tokens'; |
| 36 |
exit 0; |
| 37 |
} else { |
| 38 |
$principal = contents ("$DATA/test.principal"); |
| 39 |
unlink 'krb5cc_test'; |
| 40 |
($out, $err, $status) |
| 41 |
= command ($K5START, '-tqUf', "$DATA/test.keytab", '--', 'tokens'); |
| 42 |
if ($err eq "k5start: cannot create PAG: AFS support is not available\n") { |
| 43 |
plan skip_all => 'not built with AFS support'; |
| 44 |
exit 0; |
| 45 |
} else { |
| 46 |
plan tests => 22; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
# Basic token test. |
| 51 |
is ($status, 0, 'k5start -t succeeds'); |
| 52 |
is ($err, '', ' with no errors'); |
| 53 |
like ($out, qr/^(User\'s \([^\)]+\) )?(\S+ )?[Tt]okens for /m, |
| 54 |
' and the right output'); |
| 55 |
my ($default, $service) = klist (); |
| 56 |
is ($default, undef, ' and the normal ticket cache is untouched'); |
| 57 |
|
| 58 |
# Set the token program to something that doesn't obtain tokens. |
| 59 |
# Everything should still work, but we should have no tokens. |
| 60 |
$ENV{AKLOG} = '/bin/true'; |
| 61 |
($out, $err, $status) |
| 62 |
= command ($K5START, '-tqUf', "$DATA/test.keytab", '--', 'tokens'); |
| 63 |
is ($status, 0, 'k5start -t succeeds with no aklog'); |
| 64 |
is ($err, '', ' with no errors'); |
| 65 |
unlike ($out, qr/^(User\'s \([^\)]+\) )?(\S+ )?[Tt]okens for /m, |
| 66 |
' and we have no tokens'); |
| 67 |
delete $ENV{AKLOG}; |
| 68 |
|
| 69 |
# Make sure that we run the right aklog program. |
| 70 |
$ENV{AKLOG} = $FAKE_AKLOG; |
| 71 |
($out, $err, $status) |
| 72 |
= command ($K5START, '-tqUf', "$DATA/test.keytab", '--', 'true'); |
| 73 |
is ($status, 0, 'k5start -t succeeds with fake aklog'); |
| 74 |
is ($err, '', ' with no errors'); |
| 75 |
is ($out, "Running fake aklog\n", ' and we ran the fake aklog'); |
| 76 |
delete $ENV{AKLOG}; |
| 77 |
|
| 78 |
# AKLOG should override KINIT_PROG. |
| 79 |
$ENV{KINIT_PROG} = $FAKE_AKLOG; |
| 80 |
$ENV{AKLOG} = '/bin/true'; |
| 81 |
($out, $err, $status) |
| 82 |
= command ($K5START, '-tqUf', "$DATA/test.keytab", '--', 'true'); |
| 83 |
is ($status, 0, 'k5start -t succeeds with /bin/true aklog'); |
| 84 |
is ($err, '', ' with no errors'); |
| 85 |
is ($out, '', ' and we did not run KINIT_PROG'); |
| 86 |
delete $ENV{AKLOG}; |
| 87 |
delete $ENV{KINIT_PROG}; |
| 88 |
|
| 89 |
# KINIT_PROG should still work. |
| 90 |
$ENV{KINIT_PROG} = $FAKE_AKLOG; |
| 91 |
($out, $err, $status) |
| 92 |
= command ($K5START, '-tqUf', "$DATA/test.keytab", '--', 'true'); |
| 93 |
is ($status, 0, 'k5start -t succeeds with KINIT_PROG'); |
| 94 |
is ($err, '', ' with no errors'); |
| 95 |
is ($out, "Running fake aklog\n", ' and we ran the fake aklog'); |
| 96 |
delete $ENV{KINIT_PROG}; |
| 97 |
|
| 98 |
# First, get an existing ticket cache. Then, be sure that, even though |
| 99 |
# the ticket cache is good with -H, we still run aklog if -t was given. |
| 100 |
$ENV{KINIT_PROG} = $FAKE_AKLOG; |
| 101 |
($out, $err, $status) = command ($K5START, '-qUf', "$DATA/test.keytab"); |
| 102 |
is ($status, 0, 'k5start succeeds'); |
| 103 |
is ($err, '', ' with no errors'); |
| 104 |
is ($out, '', ' and no output'); |
| 105 |
($out, $err, $status) |
| 106 |
= command ($K5START, '-tqU', '-H', '60', '-f', "$DATA/test.keytab"); |
| 107 |
is ($status, 0, ' and k5start -H 60 -t succeeds with KINIT_PROG'); |
| 108 |
is ($err, '', ' with no errors'); |
| 109 |
is ($out, "Running fake aklog\n", ' and we ran the fake aklog'); |
| 110 |
delete $ENV{KINIT_PROG}; |
| 111 |
|
| 112 |
# Clean up. |
| 113 |
unlink 'krb5cc_test'; |