diff options
author | Thomas Dinkjian <thomas.dinkjian@rackspace.com> | 2015-03-09 15:39:52 -0500 |
---|---|---|
committer | Thomas Dinkjian <thomas.dinkjian@rackspace.com> | 2015-03-10 14:50:53 -0500 |
commit | 92b53a749d6d363b51271a796d24d6f9642d1b91 (patch) | |
tree | 56247d296aedfdfb63c5ae1bf759e67c3ec76c12 | |
parent | f48efbdf5302c59b401f64ca5c46665a3093bb6a (diff) | |
download | python-barbicanclient-92b53a749d6d363b51271a796d24d6f9642d1b91.tar.gz |
Fix when submitting with empty string, none and zero
Changes the way barbican client handles empty, none and zero.
The client will now provide an error when trying to store
an empty string or none payload. All other invalid payloads
such as zero, int and array will return a 400 http code.
Also added the negative tests that test this change.
Change-Id: Icdef89b9171a6a95e16ab303fc4af118fc618255
-rw-r--r-- | barbicanclient/secrets.py | 2 | ||||
-rw-r--r-- | functionaltests/client/v1/functional/test_secrets.py | 41 |
2 files changed, 42 insertions, 1 deletions
diff --git a/barbicanclient/secrets.py b/barbicanclient/secrets.py index 10ce54e..9107bb7 100644 --- a/barbicanclient/secrets.py +++ b/barbicanclient/secrets.py @@ -172,7 +172,7 @@ class Secret(SecretFormatter): """ Lazy-loaded property that holds the unencrypted data """ - if not self._payload: + if self._payload is None: self._fetch_payload() return self._payload diff --git a/functionaltests/client/v1/functional/test_secrets.py b/functionaltests/client/v1/functional/test_secrets.py index 4a32d54..75f44d8 100644 --- a/functionaltests/client/v1/functional/test_secrets.py +++ b/functionaltests/client/v1/functional/test_secrets.py @@ -245,6 +245,47 @@ class SecretsTestCase(base.TestCase): str(base64.b64encode(get_resp.payload))) @utils.parameterized_dataset({ + 'array': [['boom']], + 'int': [123], + 'zero': [0] + }) + @testcase.attr('negative') + def test_secret_create_defaults_invalid_payload_http_err(self, payload): + """Covers creating secrets with various invalid payloads. + + These requests will error with 400 and are will make a request to + the server. + """ + 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) + + @utils.parameterized_dataset({ + 'empty': [''], + 'none': [None], + }) + @testcase.attr('negative') + def test_secret_create_defaults_invalid_payload(self, payload): + """Covers creating secrets with various invalid payloads. + + These requests will fail with a value error before the request to the + server is made""" + test_model = self.behaviors.create_secret( + secret_create_defaults_data) + test_model.payload = payload + + e = self.assertRaises(ValueError, self.behaviors.store_secret, + test_model) + + self.assertIn('Payload incorrectly specified.', + e.message) + + @utils.parameterized_dataset({ 'negative_five_long_expire': { 'timezone': '-05:00', 'days': 5}, |