Skip to content

Commit

Permalink
Use expected_msg in test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
greghudson committed Jan 19, 2017
1 parent 7b7e5d9 commit d406afa
Show file tree
Hide file tree
Showing 40 changed files with 475 additions and 841 deletions.
18 changes: 8 additions & 10 deletions src/appl/gss-sample/t_gss_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,20 @@
# Run a gss-server process and a gss-client process, with additional
# gss-client flags given by options and additional gss-server flags
# given by server_options. Return the output of gss-client.
def run_client_server(realm, options, server_options, expected_code=0):
def run_client_server(realm, options, server_options, **kwargs):
portstr = str(realm.server_port())
server_args = [gss_server, '-export', '-port', portstr]
server_args += server_options + ['host']
server = realm.start_server(server_args, 'starting...')
out = realm.run([gss_client, '-port', portstr] + options +
[hostname, 'host', 'testmsg'], expected_code=expected_code)
realm.run([gss_client, '-port', portstr] + options +
[hostname, 'host', 'testmsg'], **kwargs)
stop_daemon(server)
return out

# Run a gss-server and gss-client process, and verify that gss-client
# displayed the expected output for a successful negotiation.
def server_client_test(realm, options, server_options):
out = run_client_server(realm, options, server_options)
if 'Signature verified.' not in out:
fail('Expected message not seen in gss-client output')
run_client_server(realm, options, server_options,
expected_msg='Signature verified.')

# Make up a filename to hold user's initial credentials.
def ccache_savefile(realm):
Expand Down Expand Up @@ -81,10 +79,10 @@ def pw_test(realm, options, server_options=[]):
# IAKERB, gss_aqcuire_cred_with_password() otherwise).
def wrong_pw_test(realm, options, server_options=[], iakerb=False):
options = options + ['-user', realm.user_princ, '-pass', 'wrongpw']
out = run_client_server(realm, options, server_options, expected_code=1)
failed_op = 'initializing context' if iakerb else 'acquiring creds'
if 'GSS-API error ' + failed_op not in out:
fail('Expected error not seen in gss-client output')
msg = 'GSS-API error ' + failed_op
run_client_server(realm, options, server_options, expected_code=1,
expected_msg=msg)

# Perform a test of the server and client with initial credentials
# obtained with the client keytab
Expand Down
6 changes: 3 additions & 3 deletions src/appl/user_user/t_user2user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
else:
srv_output = realm.start_server(['./uuserver', '9999'], 'Server started')

output = realm.run(['./uuclient', hostname, 'testing message', '9999'])
if 'uu-client: server says \"Hello, other end of connection.\"' not in output:
fail('Message not echoed back.')
msg = 'uu-client: server says "Hello, other end of connection."'
realm.run(['./uuclient', hostname, 'testing message', '9999'],
expected_msg=msg)


success('User-2-user test programs')
5 changes: 2 additions & 3 deletions src/kdc/t_emptytgt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from k5test import *

realm = K5Realm(create_host=False)
output = realm.run([kvno, 'krbtgt/'], expected_code=1)
if 'not found in Kerberos database' not in output:
fail('TGT lookup for empty realm failed in unexpected way')
realm.run([kvno, 'krbtgt/'], expected_code=1,
expected_msg='not found in Kerberos database')
success('Empty tgt lookup.')
13 changes: 4 additions & 9 deletions src/lib/krb5/krb/t_expire_warn.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,10 @@
output = realm.run(['./t_expire_warn', 'noexpire', 'pass', '0'])
if output:
fail('Unexpected output for noexpire')
output = realm.run(['./t_expire_warn', 'minutes', 'pass', '0'])
if ' less than one hour on ' not in output:
fail('Expected warning not seen for minutes')
output = realm.run(['./t_expire_warn', 'hours', 'pass', '0'])
if ' hours on ' not in output:
fail('Expected warning not seen for hours')
output = realm.run(['./t_expire_warn', 'days', 'pass', '0'])
if ' days on ' not in output:
fail('Expected warning not seen for days')
realm.run(['./t_expire_warn', 'minutes', 'pass', '0'],
expected_msg=' less than one hour on ')
realm.run(['./t_expire_warn', 'hours', 'pass', '0'], expected_msg=' hours on ')
realm.run(['./t_expire_warn', 'days', 'pass', '0'], expected_msg=' days on ')

