diff --git a/barbicanclient/exceptions.py b/barbicanclient/exceptions.py index 94db9c83..e032de4f 100644 --- a/barbicanclient/exceptions.py +++ b/barbicanclient/exceptions.py @@ -20,3 +20,7 @@ class BarbicanException(Exception): class NoPayloadException(BarbicanException): pass + + +class InvalidPayloadException(BarbicanException): + pass diff --git a/barbicanclient/secrets.py b/barbicanclient/secrets.py index 0286de0a..0f503173 100644 --- a/barbicanclient/secrets.py +++ b/barbicanclient/secrets.py @@ -251,6 +251,7 @@ class Secret(SecretFormatter): in Barbican until this method is called. :raises: NoPayloadException + :raises: InvalidPayloadException """ secret_dict = { 'name': self.name, @@ -262,6 +263,8 @@ class Secret(SecretFormatter): if not self.payload: raise exceptions.NoPayloadException + if not isinstance(self.payload, (six.text_type, six.binary_type)): + raise exceptions.InvalidPayloadException if self.payload_content_type: """ Setting the payload_content_type and payload_content_encoding diff --git a/functionaltests/client/v1/functional/test_secrets.py b/functionaltests/client/v1/functional/test_secrets.py index 09664421..b1b28cfb 100644 --- a/functionaltests/client/v1/functional/test_secrets.py +++ b/functionaltests/client/v1/functional/test_secrets.py @@ -273,29 +273,29 @@ class SecretsTestCase(base.TestCase): self.assertEqual(test_model.payload, get_resp.payload) @utils.parameterized_dataset({ - 'array': [['boom']], - 'int': [123], - 'zero': [0] + 'list': [['boom']], + 'int': [123] }) @testcase.attr('negative') - def test_secret_create_defaults_invalid_payload_http_err(self, payload): - """Covers creating secrets with various invalid payloads. + def test_secret_create_with_invalid_payload_(self, payload): + """Covers attempting to create secret with invalid payload types - These requests will error with 400 and are will make a request to - the server. + Tests the negative cases of invalid types (list and int). """ test_model = self.behaviors.create_secret( secret_create_defaults_data) test_model.payload = payload - e = self.assertRaises(Exception, self.behaviors.store_secret, - test_model) - - self.assertEqual(e.http_status, 400) + self.assertRaises( + exceptions.InvalidPayloadException, + self.behaviors.store_secret, + test_model + ) @utils.parameterized_dataset({ 'empty': [''], 'none': [None], + 'zero': [0] }) @testcase.attr('negative') def test_secret_with_no_payload_exception(self, payload):