Best Python code snippet using lisa_python
t_vfy_increds.py
Source:t_vfy_increds.py
...22# or implied warranty.23from k5test import *24realm = K5Realm()25# Verify the default test realm credentials with the default keytab.26realm.run_as_server(['./t_vfy_increds'])27realm.run_as_server(['./t_vfy_increds', '-n'])28# Verify after updating the keytab (so the keytab contains an outdated29# version 1 key followed by an up-to-date version 2 key).30realm.run_kadminl('ktadd ' + realm.host_princ)31realm.run_as_server(['./t_vfy_increds'])32realm.run_as_server(['./t_vfy_increds', '-n'])33# Bump the host key without updating the keytab and make sure that34# verification fails as we expect it to.35realm.run_kadminl('change_password -randkey ' + realm.host_princ)36realm.run_as_server(['./t_vfy_increds'], expected_code=1)37realm.run_as_server(['./t_vfy_increds', '-n'], expected_code=1)38# Simulate a system where the hostname has changed and the keytab39# contains host service principals with a hostname that no longer40# matches. Verify after updating the keytab with a host service41# principal that has hostname that doesn't match the host running the42# test. Verify should succeed, with or without nofail.43realm.run_kadminl('addprinc -randkey host/wrong.hostname')44realm.run_kadminl('ktadd host/wrong.hostname')45realm.run_as_server(['./t_vfy_increds'])46realm.run_as_server(['./t_vfy_increds', '-n'])47# Remove the keytab and verify again. This should succeed if nofail48# is not set, and fail if it is set.49os.remove(realm.keytab)50realm.run_as_server(['./t_vfy_increds'])51realm.run_as_server(['./t_vfy_increds', '-n'], expected_code=1)52# Create an empty keytab file and verify again. This simulates a53# system where an admin ran "touch krb5.keytab" to work around a54# Solaris Kerberos bug where krb5_kt_default() fails if the keytab55# file doesn't exist. Verification should succeed in nofail is not56# set. (An empty keytab file appears as corrupt to keytab calls,57# causing a KRB5_KEYTAB_BADVNO error, so any tightening of the58# krb5_verify_init_creds semantics needs to take this into account.)59open(realm.keytab, 'w').close()60realm.run_as_server(['./t_vfy_increds'])61realm.run_as_server(['./t_vfy_increds', '-n'], expected_code=1)62os.remove(realm.keytab)63# Add an NFS service principal to keytab. Verify should ignore it by64# default (succeeding unless nofail is set), but should verify with it65# when it is specifically requested.66realm.run_kadminl('addprinc -randkey ' + realm.nfs_princ)67realm.run_kadminl('ktadd ' + realm.nfs_princ)68realm.run_as_server(['./t_vfy_increds'])69realm.run_as_server(['./t_vfy_increds', '-n'], expected_code=1)70realm.run_as_server(['./t_vfy_increds', realm.nfs_princ])71realm.run_as_server(['./t_vfy_increds', '-n', realm.nfs_princ])72# Invalidating the NFS keys in the keytab. We should get the same73# results with the default principal argument, but verification should74# now fail if we request it specifically.75realm.run_kadminl('change_password -randkey ' + realm.nfs_princ)76realm.run_as_server(['./t_vfy_increds'])77realm.run_as_server(['./t_vfy_increds', '-n'], expected_code=1)78realm.run_as_server(['./t_vfy_increds', realm.nfs_princ], expected_code=1)79realm.run_as_server(['./t_vfy_increds', '-n', realm.nfs_princ],80 expected_code=1)81# Spot-check that verify_ap_req_nofail works equivalently to the82# programmatic nofail option.83realm.stop()84conf = { 'server' : { 'libdefaults' : { 'verify_ap_req_nofail' : 'true' } } }85realm = K5Realm(krb5_conf=conf)86os.remove(realm.keytab)87realm.run_as_server(['./t_vfy_increds'], expected_code=1)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!