# Check for expected expire callback behavior. These tests are
# carefully agnostic about whether the KDC supports last_req fields,
Expand Down
5 changes: 2 additions & 3 deletions src/tests/gssapi/t_authind.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
if '73757065727374726f6e67' not in out:
fail('Expected auth indicator not seen in name attributes')

out = realm.run(['./t_srcattrs', 'p:service/2'], expected_code=1)
if 'gss_init_sec_context: KDC policy rejects request' not in out:
fail('Expected error message not seen for indicator mismatch')
msg = 'gss_init_sec_context: KDC policy rejects request'
realm.run(['./t_srcattrs', 'p:service/2'], expected_code=1, expected_msg=msg)

realm.kinit(realm.user_princ, password('user'), ['-X', 'indicators=one two'])
out = realm.run(['./t_srcattrs', 'p:service/2'])
Expand Down
10 changes: 4 additions & 6 deletions src/tests/gssapi/t_ccselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@

# Verify that we can't get initiator creds with no credentials in the
# collection.
output = r1.run(['./t_ccselect', host1, '-'], expected_code=1)
if 'No Kerberos credentials available' not in output:
fail('Expected error not seen in output when no credentials available')
r1.run(['./t_ccselect', host1, '-'], expected_code=1,
expected_msg='No Kerberos credentials available')

# Make a directory collection and use it for client commands in both realms.
ccdir = os.path.join(r1.testdir, 'cc')
Expand Down Expand Up @@ -117,8 +116,7 @@
output = r1.run(['./t_ccselect', refserver])
if output != (bob + '\n'):
fail('bob not chosen via primary cache when no .k5identity line matches.')
output = r1.run(['./t_ccselect', 'h:bogus@' + hostname], expected_code=1)
if 'Can\'t find client principal noprinc' not in output:
fail('Expected error not seen when k5identity selects bad principal.')
r1.run(['./t_ccselect', 'h:bogus@' + hostname], expected_code=1,
expected_msg="Can't find client principal noprinc")

success('GSSAPI credential selection tests')
60 changes: 18 additions & 42 deletions src/tests/gssapi/t_client_keytab.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,35 @@
realm.extract_keytab(bob, realm.client_keytab)

# Test 1: no name/cache specified, pick first principal from client keytab
out = realm.run(['./t_ccselect', phost])
if realm.user_princ not in out:
fail('Authenticated as wrong principal')
realm.run(['./t_ccselect', phost], expected_msg=realm.user_princ)
realm.run([kdestroy])

# Test 2: no name/cache specified, pick principal from k5identity
k5idname = os.path.join(realm.testdir, '.k5identity')
k5id = open(k5idname, 'w')
k5id.write('%s service=host host=%s\n' % (bob, hostname))
k5id.close()
out = realm.run(['./t_ccselect', gssserver])
if bob not in out:
fail('Authenticated as wrong principal')
realm.run(['./t_ccselect', gssserver], expected_msg=bob)
os.remove(k5idname)
realm.run([kdestroy])

# Test 3: no name/cache specified, default ccache has name but no creds
realm.run(['./ccinit', realm.ccache, bob])
out = realm.run(['./t_ccselect', phost])
if bob not in out:
fail('Authenticated as wrong principal')
realm.run(['./t_ccselect', phost], expected_msg=bob)
# Leave tickets for next test.

# Test 4: name specified, non-collectable default cache doesn't match
out = realm.run(['./t_ccselect', phost, puser], expected_code=1)
if 'Principal in credential cache does not match desired name' not in out:
fail('Expected error not seen')
msg = 'Principal in credential cache does not match desired name'
realm.run(['./t_ccselect', phost, puser], expected_code=1, expected_msg=msg)
realm.run([kdestroy])

# Test 5: name specified, nonexistent default cache
out = realm.run(['./t_ccselect', phost, pbob])
if bob not in out:
fail('Authenticated as wrong principal')
realm.run(['./t_ccselect', phost, pbob], expected_msg=bob)
# Leave tickets for next test.

# Test 6: name specified, matches default cache, time to refresh
realm.run(['./ccrefresh', realm.ccache, '1'])
out = realm.run(['./t_ccselect', phost, pbob])
if bob not in out:
fail('Authenticated as wrong principal')
realm.run(['./t_ccselect', phost, pbob], expected_msg=bob)
out = realm.run(['./ccrefresh', realm.ccache])
if int(out) < 1000:
fail('Credentials apparently not refreshed')
Expand All @@ -67,9 +56,8 @@

