summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--barbicanclient/exceptions.py22
-rw-r--r--barbicanclient/secrets.py5
-rw-r--r--functionaltests/client/v1/functional/test_secrets.py14
3 files changed, 35 insertions, 6 deletions
diff --git a/barbicanclient/exceptions.py b/barbicanclient/exceptions.py
new file mode 100644
index 0000000..94db9c8
--- /dev/null
+++ b/barbicanclient/exceptions.py
@@ -0,0 +1,22 @@
+# Copyright (c) 2015 Rackspace, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+class BarbicanException(Exception):
+ pass
+
+
+class NoPayloadException(BarbicanException):
+ pass
diff --git a/barbicanclient/secrets.py b/barbicanclient/secrets.py
index fca7dd0..daa9aad 100644
--- a/barbicanclient/secrets.py
+++ b/barbicanclient/secrets.py
@@ -20,6 +20,7 @@ from oslo_utils.timeutils import parse_isotime
import six
from barbicanclient import base
+from barbicanclient import exceptions
from barbicanclient import formatter
@@ -248,6 +249,8 @@ class Secret(SecretFormatter):
"""
Stores the Secret in Barbican. New Secret objects are not persisted
in Barbican until this method is called.
+
+ :raises: NoPayloadException
"""
secret_dict = base.filter_null_keys({
'name': self.name,
@@ -257,6 +260,8 @@ class Secret(SecretFormatter):
'expiration': self.expiration
})
+ if not self.payload:
+ raise exceptions.NoPayloadException
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 552f17a..0966442 100644
--- a/functionaltests/client/v1/functional/test_secrets.py
+++ b/functionaltests/client/v1/functional/test_secrets.py
@@ -20,6 +20,8 @@ from functionaltests.client.v1.behaviors import secret_behaviors
from functionaltests import utils
from testtools import testcase
+from barbicanclient import exceptions
+
secret_create_defaults_data = {
"name": "AES key",
"expiration": "2018-02-28T19:14:44.180394",
@@ -296,7 +298,7 @@ class SecretsTestCase(base.TestCase):
'none': [None],
})
@testcase.attr('negative')
- def test_secret_create_defaults_invalid_payload(self, payload):
+ def test_secret_with_no_payload_exception(self, payload):
"""Covers creating secrets with various invalid payloads.
These requests will fail with a value error before the request to the
@@ -305,11 +307,11 @@ class SecretsTestCase(base.TestCase):
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)
+ self.assertRaises(
+ exceptions.NoPayloadException,
+ self.behaviors.store_secret,
+ test_model
+ )
@utils.parameterized_dataset({
'negative_five_long_expire': {