[WIP] Implemented check on range end to fetch artifact
Getting contents of the file instead of 416 error when range end is greater than or equal to size of the file. Added a check for range end while fetching artifact information. If range end is greater than or equal to size of the file then 416 error will be returned in response. Closes-Bug: #1959885 Change-Id: I8dbf7f8407f199350476fc7f093a3cccc78e5030
This commit is contained in:
parent
7b859ab349
commit
1bacc27d4f
|
@ -297,6 +297,13 @@ class VnfPkgmController(wsgi.Controller):
|
|||
"[0, %s].") % (zip_file_size - 1)
|
||||
raise webob.exc.HTTPRequestRangeNotSatisfiable(
|
||||
explanation=msg)
|
||||
if range_.end:
|
||||
if range_.end - 1 >= zip_file_size:
|
||||
msg = _("Invalid end position in Range header. "
|
||||
"End position MUST be in the inclusive range"
|
||||
"[0, %s].") % (zip_file_size - 1)
|
||||
raise webob.exc.HTTPRequestRangeNotSatisfiable(
|
||||
explanation=msg)
|
||||
return range_
|
||||
|
||||
@wsgi.response(http_client.ACCEPTED)
|
||||
|
|
|
@ -465,7 +465,7 @@ class VnfPackageTest(base.BaseTackerTest):
|
|||
zipf.writestr(file_path, data)
|
||||
|
||||
# Partial download 2
|
||||
range_ = 'bytes=11-{}'.format(self.SIZE_CSAR_ZIP)
|
||||
range_ = 'bytes=11-{}'.format(self.SIZE_CSAR_ZIP - 1)
|
||||
headers = {'Range': range_}
|
||||
response_2 = self.http_client.do_request(
|
||||
'{base_path}/{id}/package_content'.format(
|
||||
|
@ -537,3 +537,44 @@ class VnfPackageTest(base.BaseTackerTest):
|
|||
image_path = body[0]['softwareImages'][0]['imagePath']
|
||||
expected_result = self.package2.get('softwareImages')[0]['imagePath']
|
||||
self.assertEqual(image_path, expected_result)
|
||||
|
||||
def test_fetch_vnf_package_artifacts_range_exception(self):
|
||||
# test for response status code 416 when
|
||||
# range start greater than range end
|
||||
range_ = 'bytes=9-8'
|
||||
# get headers
|
||||
headers = {'Range': range_}
|
||||
# request download api
|
||||
response = self.http_client.do_request(
|
||||
'{base_path}/{id}/artifacts/{artifact_path}'.format(
|
||||
base_path=self.base_url, id=self.package_id1,
|
||||
artifact_path='Scripts/install.sh'),
|
||||
"GET", body={}, headers=headers)
|
||||
# verification
|
||||
self.assertEqual(416, response[0].status_code)
|
||||
|
||||
# range end greater than or equal to size of the file
|
||||
range_ = 'bytes=0-33'
|
||||
# get headers
|
||||
headers = {'Range': range_}
|
||||
# request download api
|
||||
response = self.http_client.do_request(
|
||||
'{base_path}/{id}/artifacts/{artifact_path}'.format(
|
||||
base_path=self.base_url, id=self.package_id1,
|
||||
artifact_path='Scripts/install.sh'),
|
||||
"GET", body={}, headers=headers)
|
||||
# verification
|
||||
self.assertEqual(416, response[0].status_code)
|
||||
|
||||
# range start greater than size of the file
|
||||
range_ = 'bytes=33-'
|
||||
# get headers
|
||||
headers = {'Range': range_}
|
||||
# request download api
|
||||
response = self.http_client.do_request(
|
||||
'{base_path}/{id}/artifacts/{artifact_path}'.format(
|
||||
base_path=self.base_url, id=self.package_id1,
|
||||
artifact_path='Scripts/install.sh'),
|
||||
"GET", body={}, headers=headers)
|
||||
# verification
|
||||
self.assertEqual(416, response[0].status_code)
|
||||
|
|
|
@ -1016,6 +1016,14 @@ class TestController(base.TestCase):
|
|||
self.assertRaises(exc.HTTPRequestRangeNotSatisfiable,
|
||||
self.controller._get_range_from_request,
|
||||
request, 120)
|
||||
request.headers["Range"] = 'bytes=110-100'
|
||||
self.assertRaises(exc.HTTPRequestRangeNotSatisfiable,
|
||||
self.controller._get_range_from_request,
|
||||
request, 120)
|
||||
request.headers["Range"] = 'bytes=100-120'
|
||||
self.assertRaises(exc.HTTPRequestRangeNotSatisfiable,
|
||||
self.controller._get_range_from_request,
|
||||
request, 120)
|
||||
|
||||
def test_fetch_vnf_package_content_invalid_multiple_range(self):
|
||||
request = fake_request.HTTPRequest.blank(
|
||||
|
|
Loading…
Reference in New Issue