summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Dinkjian <thomas.dinkjian@rackspace.com>2015-03-09 15:39:52 -0500
committerThomas Dinkjian <thomas.dinkjian@rackspace.com>2015-03-10 14:50:53 -0500
commit92b53a749d6d363b51271a796d24d6f9642d1b91 (patch)
tree56247d296aedfdfb63c5ae1bf759e67c3ec76c12
parentf48efbdf5302c59b401f64ca5c46665a3093bb6a (diff)
downloadpython-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.py2
-rw-r--r--functionaltests/client/v1/functional/test_secrets.py41
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},