def test_conf_checks_package(self): with mock.patch.object(util, 'check_file_exists', return_value=True): with mock.patch.object(pkcs11, 'import_pkcs', side_effect=ImportError()): with self.assertRaises(errors.ConfigValidationException): pkcs11.conf_validator("name", self.good_conf)
def test_conf_allows_valid(self): session = mock.Mock() lib = mock.Mock() lib.getSlotList.return_value = [self.good_conf['slot']] lib.openSession.return_value = session mod = mock.Mock() mod.PyKCS11Lib.return_value = lib with mock.patch.object(util, 'check_file_exists', return_value=True): with mock.patch.object(pkcs11, 'import_pkcs', return_value=mod): pkcs11.conf_validator("name", self.good_conf)
def test_conf_checks_valid_slot(self): class MockExc(Exception): pass lib = mock.Mock() lib.getSlotList.return_value = [4, 6] mod = mock.Mock() mod.PyKCS11Error = MockExc mod.PyKCS11Lib.return_value = lib with mock.patch.object(util, 'check_file_exists', return_value=True): with mock.patch.object(pkcs11, 'import_pkcs', return_value=mod): with self.assertRaises(errors.ConfigValidationException): pkcs11.conf_validator("name", self.good_conf)
def test_conf_checks_valid_pin(self): class MockExc(Exception): pass session = mock.Mock() session.login.side_effect = MockExc() lib = mock.Mock() lib.getSlotList.return_value = [self.good_conf['slot']] lib.openSession.return_value = session mod = mock.Mock() mod.PyKCS11Error = MockExc mod.PyKCS11Lib.return_value = lib with mock.patch.object(util, 'check_file_exists', return_value=True): with mock.patch.object(pkcs11, 'import_pkcs', return_value=mod): with self.assertRaises(errors.ConfigValidationException): pkcs11.conf_validator("name", self.good_conf)
def test_conf_checks_file_permissions(self): with mock.patch.object(util, 'check_file_exists', return_value=False): with self.assertRaises(errors.ConfigValidationException): pkcs11.conf_validator("name", self.good_conf)
def test_conf_checks_fields(self): for key in self.good_conf: conf = self.good_conf.copy() del conf[key] with self.assertRaises(errors.ConfigValidationException): pkcs11.conf_validator("name", conf)