Blame src/tests/t_kadmin_parsing.py

Packit Service 99d1c0
from k5test import *
Packit Service 99d1c0
Packit Service 99d1c0
# This file contains tests for kadmin command parsing.  Principal
Packit Service 99d1c0
# flags (which can also be used in kadm5.acl or krb5.conf) are tested
Packit Service 99d1c0
# in t_princflags.py.
Packit Service 99d1c0
Packit Service 99d1c0
# kadmin recognizes time intervals using either the
Packit Service 99d1c0
# krb5_string_to_deltat() formats or the relative getdate.y formats.
Packit Service 99d1c0
# (Absolute getdate.y formats also work with the current time
Packit Service 99d1c0
# subtracted; this isn't very useful and we won't test it here.)
Packit Service 99d1c0
intervals = (
Packit Service 99d1c0
    # krb5_string_to_deltat() formats.  Whitespace ( \t\n) is allowed
Packit Service 99d1c0
    # before or between most elements or at the end, but not after
Packit Service 99d1c0
    # 's'.  Negative or oversized numbers are allowed in most places,
Packit Service 99d1c0
    # but not after the first number in an HH:MM:SS form.
Packit Service 99d1c0
    ('28s', '0 days 00:00:28'),
Packit Service 99d1c0
    ('7m ', '0 days 00:07:00'),
Packit Service 99d1c0
    ('6m 9s', '0 days 00:06:09'),
Packit Service 99d1c0
    ('2h', '0 days 02:00:00'),
Packit Service 99d1c0
    ('2h-5s', '0 days 01:59:55'),
Packit Service 99d1c0
    ('2h3m', '0 days 02:03:00'),
Packit Service 99d1c0
    ('2h3m5s', '0 days 02:03:05'),
Packit Service 99d1c0
    ('5d ', '5 days 00:00:00'),
Packit Service 99d1c0
    ('5d-48s', '4 days 23:59:12'),
Packit Service 99d1c0
    ('5d18m', '5 days 00:18:00'),
Packit Service 99d1c0
    ('5d -6m56s', '4 days 23:54:56'),
Packit Service 99d1c0
    ('5d4h', '5 days 04:00:00'),
Packit Service 99d1c0
    ('5d4h 1s', '5 days 04:00:01'),
Packit Service 99d1c0
    ('5d4h3m', '5 days 04:03:00'),
Packit Service 99d1c0
    (' \t 15d \n 4h  3m  2s', '15 days 04:03:02'),
Packit Service 99d1c0
    ('10-8:45:0', '10 days 08:45:00'),
Packit Service 99d1c0
    ('1000:67:99', '41 days 17:08:39'),
Packit Service 99d1c0
    ('999:11', '41 days 15:11:00'),
Packit Service 99d1c0
    ('382512', '4 days 10:15:12'),
Packit Service 99d1c0
Packit Service 99d1c0
    # getdate.y relative formats (and "never", which is handled
Packit Service 99d1c0
    # specially as a zero interval).  Any number of relative forms can
Packit Service 99d1c0
    # be specified in any order.  Whitespace is ignored before or
Packit Service 99d1c0
    # after any token.  "month" and "year" are allowed as units but
Packit Service 99d1c0
    # depend on the current time, so we won't test them.  Plural unit
Packit Service 99d1c0
    # names are treated identically to singular unit names.  Numbers
Packit Service 99d1c0
    # before unit names are optional and may be signed; there are also
Packit Service 99d1c0
    # aliases for some numbers.  "ago" inverts the interval up to the
Packit Service 99d1c0
    # point where it appears.
Packit Service 99d1c0
    ('never', '0 days 00:00:00'),
Packit Service 99d1c0
    ('fortnight', '14 days 00:00:00'),
Packit Service 99d1c0
    ('3 day ago 4 weeks 8 hours', '25 days 08:00:00'),
Packit Service 99d1c0
    ('8 second -3 secs 5 minute ago 63 min', '0 days 00:57:55'),
Packit Service 99d1c0
    ('min mins min mins min', '0 days 00:05:00'),
Packit Service 99d1c0
    ('tomorrow tomorrow today yesterday now last minute', '0 days 23:59:00'),
Packit Service 99d1c0
    ('this second next minute first hour third fortnight fourth day '
Packit Service 99d1c0
     'fifth weeks sixth sec seventh secs eighth second ninth mins tenth '
Packit Service 99d1c0
     'day eleventh min twelfth sec', '91 days 01:22:34'))
Packit Service 99d1c0
Packit Service 99d1c0
realm = K5Realm(create_host=False, get_creds=False)
Packit Service 99d1c0
realm.run([kadminl, 'addpol', 'pol'])
Packit Service 99d1c0
for instr, outstr in intervals:
Packit Service 99d1c0
    realm.run([kadminl, 'modprinc', '-maxlife', instr, realm.user_princ])
Packit Service 99d1c0
    msg = 'Maximum ticket life: ' + outstr + '\n'
Packit Service 99d1c0
    realm.run([kadminl, 'getprinc', realm.user_princ], expected_msg=msg)
Packit Service 99d1c0
Packit Service 99d1c0
    realm.run([kadminl, 'modprinc', '-maxrenewlife', instr, realm.user_princ])
Packit Service 99d1c0
    msg = 'Maximum renewable life: ' + outstr + '\n'
Packit Service 99d1c0
    realm.run([kadminl, 'getprinc', realm.user_princ], expected_msg=msg)
Packit Service 99d1c0
Packit Service 99d1c0
    realm.run([kadminl, 'modpol', '-maxlife', instr, 'pol'])
Packit Service 99d1c0
    msg = 'Maximum password life: ' + outstr + '\n'
Packit Service 99d1c0
    realm.run([kadminl, 'getpol', 'pol'], expected_msg=msg)
Packit Service 99d1c0
Packit Service 99d1c0
    realm.run([kadminl, 'modpol', '-minlife', instr, 'pol'])
Packit Service 99d1c0
    msg = 'Minimum password life: ' + outstr + '\n'
Packit Service 99d1c0
    realm.run([kadminl, 'getpol', 'pol'], expected_msg=msg)
Packit Service 99d1c0
Packit Service 99d1c0
    realm.run([kadminl, 'modpol', '-failurecountinterval', instr, 'pol'])
Packit Service 99d1c0
    msg = 'Password failure count reset interval: ' + outstr + '\n'
Packit Service 99d1c0
    realm.run([kadminl, 'getpol', 'pol'], expected_msg=msg)
Packit Service 99d1c0
Packit Service 99d1c0
    realm.run([kadminl, 'modpol', '-lockoutduration', instr, 'pol'])
Packit Service 99d1c0
    msg = 'Password lockout duration: ' + outstr + '\n'
Packit Service 99d1c0
    realm.run([kadminl, 'getpol', 'pol'], expected_msg=msg)
Packit Service 99d1c0
Packit Service 99d1c0
success('kadmin command parsing tests')