From fdec9e04ad2f2fc27b2cd2ac92a4fa16a3f7f28c Mon Sep 17 00:00:00 2001 From: noa Date: Mon, 17 Aug 2015 13:33:30 +0000 Subject: [PATCH] Fixing support for package download API. Adding "application/octet-stream" to default_accept_types in order to allow calling the package download api with the header "accept"="application/octet-stream". Adding test for the fix, including negative test with bad accept type. Change-Id: I682e312b24183354b62fe10f45c412bf65e4f71e Closes-Bug: #1485480 --- murano/common/wsgi.py | 4 ++- murano/tests/unit/api/base.py | 8 ++++++ murano/tests/unit/api/v1/test_catalog.py | 33 ++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/murano/common/wsgi.py b/murano/common/wsgi.py index ae085567..a6d62d2b 100644 --- a/murano/common/wsgi.py +++ b/murano/common/wsgi.py @@ -291,7 +291,9 @@ class Request(webob.Request): 'application/xml', 'application/murano-packages-json-patch', 'multipart/form-data') - default_accept_types = ('application/json', 'application/xml') + default_accept_types = ('application/json', + 'application/xml', + 'application/octet-stream') def best_match_content_type(self, supported_content_types=None): """Determine the requested response content-type. diff --git a/murano/tests/unit/api/base.py b/murano/tests/unit/api/base.py index 235416a6..3b8ebd0a 100644 --- a/murano/tests/unit/api/base.py +++ b/murano/tests/unit/api/base.py @@ -173,6 +173,14 @@ class ControllerTest(object): return self._simple_request(path, params=params, user=user, tenant=tenant) + def _get_with_accept(self, path, params=None, user=DEFAULT_USER, + tenant=DEFAULT_TENANT, + accept='application/octet-stream'): + req = self._simple_request(path, params=params, user=user, + tenant=tenant) + req.accept = accept + return req + def _delete(self, path, params=None, user=DEFAULT_USER, tenant=DEFAULT_TENANT): params = params or {} diff --git a/murano/tests/unit/api/v1/test_catalog.py b/murano/tests/unit/api/v1/test_catalog.py index bd87c934..652acfc1 100644 --- a/murano/tests/unit/api/v1/test_catalog.py +++ b/murano/tests/unit/api/v1/test_catalog.py @@ -257,6 +257,39 @@ class TestCatalogApi(test_base.ControllerTest, test_base.MuranoApiTestCase): self.assertEqual(imghdr.what('', result), 'png') + def test_download_package(self): + self._set_policy_rules( + {'download_package': '@'} + ) + package_from_dir, package = self._test_package() + + saved_package = db_catalog_api.package_upload(package, '') + + self.expect_policy_check('download_package', + {'package_id': saved_package.id}) + + req = self._get_with_accept('/catalog/packages/%s/download' + % saved_package.id, + accept='application/octet-stream') + + result = req.get_response(self.api) + + self.assertEqual(200, result.status_code) + + def test_download_package_negative(self): + + package_from_dir, package = self._test_package() + + saved_package = db_catalog_api.package_upload(package, '') + + req = self._get_with_accept('/catalog/packages/%s/download' + % saved_package.id, + accept='application/foo') + + result = req.get_response(self.api) + + self.assertEqual(415, result.status_code) + def test_add_public_unauthorized(self): self._set_policy_rules({ 'upload_package': '@',