From 8bef6b47a5c6ef5426f118ab63b3ad49559ebefe Mon Sep 17 00:00:00 2001 From: liujiong Date: Sun, 12 Jun 2016 17:36:18 +0800 Subject: [PATCH] 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 --- barbican/plugin/interface/secret_store.py | 6 ++++- .../api/v1/functional/test_orders.py | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/barbican/plugin/interface/secret_store.py b/barbican/plugin/interface/secret_store.py index 80759418c..9df6a9b24 100644 --- a/barbican/plugin/interface/secret_store.py +++ b/barbican/plugin/interface/secret_store.py @@ -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( diff --git a/functionaltests/api/v1/functional/test_orders.py b/functionaltests/api/v1/functional/test_orders.py index 4f6e99ac9..25dcc2925 100644 --- a/functionaltests/api/v1/functional/test_orders.py +++ b/functionaltests/api/v1/functional/test_orders.py @@ -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.