Best Python code snippet using localstack_python
t_proxy.py
Source:t_proxy.py
...43 'kpasswd_server': proxyurl4,44 'http_anchors': 'FILE:%s' % proxyca}}}45kpasswd_input = (password('user') + '\n' + password('user') + '\n' +46 password('user') + '\n')47def start_proxy(realm, keycertpem):48 proxy_conf_path = os.path.join(realm.testdir, 'kdcproxy.conf')49 proxy_exec_path = os.path.join(srctop, 'util', 'wsgiref-kdcproxy.py')50 conf = open(proxy_conf_path, 'w')51 conf.write('[%s]\n' % realm.realm)52 conf.write('kerberos = kerberos://localhost:%d\n' % realm.portbase)53 conf.write('kpasswd = kpasswd://localhost:%d\n' % (realm.portbase + 2))54 conf.close()55 realm.env['KDCPROXY_CONFIG'] = proxy_conf_path56 cmd = [sys.executable, proxy_exec_path, str(realm.server_port()),57 keycertpem]58 return realm.start_server(cmd, sentinel='proxy server ready')59# Fail: untrusted issuer and hostname doesn't match.60mark('untrusted issuer, hostname mismatch')61output("running pass 1: issuer not trusted and hostname doesn't match\n")62realm = K5Realm(krb5_conf=unanchored_krb5_conf, get_creds=False,63 create_host=False)64proxy = start_proxy(realm, proxywrongpem)65realm.kinit(realm.user_princ, password=password('user'), expected_code=1)66stop_daemon(proxy)67realm.stop()68# Fail: untrusted issuer, host name matches subject.69mark('untrusted issuer, hostname subject match')70output("running pass 2: subject matches, issuer not trusted\n")71realm = K5Realm(krb5_conf=unanchored_krb5_conf, get_creds=False,72 create_host=False)73proxy = start_proxy(realm, proxysubjectpem)74realm.kinit(realm.user_princ, password=password('user'), expected_code=1)75stop_daemon(proxy)76realm.stop()77# Fail: untrusted issuer, host name matches subjectAltName.78mark('untrusted issuer, hostname SAN match')79output("running pass 3: subjectAltName matches, issuer not trusted\n")80realm = K5Realm(krb5_conf=unanchored_krb5_conf, get_creds=False,81 create_host=False)82proxy = start_proxy(realm, proxysanpem)83realm.kinit(realm.user_princ, password=password('user'), expected_code=1)84stop_daemon(proxy)85realm.stop()86# Fail: untrusted issuer, certificate signature is bad.87mark('untrusted issuer, bad signature')88output("running pass 4: subject matches, issuer not trusted\n")89realm = K5Realm(krb5_conf=unanchored_krb5_conf, get_creds=False,90 create_host=False)91proxy = start_proxy(realm, proxybadpem)92realm.kinit(realm.user_princ, password=password('user'), expected_code=1)93stop_daemon(proxy)94realm.stop()95# Fail: trusted issuer but hostname doesn't match.96mark('trusted issuer, hostname mismatch')97output("running pass 5: issuer trusted but hostname doesn't match\n")98realm = K5Realm(krb5_conf=anchored_name_krb5_conf, get_creds=False,99 create_host=False)100proxy = start_proxy(realm, proxywrongpem)101realm.kinit(realm.user_princ, password=password('user'), expected_code=1)102stop_daemon(proxy)103realm.stop()104# Succeed: trusted issuer and host name matches subject.105mark('trusted issuer, hostname subject match')106output("running pass 6: issuer trusted, subject matches\n")107realm = K5Realm(krb5_conf=anchored_name_krb5_conf, start_kadmind=True,108 get_creds=False)109proxy = start_proxy(realm, proxysubjectpem)110realm.kinit(realm.user_princ, password=password('user'))111realm.run([kvno, realm.host_princ])112realm.run([kpasswd, realm.user_princ], input=kpasswd_input)113stop_daemon(proxy)114realm.stop()115# Succeed: trusted issuer and host name matches subjectAltName.116mark('trusted issuer, hostname SAN match')117output("running pass 7: issuer trusted, subjectAltName matches\n")118realm = K5Realm(krb5_conf=anchored_name_krb5_conf, start_kadmind=True,119 get_creds=False)120proxy = start_proxy(realm, proxysanpem)121realm.kinit(realm.user_princ, password=password('user'))122realm.run([kvno, realm.host_princ])123realm.run([kpasswd, realm.user_princ], input=kpasswd_input)124stop_daemon(proxy)125realm.stop()126# Fail: certificate signature is bad.127mark('bad signature')128output("running pass 8: issuer trusted and subjectAltName matches, sig bad\n")129realm = K5Realm(krb5_conf=anchored_name_krb5_conf,130 get_creds=False,131 create_host=False)132proxy = start_proxy(realm, proxybadpem)133realm.kinit(realm.user_princ, password=password('user'), expected_code=1)134stop_daemon(proxy)135realm.stop()136# Fail: trusted issuer but IP doesn't match.137mark('trusted issuer, IP mismatch')138output("running pass 9: issuer trusted but no name matches IP\n")139realm = K5Realm(krb5_conf=anchored_ipv4_krb5_conf, get_creds=False,140 create_host=False)141proxy = start_proxy(realm, proxywrongpem)142realm.kinit(realm.user_princ, password=password('user'), expected_code=1)143stop_daemon(proxy)144realm.stop()145# Fail: trusted issuer, but subject does not match.146mark('trusted issuer, IP mismatch (hostname in subject)')147output("running pass 10: issuer trusted, but subject does not match IP\n")148realm = K5Realm(krb5_conf=anchored_ipv4_krb5_conf, get_creds=False,149 create_host=False)150proxy = start_proxy(realm, proxysubjectpem)151realm.kinit(realm.user_princ, password=password('user'), expected_code=1)152stop_daemon(proxy)153realm.stop()154# Succeed: trusted issuer and host name matches subjectAltName.155mark('trusted issuer, IP SAN match')156output("running pass 11: issuer trusted, subjectAltName matches IP\n")157realm = K5Realm(krb5_conf=anchored_ipv4_krb5_conf, start_kadmind=True,158 get_creds=False)159proxy = start_proxy(realm, proxysanpem)160realm.kinit(realm.user_princ, password=password('user'))161realm.run([kvno, realm.host_princ])162realm.run([kpasswd, realm.user_princ], input=kpasswd_input)163stop_daemon(proxy)164realm.stop()165# Fail: certificate signature is bad.166mark('bad signature (IP hostname)')167output("running pass 12: issuer trusted, names don't match, signature bad\n")168realm = K5Realm(krb5_conf=anchored_ipv4_krb5_conf, get_creds=False,169 create_host=False)170proxy = start_proxy(realm, proxybadpem)171realm.kinit(realm.user_princ, password=password('user'), expected_code=1)172stop_daemon(proxy)173realm.stop()174# Succeed: trusted issuer and host name matches subject, using kadmin175# configuration to find kpasswdd.176mark('trusted issuer, hostname subject match (kadmin)')177output("running pass 13: issuer trusted, subject matches\n")178realm = K5Realm(krb5_conf=anchored_kadmin_krb5_conf, start_kadmind=True,179 get_creds=False, create_host=False)180proxy = start_proxy(realm, proxysubjectpem)181realm.run([kpasswd, realm.user_princ], input=kpasswd_input)182stop_daemon(proxy)183realm.stop()184# Succeed: trusted issuer and host name matches subjectAltName, using185# kadmin configuration to find kpasswdd.186mark('trusted issuer, hostname SAN match (kadmin)')187output("running pass 14: issuer trusted, subjectAltName matches\n")188realm = K5Realm(krb5_conf=anchored_kadmin_krb5_conf, start_kadmind=True,189 get_creds=False, create_host=False)190proxy = start_proxy(realm, proxysanpem)191realm.run([kpasswd, realm.user_princ], input=kpasswd_input)192stop_daemon(proxy)193realm.stop()194# Succeed: trusted issuer and host name matches subjectAltName (give or take195# case).196mark('trusted issuer, hostname SAN case-insensitive match')197output("running pass 15: issuer trusted, subjectAltName case-insensitive\n")198realm = K5Realm(krb5_conf=anchored_upcasename_krb5_conf, start_kadmind=True,199 get_creds=False, create_host=False)200proxy = start_proxy(realm, proxysanpem)201realm.run([kpasswd, realm.user_princ], input=kpasswd_input)202stop_daemon(proxy)203realm.stop()...
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!!