Path: blob/main/crypto/krb5/src/clients/kvno/t_kvno.py
34889 views
from k5test import *12realm = K5Realm()34def check_cache(ccache, expected_services):5# Fetch the klist output and skip past the header.6lines = realm.run([klist, '-c', ccache]).splitlines()7lines = lines[4:]89# For each line not beginning with an indent, match against the10# expected service principals.11svcs = {x: True for x in expected_services}12for l in lines:13if not l.startswith('\t'):14svcprinc = l.split()[4]15if svcprinc in svcs:16del svcs[svcprinc]17else:18fail('unexpected service princ ' + svcprinc)1920if svcs:21fail('services not found in klist output: ' + ' '.join(svcs.keys()))222324mark('no options')25realm.run([kvno, realm.user_princ], expected_msg='[email protected]: kvno = 1')26check_cache(realm.ccache, [realm.krbtgt_princ, realm.user_princ])2728mark('-e')29msgs = ('etypes requested in TGS request: camellia128-cts',30'/KDC has no support for encryption type')31realm.run([kvno, '-e', 'camellia128-cts', realm.host_princ],32expected_code=1, expected_trace=msgs)3334mark('--cached-only')35realm.run([kvno, '--cached-only', realm.user_princ], expected_msg='kvno = 1')36realm.run([kvno, '--cached-only', realm.host_princ],37expected_code=1, expected_msg='Matching credential not found')38check_cache(realm.ccache, [realm.krbtgt_princ, realm.user_princ])3940mark('--no-store')41realm.run([kvno, '--no-store', realm.host_princ], expected_msg='kvno = 1')42check_cache(realm.ccache, [realm.krbtgt_princ, realm.user_princ])4344mark('--out-cache') # and multiple services45out_ccache = os.path.join(realm.testdir, 'ccache.out')46realm.run([kvno, '--out-cache', out_ccache,47realm.host_princ, realm.admin_princ])48check_cache(realm.ccache, [realm.krbtgt_princ, realm.user_princ])49check_cache(out_ccache, [realm.host_princ, realm.admin_princ])5051mark('--out-cache --cached-only') # tests out-cache overwriting, and -q52realm.run([kvno, '--out-cache', out_ccache, '--cached-only', realm.host_princ],53expected_code=1, expected_msg='Matching credential not found')54out = realm.run([kvno, '-q', '--out-cache', out_ccache, '--cached-only',55realm.user_princ])56if out:57fail('unexpected kvno output with -q')58check_cache(out_ccache, [realm.user_princ])5960mark('-U') # and -c61svc_ccache = os.path.join(realm.testdir, 'ccache.svc')62realm.run([kinit, '-k', '-c', svc_ccache, realm.host_princ])63realm.run([kvno, '-c', svc_ccache, '-U', 'user', realm.host_princ])64realm.run([klist, '-c', svc_ccache], expected_msg='for client user@')65realm.run([kvno, '-c', svc_ccache, '-U', 'user', '--out-cache', out_ccache,66realm.host_princ])67out = realm.run([klist, '-c', out_ccache])68if ('Default principal: [email protected]' not in out):69fail('wrong default principal in klist output')7071# More S4U options are tested in tests/gssapi/t_s4u.py.72# --u2u is tested in tests/t_u2u.py.7374success('kvno tests')757677