xref: /freebsd/crypto/krb5/src/tests/t_errmsg.py (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1from k5test import *
2
3realm = K5Realm(create_kdb=False)
4
5# Test err_fmt, using klist -c to induce errors.
6fmt1 = 'FOO Error: %M (see http://localhost:1234/%C for more information)'
7conf1 = {'libdefaults': {'err_fmt': fmt1}}
8e1 = realm.special_env('fmt1', False, krb5_conf=conf1)
9out = realm.run([klist, '-c', 'testdir/xx/yy'], env=e1, expected_code=1)
10if out != ('klist: FOO Error: No credentials cache found (filename: '
11           'testdir/xx/yy) (see http://localhost:1234/-1765328189 for more '
12           'information)\n'):
13    fail('err_fmt expansion failed')
14conf2 = {'libdefaults': {'err_fmt': '%M - %C'}}
15e2 = realm.special_env('fmt2', False, krb5_conf=conf2)
16out = realm.run([klist, '-c', 'testdir/xx/yy'], env=e2, expected_code=1)
17if out != ('klist: No credentials cache found (filename: testdir/xx/yy) - '
18           '-1765328189\n'):
19    fail('err_fmt expansion failed')
20conf3 = {'libdefaults': {'err_fmt': '%%%M %-% %C%'}}
21e3 = realm.special_env('fmt3', False, krb5_conf=conf3)
22out = realm.run([klist, '-c', 'testdir/xx/yy'], env=e3, expected_code=1)
23if out != ('klist: %No credentials cache found (filename: testdir/xx/yy) %-% '
24           '-1765328189%\n'):
25    fail('err_fmt expansion failed')
26
27success('error message tests')
28