application: missing manifest in bundle on install (#88069)
gitea/hobo/pipeline/head This commit looks good Details

This commit is contained in:
Lauréline Guérin 2024-03-14 09:41:45 +01:00
parent 159f93a783
commit faa2ccce75
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 21 additions and 1 deletions

View File

@ -456,7 +456,11 @@ class Install(FormView):
tar_io = io.BytesIO(self.request.FILES['bundle'].read())
try:
with tarfile.open(fileobj=tar_io) as tar:
manifest = json.loads(tar.extractfile('manifest.json').read().decode())
try:
manifest = json.loads(tar.extractfile('manifest.json').read().decode())
except KeyError:
form.add_error('bundle', _('Invalid tar file, missing manifest.'))
return self.form_invalid(form)
if self.application and self.application.slug != manifest.get('slug'):
form.add_error(
'bundle',

View File

@ -1182,6 +1182,22 @@ def test_deploy_application(app, admin_user, settings, app_bundle, app_bundle_wi
resp = resp.form.submit()
assert resp.context['form'].errors == {'bundle': ['Invalid tar file.']}
# missing manifest
tar_io = io.BytesIO()
with tarfile.open(mode='w', fileobj=tar_io) as tar:
foo_fd = io.BytesIO(json.dumps({'foo': 'bar'}, indent=2).encode())
tarinfo = tarfile.TarInfo('foo.json')
tarinfo.size = len(foo_fd.getvalue())
tar.addfile(tarinfo, fileobj=foo_fd)
resp = app.get('/applications/')
if action == 'Update':
with StatefulHTTMock(mocked_http2):
resp = resp.click(href='manifest/test/')
resp = resp.click(action)
resp.form['bundle'] = Upload('app.tar', tar_io.getvalue(), 'application/x-tar')
resp = resp.form.submit()
assert resp.context['form'].errors == {'bundle': ['Invalid tar file, missing manifest.']}
def test_update_application(app, admin_user, settings, app_bundle):
Wcs.objects.create(base_url='https://wcs.example.invalid', slug='foobar', title='Foobar')