# Test 8: ccache specified with name but no creds; name not in client keytab
realm.run(['./ccinit', realm.ccache, realm.host_princ])
out = realm.run(['./t_imp_cred', phost], expected_code=1)
if 'Credential cache is empty' not in out:
fail('Expected error not seen')
realm.run(['./t_imp_cred', phost], expected_code=1,
expected_msg='Credential cache is empty')
realm.run([kdestroy])

# Test 9: ccache specified with name but no creds; name in client keytab
Expand Down Expand Up @@ -104,39 +92,28 @@
# Test 12: name specified, matching cache in collection with no creds
bobcache = os.path.join(ccdir, 'tktbob')
realm.run(['./ccinit', bobcache, bob])
out = realm.run(['./t_ccselect', phost, pbob])
if bob not in out:
fail('Authenticated as wrong principal')
realm.run(['./t_ccselect', phost, pbob], expected_msg=bob)
# Leave tickets for next test.

# Test 13: name specified, matching cache in collection, time to refresh
realm.run(['./ccrefresh', bobcache, '1'])
out = realm.run(['./t_ccselect', phost, pbob])
if bob not in out:
fail('Authenticated as wrong principal')
realm.run(['./t_ccselect', phost, pbob], expected_msg=bob)
out = realm.run(['./ccrefresh', bobcache])
if int(out) < 1000:
fail('Credentials apparently not refreshed')
realm.run([kdestroy, '-A'])

# Test 14: name specified, collection has default for different principal
realm.kinit(realm.user_princ, password('user'))
out = realm.run(['./t_ccselect', phost, pbob])
if bob not in out:
fail('Authenticated as wrong principal')
out = realm.run([klist])
if 'Default principal: %s\n' % realm.user_princ not in out:
fail('Default cache overwritten by acquire_cred')
realm.run(['./t_ccselect', phost, pbob], expected_msg=bob)
msg = 'Default principal: %s\n' % realm.user_princ
realm.run([klist], expected_msg=msg)
realm.run([kdestroy, '-A'])

# Test 15: name specified, collection has no default cache
out = realm.run(['./t_ccselect', phost, pbob])
if bob not in out:
fail('Authenticated as wrong principal')
realm.run(['./t_ccselect', phost, pbob], expected_msg=bob)
# Make sure the tickets we acquired didn't become the default
out = realm.run([klist], expected_code=1)
if 'No credentials cache found' not in out:
fail('Expected error not seen')
realm.run([klist], expected_code=1, expected_msg='No credentials cache found')
realm.run([kdestroy, '-A'])

# Test 16: default client keytab cannot be resolved, but valid
Expand All @@ -145,8 +122,7 @@
bad_cktname = realm.special_env('bad_cktname', False, krb5_conf=conf)
del bad_cktname['KRB5_CLIENT_KTNAME']
realm.kinit(realm.user_princ, password('user'))
out = realm.run(['./t_ccselect', phost], env=bad_cktname)
if realm.user_princ not in out:
fail('Expected principal not seen for bad client keytab name')
realm.run(['./t_ccselect', phost], env=bad_cktname,
expected_msg=realm.user_princ)

success('Client keytab tests')
4 changes: 1 addition & 3 deletions src/tests/gssapi/t_enctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def test(msg, ienc, aenc, tktenc='', tktsession='', proto='', isubkey='',
# and check that it fails with the expected error message.
def test_err(msg, ienc, aenc, expected_err):
shutil.copyfile(os.path.join(realm.testdir, 'save'), realm.ccache)
out = realm.run(cmdline(ienc, aenc), expected_code=1)
if expected_err not in out:
fail(msg)
realm.run(cmdline(ienc, aenc), expected_code=1, expected_msg=expected_err)


# By default, all of the key enctypes should be aes256.
Expand Down
4 changes: 1 addition & 3 deletions src/tests/gssapi/t_export_cred.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def ccache_restore(realm):
def check(realm, args):
ccache_restore(realm)
realm.run(['./t_export_cred'] + args)
output = realm.run([klist, '-f'])
if 'Flags: Ff' not in output:
fail('Forwarded tickets not found in ccache after t_export_cred')
realm.run([klist, '-f'], expected_msg='Flags: Ff')

# Check a given set of arguments with no specified mech and with krb5
# and SPNEGO as the specified mech.
Expand Down

0 comments on commit d406afa

Please sign in to comment.