def test_refresh_credential_cache(self): ''' This test method depends on whether to use GSSAPI authentication mechanism. When this method throws Krb5Error, do check whether enable USING_GSSAPI and configure GSSAPI related configurations correctly. ''' from tcms.integration.djqpid.utils import refresh_HTTP_credential_cache old_cache = os.getenv('KRB5CCNAME', None) ccache_file = refresh_HTTP_credential_cache() os.environ['KRB5CCNAME'] = ccache_file self.assert_(os.path.exists(ccache_file), 'The credential cache file was not be generated.') op = subprocess.Popen('klist'.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = op.communicate() if old_cache: os.environ['KRB5CCNAME'] = old_cache else: del os.environ['KRB5CCNAME'] reader = StringIO(stdout) line1 = reader.readline().strip(os.linesep) line2 = reader.readline().strip(os.linesep) reader.close() self.assertEqual( line1, 'Ticket cache: FILE:%s' % ccache_file, 'Ticket cache file name does ' 'not match the newly generated.') self.assertEqual( line2, 'Default principal: %s' % st.SERVICE_PRINCIPAL, 'Default principal within credential cache does ' 'not match the SERVICE_PRINCIPAL in settings')
def test_refresh_credential_cache(self): ''' This test method depends on whether to use GSSAPI authentication mechanism. When this method throws Krb5Error, do check whether enable USING_GSSAPI and configure GSSAPI related configurations correctly. ''' from tcms.integration.djqpid.utils import refresh_HTTP_credential_cache old_cache = os.getenv('KRB5CCNAME', None) ccache_file = refresh_HTTP_credential_cache() os.environ['KRB5CCNAME'] = ccache_file self.assert_(os.path.exists(ccache_file), 'The credential cache file was not be generated.') op = subprocess.Popen('klist'.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = op.communicate() if old_cache: os.environ['KRB5CCNAME'] = old_cache else: del os.environ['KRB5CCNAME'] reader = StringIO(stdout) line1 = reader.readline().strip(os.linesep) line2 = reader.readline().strip(os.linesep) reader.close() self.assertEqual(line1, 'Ticket cache: FILE:%s' % ccache_file, 'Ticket cache file name does ' 'not match the newly generated.') self.assertEqual(line2, 'Default principal: %s' % st.SERVICE_PRINCIPAL, 'Default principal within credential cache does ' 'not match the SERVICE_PRINCIPAL in settings')
def __connect_with_gssapi(self): ev_krb5ccname = 'KRB5CCNAME' old_ccache = os.getenv(ev_krb5ccname, None) new_ccache = refresh_HTTP_credential_cache() os.environ[ev_krb5ccname] = 'FILE:%s' % new_ccache options = { 'host': st.QPID_BROKER_HOST, 'port': st.QPID_BROKER_PORT, 'sasl_mechanisms': st.QPID_BROKER_SASL_MECHANISMS, 'transport': st.QPID_BROKER_TRANSPORT, } Producer._connection = Connection(**options) try: Producer._connection.open() finally: if old_ccache: os.environ[ev_krb5ccname] = old_ccache else: # OS has no KRB5CCNAME originally. # The current one is unncessary after establishing the connection del os.environ[ev_krb5ccname]