Path: blob/main/crypto/krb5/src/tests/gssapi/t_export_cred.py
34889 views
from k5test import *12# Test gss_export_cred and gss_import_cred for initiator creds,3# acceptor creds, and traditional delegated creds. t_s4u.py tests4# exporting and importing a synthesized S4U2Proxy delegated5# credential.67# Make up a filename to hold user's initial credentials.8def ccache_savefile(realm):9return os.path.join(realm.testdir, 'ccache.copy')1011# Move user's initial credentials into the save file.12def ccache_save(realm):13os.rename(realm.ccache, ccache_savefile(realm))1415# Copy user's initial credentials from the save file into the ccache.16def ccache_restore(realm):17shutil.copyfile(ccache_savefile(realm), realm.ccache)1819# Run t_export_cred with the saved ccache and verify that it stores a20# forwarded cred into the default ccache.21def check(realm, args):22ccache_restore(realm)23realm.run(['./t_export_cred'] + args)24realm.run([klist, '-f'], expected_msg='Flags: Ff')2526# Check a given set of arguments with no specified mech and with krb527# and SPNEGO as the specified mech.28def check_mechs(realm, args):29check(realm, args)30check(realm, ['-k'] + args)31check(realm, ['-s'] + args)3233# Make a realm, get forwardable tickets, and save a copy for each test.34realm = K5Realm(get_creds=False)35realm.kinit(realm.user_princ, password('user'), ['-f'])36ccache_save(realm)3738# Test with default initiator and acceptor cred.39tname = 'p:' + realm.host_princ40check_mechs(realm, [tname])4142# Test with principal-named initiator and acceptor cred.43iname = 'p:' + realm.user_princ44check_mechs(realm, ['-i', iname, '-a', tname, tname])4546# Test with host-based acceptor cred.47check_mechs(realm, ['-a', 'h:host', tname])4849success('gss_export_cred/gss_import_cred tests')505152