xref: /freebsd/crypto/krb5/src/tests/t_kadmin_parsing.py (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubertfrom k5test import *
2*7f2fe78bSCy Schubert
3*7f2fe78bSCy Schubert# This file contains tests for kadmin command parsing.  Principal
4*7f2fe78bSCy Schubert# flags (which can also be used in kadm5.acl or krb5.conf) are tested
5*7f2fe78bSCy Schubert# in t_princflags.py.
6*7f2fe78bSCy Schubert
7*7f2fe78bSCy Schubert# kadmin recognizes time intervals using either the
8*7f2fe78bSCy Schubert# krb5_string_to_deltat() formats or the relative getdate.y formats.
9*7f2fe78bSCy Schubert# (Absolute getdate.y formats also work with the current time
10*7f2fe78bSCy Schubert# subtracted; this isn't very useful and we won't test it here.)
11*7f2fe78bSCy Schubertintervals = (
12*7f2fe78bSCy Schubert    # krb5_string_to_deltat() formats.  Whitespace ( \t\n) is allowed
13*7f2fe78bSCy Schubert    # before or between most elements or at the end, but not after
14*7f2fe78bSCy Schubert    # 's'.  Negative or oversized numbers are allowed in most places,
15*7f2fe78bSCy Schubert    # but not after the first number in an HH:MM:SS form.
16*7f2fe78bSCy Schubert    ('28s', '0 days 00:00:28'),
17*7f2fe78bSCy Schubert    ('7m ', '0 days 00:07:00'),
18*7f2fe78bSCy Schubert    ('6m 9s', '0 days 00:06:09'),
19*7f2fe78bSCy Schubert    ('2h', '0 days 02:00:00'),
20*7f2fe78bSCy Schubert    ('2h-5s', '0 days 01:59:55'),
21*7f2fe78bSCy Schubert    ('2h3m', '0 days 02:03:00'),
22*7f2fe78bSCy Schubert    ('2h3m5s', '0 days 02:03:05'),
23*7f2fe78bSCy Schubert    ('5d ', '5 days 00:00:00'),
24*7f2fe78bSCy Schubert    ('5d-48s', '4 days 23:59:12'),
25*7f2fe78bSCy Schubert    ('5d18m', '5 days 00:18:00'),
26*7f2fe78bSCy Schubert    ('5d -6m56s', '4 days 23:54:56'),
27*7f2fe78bSCy Schubert    ('5d4h', '5 days 04:00:00'),
28*7f2fe78bSCy Schubert    ('5d4h 1s', '5 days 04:00:01'),
29*7f2fe78bSCy Schubert    ('5d4h3m', '5 days 04:03:00'),
30*7f2fe78bSCy Schubert    (' \t 15d \n 4h  3m  2s', '15 days 04:03:02'),
31*7f2fe78bSCy Schubert    ('10-8:45:0', '10 days 08:45:00'),
32*7f2fe78bSCy Schubert    ('1000:67:99', '41 days 17:08:39'),
33*7f2fe78bSCy Schubert    ('999:11', '41 days 15:11:00'),
34*7f2fe78bSCy Schubert    ('382512', '4 days 10:15:12'),
35*7f2fe78bSCy Schubert
36*7f2fe78bSCy Schubert    # getdate.y relative formats (and "never", which is handled
37*7f2fe78bSCy Schubert    # specially as a zero interval).  Any number of relative forms can
38*7f2fe78bSCy Schubert    # be specified in any order.  Whitespace is ignored before or
39*7f2fe78bSCy Schubert    # after any token.  "month" and "year" are allowed as units but
40*7f2fe78bSCy Schubert    # depend on the current time, so we won't test them.  Plural unit
41*7f2fe78bSCy Schubert    # names are treated identically to singular unit names.  Numbers
42*7f2fe78bSCy Schubert    # before unit names are optional and may be signed; there are also
43*7f2fe78bSCy Schubert    # aliases for some numbers.  "ago" inverts the interval up to the
44*7f2fe78bSCy Schubert    # point where it appears.
45*7f2fe78bSCy Schubert    ('never', '0 days 00:00:00'),
46*7f2fe78bSCy Schubert    ('fortnight', '14 days 00:00:00'),
47*7f2fe78bSCy Schubert    ('3 day ago 4 weeks 8 hours', '25 days 08:00:00'),
48*7f2fe78bSCy Schubert    ('8 second -3 secs 5 minute ago 63 min', '0 days 00:57:55'),
49*7f2fe78bSCy Schubert    ('min mins min mins min', '0 days 00:05:00'),
50*7f2fe78bSCy Schubert    ('tomorrow tomorrow today yesterday now last minute', '0 days 23:59:00'),
51*7f2fe78bSCy Schubert    ('this second next minute first hour third fortnight fourth day '
52*7f2fe78bSCy Schubert     'fifth weeks sixth sec seventh secs eighth second ninth mins tenth '
53*7f2fe78bSCy Schubert     'day eleventh min twelfth sec', '91 days 01:22:34'))
54*7f2fe78bSCy Schubert
55*7f2fe78bSCy Schubertrealm = K5Realm(create_host=False, get_creds=False)
56*7f2fe78bSCy Schubertrealm.run([kadminl, 'addpol', 'pol'])
57*7f2fe78bSCy Schubertfor instr, outstr in intervals:
58*7f2fe78bSCy Schubert    realm.run([kadminl, 'modprinc', '-maxlife', instr, realm.user_princ])
59*7f2fe78bSCy Schubert    msg = 'Maximum ticket life: ' + outstr + '\n'
60*7f2fe78bSCy Schubert    realm.run([kadminl, 'getprinc', realm.user_princ], expected_msg=msg)
61*7f2fe78bSCy Schubert
62*7f2fe78bSCy Schubert    realm.run([kadminl, 'modprinc', '-maxrenewlife', instr, realm.user_princ])
63*7f2fe78bSCy Schubert    msg = 'Maximum renewable life: ' + outstr + '\n'
64*7f2fe78bSCy Schubert    realm.run([kadminl, 'getprinc', realm.user_princ], expected_msg=msg)
65*7f2fe78bSCy Schubert
66*7f2fe78bSCy Schubert    realm.run([kadminl, 'modpol', '-maxlife', instr, 'pol'])
67*7f2fe78bSCy Schubert    msg = 'Maximum password life: ' + outstr + '\n'
68*7f2fe78bSCy Schubert    realm.run([kadminl, 'getpol', 'pol'], expected_msg=msg)
69*7f2fe78bSCy Schubert
70*7f2fe78bSCy Schubert    realm.run([kadminl, 'modpol', '-minlife', instr, 'pol'])
71*7f2fe78bSCy Schubert    msg = 'Minimum password life: ' + outstr + '\n'
72*7f2fe78bSCy Schubert    realm.run([kadminl, 'getpol', 'pol'], expected_msg=msg)
73*7f2fe78bSCy Schubert
74*7f2fe78bSCy Schubert    realm.run([kadminl, 'modpol', '-failurecountinterval', instr, 'pol'])
75*7f2fe78bSCy Schubert    msg = 'Password failure count reset interval: ' + outstr + '\n'
76*7f2fe78bSCy Schubert    realm.run([kadminl, 'getpol', 'pol'], expected_msg=msg)
77*7f2fe78bSCy Schubert
78*7f2fe78bSCy Schubert    realm.run([kadminl, 'modpol', '-lockoutduration', instr, 'pol'])
79*7f2fe78bSCy Schubert    msg = 'Password lockout duration: ' + outstr + '\n'
80*7f2fe78bSCy Schubert    realm.run([kadminl, 'getpol', 'pol'], expected_msg=msg)
81*7f2fe78bSCy Schubert
82*7f2fe78bSCy Schubertsuccess('kadmin command parsing tests')
83