3 realm = K5Realm(create_kdb=False)
5 keyctl = which('keyctl')
6 out = realm.run([klist, '-c', 'KEYRING:process:abcd'], expected_code=1)
7 test_keyring = (keyctl is not None and
8 'Unknown credential cache type' not in out)
10 skipped('keyring collection tests', 'keyring support not built')
12 # Run the collection test program against each collection-enabled type.
13 realm.run(['./t_cccol', 'DIR:' + os.path.join(realm.testdir, 'cc')])
15 def cleanup_keyring(anchor, name):
16 out = realm.run(['keyctl', 'list', anchor])
17 if ('keyring: ' + name + '\n') in out:
18 keyid = realm.run(['keyctl', 'search', anchor, 'keyring', name])
19 realm.run(['keyctl', 'unlink', keyid.strip(), anchor])
21 # Use the test directory as the collection name to avoid colliding
22 # with other build trees.
24 col_ringname = '_krb_' + cname
26 # Remove any keys left behind by previous failed test runs.
27 cleanup_keyring('@s', cname)
28 cleanup_keyring('@s', col_ringname)
29 cleanup_keyring('@u', col_ringname)
31 # Run test program over each subtype, cleaning up as we go. Don't
32 # test the persistent subtype, since it supports only one
33 # collection and might be in actual use.
34 realm.run(['./t_cccol', 'KEYRING:' + cname])
35 cleanup_keyring('@s', col_ringname)
36 realm.run(['./t_cccol', 'KEYRING:legacy:' + cname])
37 cleanup_keyring('@s', col_ringname)
38 realm.run(['./t_cccol', 'KEYRING:session:' + cname])
39 cleanup_keyring('@s', col_ringname)
40 realm.run(['./t_cccol', 'KEYRING:user:' + cname])
41 cleanup_keyring('@u', col_ringname)
42 realm.run(['./t_cccol', 'KEYRING:process:abcd'])
43 realm.run(['./t_cccol', 'KEYRING:thread:abcd'])
47 # Test cursor semantics using real ccaches.
48 realm = K5Realm(create_host=False)
50 realm.addprinc('alice', password('alice'))
51 realm.addprinc('bob', password('bob'))
53 ccdir = os.path.join(realm.testdir, 'cc')
54 dccname = 'DIR:%s' % ccdir
55 duser = 'DIR::%s/tkt1' % ccdir
56 dalice = 'DIR::%s/tkt2' % ccdir
57 dbob = 'DIR::%s/tkt3' % ccdir
58 dnoent = 'DIR::%s/noent' % ccdir
59 realm.kinit('user', password('user'), flags=['-c', duser])
60 realm.kinit('alice', password('alice'), flags=['-c', dalice])
61 realm.kinit('bob', password('bob'), flags=['-c', dbob])
64 cleanup_keyring('@s', col_ringname)
65 krccname = 'KEYRING:session:' + cname
66 kruser = '%s:tkt1' % krccname
67 kralice = '%s:tkt2' % krccname
68 krbob = '%s:tkt3' % krccname
69 krnoent = '%s:noent' % krccname
70 realm.kinit('user', password('user'), flags=['-c', kruser])
71 realm.kinit('alice', password('alice'), flags=['-c', kralice])
72 realm.kinit('bob', password('bob'), flags=['-c', krbob])
74 def cursor_test(testname, args, expected):
75 outlines = realm.run(['./t_cccursor'] + args).splitlines()
78 if outlines != expected:
79 fail('Output not expected for %s\n' % testname +
80 'Expected output:\n\n' + '\n'.join(expected) + '\n\n' +
81 'Actual output:\n\n' + '\n'.join(outlines))
84 fccname = 'FILE:%s' % realm.ccache
85 cursor_test('file-default', [], [fccname])
86 cursor_test('file-default2', [realm.ccache], [fccname])
87 cursor_test('file-default3', [fccname], [fccname])
90 cursor_test('dir', [dccname], [duser, dalice, dbob])
91 cursor_test('dir-subsidiary', [duser], [duser])
92 cursor_test('dir-nofile', [dnoent], [])
95 mark('KEYRING cursor')
96 cursor_test('keyring', [krccname], [kruser, kralice, krbob])
97 cursor_test('keyring-subsidiary', [kruser], [kruser])
98 cursor_test('keyring-noent', [krnoent], [])
100 mark('MEMORY cursor')
103 cursor_test('filemem', [fccname, mfoo], [fccname])
104 cursor_test('dirmem', [dccname, mfoo], [duser, dalice, dbob])
105 cursor_test('mem', [mfoo, mbar], [mfoo])
107 cursor_test('keyringmem', [krccname, mfoo], [kruser, kralice, krbob])
109 # Test krb5_cccol_have_content.
110 mark('krb5_cccol_have_content')
111 realm.run(['./t_cccursor', dccname, 'CONTENT'])
112 realm.run(['./t_cccursor', fccname, 'CONTENT'])
113 realm.run(['./t_cccursor', realm.ccache, 'CONTENT'])
114 realm.run(['./t_cccursor', mfoo, 'CONTENT'], expected_code=1)
116 realm.run(['./t_cccursor', krccname, 'CONTENT'])
117 cleanup_keyring('@s', col_ringname)
119 # Make sure FILE doesn't yield a nonexistent default cache.
120 mark('FILE nonexistent')
121 realm.run([kdestroy])
122 cursor_test('noexist', [], [])
123 realm.run(['./t_cccursor', fccname, 'CONTENT'], expected_code=1)
125 success('Renewing credentials')