Skip to content

Commit

Permalink
Add API integration test for manifest missing fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
skh committed Sep 24, 2020
1 parent 4b3caaf commit 20b8e70
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ function parseAndVerifyArchive(paths: string[]): ArchivePackage {
// Allow snake case for format_version
// eslint-disable-next-line @typescript-eslint/naming-convention
const { name, version, description, type, categories, format_version } = manifest;
if (!(name && version && description && type && categories && format_version)) {
throw new PackageInvalidArchiveError(
'Invalid top-level package manifest: one or more fields missing of name, version, description, type, categories, format_version'
);
}
return {
name,
version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export default function ({ getService }: FtrProviderContext) {
path.dirname(__filename),
'../fixtures/direct_upload_packages/apache_invalid_manifest_invalid_yaml_0.1.4.zip'
);
const testPkgArchiveInvalidManifestMissingField = path.join(
path.dirname(__filename),
'../fixtures/direct_upload_packages/apache_invalid_manifest_missing_field_0.1.4.zip'
);
const testPkgArchiveInvalidToplevelMismatch = path.join(
path.dirname(__filename),
'../fixtures/direct_upload_packages/apache_invalid_toplevel_mismatch_0.1.4.zip'
Expand Down Expand Up @@ -171,6 +175,23 @@ export default function ({ getService }: FtrProviderContext) {
}
});

it('should throw an error if the archive manifest misses a mandatory field', async function () {
if (server.enabled) {
const buf = fs.readFileSync(testPkgArchiveInvalidManifestMissingField);
const res = await supertest
.post(`/api/ingest_manager/epm/packages`)
.set('kbn-xsrf', 'xxxx')
.type('application/zip')
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Invalid top-level package manifest: one or more fields missing of name, version, description, type, categories, format_version"}'
);
} else {
warnAndSkipTest(this, log);
}
});

it('should throw an error if the toplevel directory name does not match the package key', async function () {
if (server.enabled) {
const buf = fs.readFileSync(testPkgArchiveInvalidToplevelMismatch);
Expand Down
Binary file not shown.

0 comments on commit 20b8e70

Please sign in to comment.