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