Merge "Remove restrictive hard-coded orders validation"

This commit is contained in:
Jenkins 2014-09-24 16:14:45 +00:00 committed by Gerrit Code Review
commit 7a6b2976ad
3 changed files with 51 additions and 102 deletions

View File

@ -308,26 +308,6 @@ class TypeOrderValidator(ValidatorBase):
# Validation secret generation related fields.
# TODO(jfwood): Invoke the crypto plugin for this purpose
if (key_meta.get('payload_content_type', '').lower() !=
'application/octet-stream'):
raise exception.UnsupportedField(field='payload_content_type',
schema=schema_name,
reason=u._("Only 'application/oc"
"tet-stream' "
"supported"))
if key_meta.get('mode', '').lower() != 'cbc':
raise exception.UnsupportedField(field="mode",
schema=schema_name,
reason=u._("Only 'cbc' "
"supported"))
if key_meta.get('algorithm', '').lower() != 'aes':
raise exception.UnsupportedField(field="algorithm",
schema=schema_name,
reason=u._("Only 'aes' "
"supported"))
self._validate_bit_length(key_meta, schema_name)
def _validate_asymmetric_meta(self, asymmetric_meta, schema_name):
@ -430,27 +410,6 @@ class NewOrderValidator(ValidatorBase):
"tet-stream' "
"supported"))
if secret.get('mode', '').lower() != 'cbc':
raise exception.UnsupportedField(field="mode",
schema=schema_name,
reason=u._("Only 'cbc' "
"supported"))
if secret.get('algorithm', '').lower() != 'aes':
raise exception.UnsupportedField(field="algorithm",
schema=schema_name,
reason=u._("Only 'aes' "
"supported"))
# TODO(reaperhulk): Future API change will move from bit to byte_length
bit_length = int(secret.get('bit_length', 1))
if bit_length % 8 != 0:
raise exception.UnsupportedField(field="bit_length",
schema=schema_name,
reason=u._("Must be a positive "
"integer that is a "
"multiple of 8"))
return json_data

View File

@ -1458,24 +1458,9 @@ class WhenCreatingOrdersUsingOrdersResource(FunctionalTest):
order = args[0]
self.assertIsInstance(order, models.Order)
def test_should_raise_add_new_order_no_secret(self):
resp = self.app.post_json(
'/orders/',
{},
expect_errors=True
)
self.assertEqual(resp.status_int, 400)
def test_should_allow_add_new_order_unsupported_algorithm(self):
# TODO(john-wood-w) Allow until plugin validation is added.
def test_should_raise_add_new_order_bad_json(self):
resp = self.app.post(
'/orders/',
'',
expect_errors=True,
headers={'Content-Type': 'application/json'},
)
self.assertEqual(resp.status_int, 400)
def test_should_raise_add_new_order_unsupported_field(self):
# Using unsupported algorithm field for this test
self.unsupported_req = {
'secret': {
@ -1492,6 +1477,23 @@ class WhenCreatingOrdersUsingOrdersResource(FunctionalTest):
expect_errors=True
)
self.assertEqual(resp.status_int, 202)
def test_should_raise_add_new_order_no_secret(self):
resp = self.app.post_json(
'/orders/',
{},
expect_errors=True
)
self.assertEqual(resp.status_int, 400)
def test_should_raise_add_new_order_bad_json(self):
resp = self.app.post(
'/orders/',
'',
expect_errors=True,
headers={'Content-Type': 'application/json'},
)
self.assertEqual(resp.status_int, 400)
def test_should_raise_add_new_order_no_content_type_header(self):

View File

@ -362,6 +362,38 @@ class WhenTestingOrderValidator(utils.BaseTestCase):
self.assertTrue('expiration' in result)
self.assertTrue(not result['expiration'])
def test_should_allow_bad_mode(self):
# TODO(john-wood-w) Allow until plugin validation is added.
self.secret_req['mode'] = 'badmode'
result = self.validator.validate(self.order_req)
self.assertTrue('secret' in result)
def test_should_allow_non_multiple_eight_bit_length(self):
# TODO(john-wood-w) Allow until plugin validation is added.
self.secret_req['bit_length'] = 129
result = self.validator.validate(self.order_req)
self.assertTrue('secret' in result)
def test_should_allow_empty_mode(self):
# TODO(john-wood-w) Allow until plugin validation is added.
del self.secret_req['mode']
result = self.validator.validate(self.order_req)
self.assertTrue('secret' in result)
def test_should_allow_empty_algorithm(self):
# TODO(john-wood-w) Allow until plugin validation is added.
del self.secret_req['algorithm']
result = self.validator.validate(self.order_req)
self.assertTrue('secret' in result)
def test_should_raise_numeric_name(self):
self.secret_req['name'] = 123
@ -373,17 +405,6 @@ class WhenTestingOrderValidator(utils.BaseTestCase):
self.assertEqual('name', exception.invalid_property)
def test_should_raise_bad_mode(self):
self.secret_req['mode'] = 'badmode'
exception = self.assertRaises(
excep.UnsupportedField,
self.validator.validate,
self.order_req,
)
self.assertEqual('mode', exception.invalid_field)
def test_should_raise_negative_bit_length(self):
self.secret_req['bit_length'] = -23
@ -406,17 +427,6 @@ class WhenTestingOrderValidator(utils.BaseTestCase):
self.assertEqual('bit_length', exception.invalid_property)
def test_should_raise_non_multiple_eight_bit_length(self):
self.secret_req['bit_length'] = 129
exception = self.assertRaises(
excep.UnsupportedField,
self.validator.validate,
self.order_req,
)
self.assertEqual('bit_length', exception.invalid_field)
def test_should_raise_secret_not_order_schema_provided(self):
exception = self.assertRaises(
excep.InvalidObject,
@ -503,28 +513,6 @@ class WhenTestingOrderValidator(utils.BaseTestCase):
self.order_req,
)
def test_should_raise_empty_mode(self):
del self.secret_req['mode']
exception = self.assertRaises(
excep.UnsupportedField,
self.validator.validate,
self.order_req,
)
self.assertEqual('mode', exception.invalid_field)
def test_should_raise_empty_algorithm(self):
del self.secret_req['algorithm']
exception = self.assertRaises(
excep.UnsupportedField,
self.validator.validate,
self.order_req,
)
self.assertEqual('algorithm', exception.invalid_field)
def test_should_raise_invalid_json_data_type(self):
self.assertRaises(
excep.InvalidObject,