validate folder data before saving it in database
Change-Id: I9c7de8be1b4d9ec65f71131f5a7decd0433d75ae closes-bug: #1799220
This commit is contained in:
parent
63f663b760
commit
0b3583af22
|
@ -83,6 +83,7 @@ def unpack_zip_archive_to_artifact_folder(context, af, zip_ref, folder_name):
|
|||
file_dict[name] = blob
|
||||
blobs.append((blob_id, utils.BlobIterator(zip_ref.read(name))))
|
||||
|
||||
setattr(af, folder_name, file_dict)
|
||||
af = af.update_blob(context, af.id, folder_name, file_dict)
|
||||
|
||||
default_store = getattr(
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
import os
|
||||
from time import time
|
||||
|
||||
from glare.common.exception import BadRequest
|
||||
from glare.tests.unit import base
|
||||
|
||||
|
||||
|
@ -65,7 +66,7 @@ class TestArtifactHooks(base.BaseTestArtifactAPI):
|
|||
|
||||
artifact = self.controller.show(self.req, 'unpacking_artifact',
|
||||
self.unpacking_artifact['id'])
|
||||
self.assertEqual(15702, artifact['zip']['size'])
|
||||
self.assertEqual(100, len(artifact['content']))
|
||||
self.assertEqual('active', artifact['zip']['status'])
|
||||
|
||||
self.assertEqual(100, len(artifact['content']))
|
||||
|
@ -74,6 +75,19 @@ class TestArtifactHooks(base.BaseTestArtifactAPI):
|
|||
self.assertEqual('active', blob['status'])
|
||||
self.assertEqual(15, blob['size'])
|
||||
|
||||
def test_unpacking_more_than_max_size_archive(self):
|
||||
var_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
||||
'../', 'var'))
|
||||
data_path = os.path.join(var_dir, 'hooks_265.zip')
|
||||
with open(data_path, "rb") as data:
|
||||
self.assertRaises(BadRequest, self.controller.upload_blob,
|
||||
self.req, 'unpacking_artifact',
|
||||
self.unpacking_artifact['id'], 'zip',
|
||||
data, 'application/octet-stream')
|
||||
artifact = self.controller.show(self.req, 'unpacking_artifact',
|
||||
self.unpacking_artifact['id'])
|
||||
self.assertEqual(0, len(artifact['content']))
|
||||
|
||||
def test_unpacking_database_big_archive(self):
|
||||
self.config(default_store='database',
|
||||
group='artifact_type:unpacking_artifact')
|
||||
|
|
Loading…
Reference in New Issue