diff --git a/x-pack/plugins/ingest_manager/server/services/epm/archive/index.ts b/x-pack/plugins/ingest_manager/server/services/epm/archive/index.ts index 5a0ecbf987c8f6e..68096b8b10498c2 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/archive/index.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/archive/index.ts @@ -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, diff --git a/x-pack/test/ingest_manager_api_integration/apis/epm/install_by_upload.ts b/x-pack/test/ingest_manager_api_integration/apis/epm/install_by_upload.ts index 89c71dc14dc9548..024af24304d3a17 100644 --- a/x-pack/test/ingest_manager_api_integration/apis/epm/install_by_upload.ts +++ b/x-pack/test/ingest_manager_api_integration/apis/epm/install_by_upload.ts @@ -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' @@ -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); diff --git a/x-pack/test/ingest_manager_api_integration/apis/fixtures/direct_upload_packages/apache_invalid_manifest_missing_field_0.1.4.zip b/x-pack/test/ingest_manager_api_integration/apis/fixtures/direct_upload_packages/apache_invalid_manifest_missing_field_0.1.4.zip new file mode 100644 index 000000000000000..8526f6a53458b6b Binary files /dev/null and b/x-pack/test/ingest_manager_api_integration/apis/fixtures/direct_upload_packages/apache_invalid_manifest_missing_field_0.1.4.zip differ