| 1 |
#!/usr/bin/perl -w |
| 2 |
# |
| 3 |
# Ensure that non-renewable tickets don't cause spurious failure. |
| 4 |
# |
| 5 |
# k5start 4.0 had a bug where if tickets weren't renewable, k5start -H 1 would |
| 6 |
# attempt to reauthenticate. Ensure that bug doesn't recur. |
| 7 |
# |
| 8 |
# Written by Russ Allbery <[email protected]> |
| 9 |
# Copyright 2021 Russ Allbery <[email protected]> |
| 10 |
# Copyright 2012 |
| 11 |
# The Board of Trustees of the Leland Stanford Junior University |
| 12 |
# |
| 13 |
# SPDX-License-Identifier: MIT |
| 14 |
|
| 15 |
use Test::More; |
| 16 |
|
| 17 |
# The full path to the newly-built k5start client. |
| 18 |
our $K5START = "$ENV{C_TAP_BUILD}/../commands/k5start"; |
| 19 |
|
| 20 |
# The path to our data directory, which contains the keytab to use to test. |
| 21 |
our $DATA = "$ENV{C_TAP_BUILD}/data"; |
| 22 |
|
| 23 |
# Load our test utility programs. |
| 24 |
require "$ENV{C_TAP_SOURCE}/libtest.pl"; |
| 25 |
|
| 26 |
# We have to generate a local krb5.conf that disables any attempt to get |
| 27 |
# renewable tickets. Try to locate the local krb5.conf that we're supposed to |
| 28 |
# use and skip if we can't find one. |
| 29 |
my $krb5conf = $ENV{KRB5_CONFIG}; |
| 30 |
unless ($krb5conf) { |
| 31 |
for my $path ('/etc', '/usr/local/etc', "$ENV{C_TAP_BUILD}/data") { |
| 32 |
if (-r "$path/krb5.conf") { |
| 33 |
$krb5conf = "$path/krb5.conf"; |
| 34 |
last; |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
if ($krb5conf) { |
| 39 |
open (CONF, '<', $krb5conf) or BAIL_OUT ("cannot open $krb5conf: $!"); |
| 40 |
open (NEWCONF, '>', './krb5.conf') |
| 41 |
or BAIL_OUT ("cannot create krb5.conf: $!"); |
| 42 |
while (<CONF>) { |
| 43 |
next if /^\s*renew_lifetime\b/; |
| 44 |
print NEWCONF $_; |
| 45 |
} |
| 46 |
close CONF; |
| 47 |
close NEWCONF; |
| 48 |
$ENV{KRB5_CONFIG} = './krb5.conf'; |
| 49 |
} else { |
| 50 |
plan skip_all => "no krb5.conf found, set KRB5_CONFIG"; |
| 51 |
exit 0; |
| 52 |
} |
| 53 |
|
| 54 |
# Decide whether we have the configuration to run the tests. |
| 55 |
my $principal; |
| 56 |
if (not -f "$DATA/test.keytab" or not -f "$DATA/test.principal") { |
| 57 |
unlink 'krb5.conf'; |
| 58 |
plan skip_all => "no keytab configuration"; |
| 59 |
exit 0; |
| 60 |
} else { |
| 61 |
$principal = contents ("$DATA/test.principal"); |
| 62 |
$ENV{KRB5CCNAME} = 'krb5cc_test'; |
| 63 |
unlink 'krb5cc_test'; |
| 64 |
unless (kinit ("$DATA/test.keytab", $principal, '-l', '1h')) { |
| 65 |
unlink 'krb5.conf'; |
| 66 |
plan skip_all => 'cannot get non-renewable tickets'; |
| 67 |
exit 0; |
| 68 |
} |
| 69 |
plan tests => 3; |
| 70 |
} |
| 71 |
|
| 72 |
# Now, k5start should start without reauthenticating. |
| 73 |
my ($out, $err, $status) |
| 74 |
= command ($K5START, '-H', '20', '-f', '/nonexistent', $principal); |
| 75 |
is ($status, 0, 'k5start -H 20 succeeds without reauthenticating'); |
| 76 |
is ($err, '', ' with no errors'); |
| 77 |
is ($out, '', ' and no output'); |
| 78 |
|
| 79 |
# Clean up. |
| 80 |
unlink 'krb5cc_test', 'krb5.conf'; |