Change SecretAcceptNotSupportedException from exception.BarbicanException to exception.BarbicanHTTPException

When retrieving secret's payload without providing payload_content_type,
if the payload_content_type is not default as "text/plain", we get 500 error.
Since this is generated by invalid input, we should mark this as 406 error.

Closes-bug: #1590097
Change-Id: I9ca94b7c66995991a9b0df37a46bd082e9795b74
This commit is contained in:
liujiong 2016-06-12 17:36:18 +08:00
parent 29e7356c9d
commit 8bef6b47a5
2 changed files with 30 additions and 1 deletions

View File

@ -153,8 +153,12 @@ class SecretPayloadDecodingError(exception.BarbicanHTTPException):
)
class SecretAcceptNotSupportedException(exception.BarbicanException):
class SecretAcceptNotSupportedException(exception.BarbicanHTTPException):
"""Raised when requested decrypted content-type is not available."""
client_message = u._("Wrong payload content-type")
status_code = 406
def __init__(self, accept):
super(SecretAcceptNotSupportedException, self).__init__(
u._("Secret Accept of '{accept}' not supported").format(

View File

@ -157,6 +157,31 @@ class OrdersTestCase(base.TestCase):
self.assertEqual(secret_resp.status_code, 200)
self.assertEqual(secret_resp.model.name, test_model.meta['name'])
@testcase.attr('negative')
def test_order_create_check_secret_payload(self):
"""Create order and check the secret payload.
Check the secret payload with wrong payload_content_type.
Should return a 406.
"""
test_model = order_models.OrderModel(**self.create_default_data)
resp, order_ref = self.behaviors.create_order(test_model)
self.assertEqual(resp.status_code, 202)
order_resp = self.behaviors.get_order(order_ref)
self.assertEqual(order_resp.status_code, 200)
# PENDING orders may take a moment to be processed by the workers
# when running tests with queue enabled
self.wait_for_order(order_resp, order_ref)
secret_ref = order_resp.model.secret_ref
secret_resp = self.secret_behaviors.get_secret(
secret_ref, payload_content_type="text/plain")
self.assertEqual(secret_resp.status_code, 406)
@testcase.attr('positive')
def test_order_and_secret_metadata_same(self):
"""Checks that metadata from secret GET and order GET are the same.