mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14:03 +03:00
Fixed handling empty zip file uploads
fix https://linear.app/tryghost/issue/SLO-102/end-of-central-directory-record-signature-not-found-an-unexpected - previously, uploading an empty zip would result in a HTTP 500 error because yauzl would error and we'd bubble that up as an InternalServerError - now, we catch the specific error message and return a more user friendly error - also includes tests and sample zip file
This commit is contained in:
parent
00f42855e3
commit
e8e3447f15
@ -235,6 +235,11 @@ class ImportManager {
|
||||
help: tpl(messages.invalidZipFileNameEncodingHelp),
|
||||
code: 'INVALID_ZIP_FILE_NAME_ENCODING'
|
||||
});
|
||||
} else if (err.message.includes('end of central directory record signature not found')) { // This comes from Yauzl when the zip is invalid
|
||||
throw new errors.UnsupportedMediaTypeError({
|
||||
message: tpl(messages.invalidZipFileNameEncoding),
|
||||
code: 'INVALID_ZIP_FILE'
|
||||
});
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
@ -103,4 +103,14 @@ describe('DB API', function () {
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
it('Handles invalid zip file uploads', async function () {
|
||||
const res = await request.post(localUtils.API.getApiQuery('db/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.attach('importfile', 'test/utils/fixtures/import/zips/empty.zip')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(415);
|
||||
|
||||
res.body.errors[0].message.should.eql('The uploaded zip could not be read');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user