def test_extensions_bad(self): csr = x509_csr.X509Csr() ext = x509_ext.X509ExtensionKeyUsage() ext.set_usage('keyCertSign', True) csr.add_extension(ext) with self.assertRaises(validators.ValidationError) as e: validators.extensions( csr=csr, allowed_extensions=['basicConstraints', 'nameConstraints']) self.assertEqual("Extension 'keyUsage' not allowed", str(e.exception))
def test_extensions_bad(self): ext_mock = mock.MagicMock() ext_mock.get_name.return_value = 'BAD' ext_mock.get_value.return_value = 'BAD' csr_mock = mock.MagicMock() csr_mock.get_extensions.return_value = [ext_mock] with self.assertRaises(validators.ValidationError) as e: validators.extensions( csr=csr_mock, allowed_extensions=['GOOD-1', 'GOOD-2']) self.assertEqual("Extension 'BAD' not allowed", str(e.exception))
def test_extensions_good(self): csr = x509_csr.X509Csr() ext = x509_ext.X509ExtensionKeyUsage() ext.set_usage('keyCertSign', True) csr.add_extension(ext) self.assertEqual( None, validators.extensions( csr=csr, allowed_extensions=['basicConstraints', 'keyUsage']))
def test_extensions_good(self): csr = x509_csr.X509Csr() ext = x509_ext.X509ExtensionKeyUsage() ext.set_usage('keyCertSign', True) csr.add_extension(ext) self.assertEqual( None, validators.extensions( csr=csr, allowed_extensions=['basicConstraints', 'keyUsage'] ) )
def test_extensions_good(self): ext_mock = mock.MagicMock() ext_mock.get_name.return_value = 'GOOD-1' ext_mock.get_value.return_value = 'GOOD-1' csr_mock = mock.MagicMock() csr_mock.get_extensions.return_value = [ext_mock] self.assertEqual( None, validators.extensions( csr=csr_mock, allowed_extensions=['GOOD-1', 'GOOD-2'] ) )