| 1 |
#!/usr/bin/perl -w |
| 2 |
# |
| 3 |
# Tests for krenew 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 and krenew clients. |
| 15 |
our $K5START = "$ENV{C_TAP_BUILD}/../commands/k5start"; |
| 16 |
our $KRENEW = "$ENV{C_TAP_BUILD}/../commands/krenew"; |
| 17 |
|
| 18 |
# The path to our data directory, which contains the keytab to use to test. |
| 19 |
our $DATA = "$ENV{C_TAP_BUILD}/data"; |
| 20 |
|
| 21 |
# Load our test utility programs. |
| 22 |
require "$ENV{C_TAP_SOURCE}/libtest.pl"; |
| 23 |
|
| 24 |
# Decide whether we have the configuration to run the tests. |
| 25 |
my $principal; |
| 26 |
if (not -f "$DATA/test.keytab" or not -f "$DATA/test.principal") { |
| 27 |
plan skip_all => 'no keytab configuration'; |
| 28 |
} else { |
| 29 |
$principal = contents ("$DATA/test.principal"); |
| 30 |
$ENV{KRB5CCNAME} = 'KEYRING:test'; |
| 31 |
unless (kinit ("$DATA/test.keytab", $principal, '-r', '2h', '-l', '10m')) { |
| 32 |
plan skip_all => 'cannot get renewable tickets in keyring'; |
| 33 |
} |
| 34 |
unless (!-f 'KEYRING:test' && klist ()) { |
| 35 |
plan skip_all => 'cannot use keyring caches'; |
| 36 |
} |
| 37 |
my ($out, $err, $status) = command ($K5START, '-k', 'KEYRING:test', '-H1'); |
| 38 |
if ($status != 0 && $err =~ /unknown ccache type/) { |
| 39 |
plan skip_all => 'Heimdal does not support keyring caches'; |
| 40 |
} |
| 41 |
plan tests => 5; |
| 42 |
} |
| 43 |
|
| 44 |
# Basic renewal test. |
| 45 |
my ($out, $err, $status) = command ($KRENEW, '-v'); |
| 46 |
is ($status, 0, 'Basic krenew command succeeds'); |
| 47 |
is ($err, '', ' with no errors'); |
| 48 |
like ($out, qr/^krenew: renewing credentials for \Q$principal\E(\@\S+)?\n\z/, |
| 49 |
' and the right output'); |
| 50 |
my ($default, $service) = klist (); |
| 51 |
like ($default, qr/^\Q$principal\E(\@\S+)?\z/, ' for the right principal'); |
| 52 |
like ($service, qr%^krbtgt/%, ' and the right service'); |