Beispiel #1
0
class SSLUtilTest(unittest.TestCase):
    '''
    Unit test that check SSLUtil methods
    '''


    def runTest(self):
        sslUtil = SSLUtil()
        sslUtil.timeout = 10
		
        # Reset the test
        certificate = sslUtil.getServerCertificate('https://gecos.solutia-it.es:8443/')
        sslUtil.removeCertificateFromTrustedCAs(certificate)
        certificate = sslUtil.getServerCertificate('https://ws003.juntadeandalucia.es/')
        sslUtil.removeCertificateFromTrustedCAs(certificate)

        # Start the test
        SSLUtil.disableSSLCertificatesVerification()
   		self.assertFalse(SSLUtil.isSSLCertificatesVerificationEnabled())

   		self.assertFalse(SSLUtil.isSSLCertificatesVerificationEnabled())
        SSLUtil.enableSSLCertificatesVerification()

        
		self.assertFalse(sslUtil.isServerCertificateTrusted(None))
		self.assertFalse(sslUtil.isServerCertificateTrusted('https://ws003.juntadeandalucia.es/'))
Beispiel #2
0
        sslUtil.removeCertificateFromTrustedCAs(certificate)

        # Start the test
        SSLUtil.disableSSLCertificatesVerification()
   		self.assertFalse(SSLUtil.isSSLCertificatesVerificationEnabled())

   		self.assertFalse(SSLUtil.isSSLCertificatesVerificationEnabled())
        SSLUtil.enableSSLCertificatesVerification()

        
		self.assertFalse(sslUtil.isServerCertificateTrusted(None))
		self.assertFalse(sslUtil.isServerCertificateTrusted('https://ws003.juntadeandalucia.es/'))

        SSLUtil.disableSSLCertificatesVerification()
		self.assertTrue(sslUtil.isServerCertificateTrusted('https://ws003.juntadeandalucia.es/'))
        SSLUtil.enableSSLCertificatesVerification()

		self.assertTrue(sslUtil.isServerCertificateTrusted('https://www.google.es/'))

        self.assertIsNotNone(sslUtil.getUntrustedCertificateCause('https://ws003.juntadeandalucia.es/'))
        print('Untrusted certificate cause: %s'%(sslUtil.getUntrustedCertificateCause('https://ws003.juntadeandalucia.es/')))
        
        self.assertIsNotNone(sslUtil.getUntrustedCertificateErrorCode('https://ws003.juntadeandalucia.es/'))
        self.assertEquals(sslUtil.getUntrustedCertificateErrorCode('https://ws003.juntadeandalucia.es/'), SSL_R_CERTIFICATE_VERIFY_FAILED)
        print('Untrusted certificate error code: %s'%(sslUtil.getUntrustedCertificateErrorCode('https://ws003.juntadeandalucia.es/')))
        
        
        self.assertIsNotNone(sslUtil.getUntrustedCertificateCause('https://192.168.0.15:8443/'))
        print('Untrusted certificate cause: %s'%(sslUtil.getUntrustedCertificateCause('https://192.168.0.15:8443/')))
        
        self.assertIsNotNone(sslUtil.getUntrustedCertificateErrorCode('https://192.168.0.15:8443/'))