Merge "Increase test coverage to 100% in validators.py"

This commit is contained in:
Jenkins 2014-07-03 19:00:43 +00:00 committed by Gerrit Code Review
commit 68a2309949
2 changed files with 56 additions and 7 deletions

View File

@ -115,7 +115,7 @@ class NewSecretValidator(ValidatorBase):
"name": {"type": "string"},
"algorithm": {"type": "string"},
"mode": {"type": "string"},
"bit_length": {"type": "integer", "minimum": 0},
"bit_length": {"type": "integer", "minimum": 1},
"expiration": {"type": "string"},
"payload": {"type": "string"},
"payload_content_type": {"type": "string"},
@ -302,12 +302,6 @@ class NewOrderValidator(ValidatorBase):
# TODO(reaperhulk): Future API change will move from bit to byte_length
bit_length = int(secret.get('bit_length', 0))
if bit_length <= 0:
raise exception.UnsupportedField(field="bit_length",
schema=schema_name,
reason=u._("Must have non-zero "
"positive bit_length "
"to generate secret"))
if bit_length % 8 != 0:
raise exception.UnsupportedField(field="bit_length",
schema=schema_name,

View File

@ -526,6 +526,23 @@ class WhenTestingOrderValidator(testtools.TestCase):
self.assertEqual('algorithm', exception.invalid_field)
def test_should_fail_invalid_json_data_type(self):
self.assertRaises(
excep.InvalidObject,
self.validator.validate,
[],
)
def test_should_fail_payload_in_secret(self):
self.order_req['secret']['payload'] = "YWJjZGVmZw=="
self.order_req['secret']['payload_content_encoding'] = 'base64'
self.assertRaises(
excep.InvalidObject,
self.validator.validate,
self.order_req
)
class WhenTestingContainerValidator(testtools.TestCase):
@ -702,6 +719,9 @@ class WhenTestingRSAContainerValidator(testtools.TestCase):
self.validator = validators.ContainerValidator()
def test_should_validate_all_fields(self):
self.validator.validate(self.container_req)
def test_should_fail_no_names_in_secret_refs(self):
del self.container_req['secret_refs'][0]['name']
@ -783,6 +803,9 @@ class WhenTestingCertificateContainerValidator(testtools.TestCase):
self.validator = validators.ContainerValidator()
def test_should_validate_all_fields(self):
self.validator.validate(self.container_req)
def test_should_fail_more_than_4_secret_refs(self):
new_secret_ref = {
'name': 'new secret ref',
@ -809,5 +832,37 @@ class WhenTestingCertificateContainerValidator(testtools.TestCase):
self.assertEqual('secret_refs', exception.invalid_property)
class WhenTestingTransportKeyValidator(testtools.TestCase):
def setUp(self):
super(WhenTestingTransportKeyValidator, self).setUp()
self.plugin_name = 'name'
self.transport_key = 'abcdef'
self.transport_req = {'plugin_name': self.plugin_name,
'transport_key': self.transport_key}
self.validator = validators.NewTransportKeyValidator()
def test_should_fail_with_invalid_json_data_type(self):
self.assertRaises(
excep.InvalidObject,
self.validator.validate,
[]
)
def test_should_fail_with_empty_transport_key(self):
self.transport_req['transport_key'] = ''
exception = self.assertRaises(
excep.InvalidObject,
self.validator.validate,
self.transport_req
)
self.assertEqual('transport_key', exception.invalid_property)
if __name__ == '__main__':
unittest.main()