From 17ed50a9f960bbbabfae194a27f5ad076958248c Mon Sep 17 00:00:00 2001 From: Fernando Diaz Date: Wed, 12 Aug 2015 13:10:48 -0500 Subject: [PATCH] Add Unit Tests for Store and Update Payload when Payload is zero Adds Unit Tests for storing and updating a payload that is set to zero. Also updated an exception to give more info. Change-Id: I5a4224b3a10ea64492b57cc6d2c3a5da53f55383 --- barbicanclient/secrets.py | 2 +- barbicanclient/tests/test_secrets.py | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/barbicanclient/secrets.py b/barbicanclient/secrets.py index 2ed41d75..a8f5a4e5 100644 --- a/barbicanclient/secrets.py +++ b/barbicanclient/secrets.py @@ -336,7 +336,7 @@ class Secret(SecretFormatter): """ if not self.payload: - raise exceptions.PayloadException("Missing Payload") + raise exceptions.PayloadException("Invalid or Missing Payload") if not self.secret_ref: raise LookupError("Secret is not yet stored.") diff --git a/barbicanclient/tests/test_secrets.py b/barbicanclient/tests/test_secrets.py index 91beb8b0..4df946e3 100644 --- a/barbicanclient/tests/test_secrets.py +++ b/barbicanclient/tests/test_secrets.py @@ -18,7 +18,7 @@ import json from oslo_utils import timeutils from barbicanclient.tests import test_client -from barbicanclient import secrets, base +from barbicanclient import secrets, base, exceptions class SecretData(object): @@ -417,6 +417,30 @@ class WhenTestingSecrets(test_client.BaseEntityResource): self.assertRaises(ValueError, self.manager.get, **{'secret_ref': '12345'}) + def test_should_fail_update_zero(self): + data = {'secret_ref': self.entity_href} + self.responses.post(self.entity_base + '/', json=data) + + secret = self.manager.create() + secret.payload = None + secret.store() + + self.responses.put(self.entity_href, status_code=204) + secret.payload = 0 + + # Verify that an error is thrown + self.assertRaises(exceptions.PayloadException, secret.update) + + def test_should_fail_store_zero(self): + data = {'secret_ref': self.entity_href} + self.responses.post(self.entity_base + '/', json=data) + + secret = self.manager.create() + secret.name = self.secret.name + secret.payload = 0 + + self.assertRaises(exceptions.PayloadException, secret.store) + def test_should_fail_decrypt_no_content_types(self): data = self.secret.get_dict(self.entity_href) self.responses.get(self.entity_href, json=data)