From 5e1e8b02aa03bff82119a287abd2a6d6236ad130 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 18 Oct 2024 06:19:26 +1100 Subject: [PATCH] [8.16] [Ingest Pipelines] Improve api integration tests (#196718) (#196749) # Backport This will backport the following commits from `main` to `8.16`: - [[Ingest Pipelines] Improve api integration tests (#196718)](https://github.com/elastic/kibana/pull/196718) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Elena Stoeva <59341489+ElenaStoeva@users.noreply.github.com> --- .../api_integration/apis/management/index.js | 1 + .../management/ingest_pipelines/databases.ts | 52 +++++++++++++++---- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/x-pack/test/api_integration/apis/management/index.js b/x-pack/test/api_integration/apis/management/index.js index d8a9ed76dd2f9..852348d8d243f 100644 --- a/x-pack/test/api_integration/apis/management/index.js +++ b/x-pack/test/api_integration/apis/management/index.js @@ -14,5 +14,6 @@ export default function ({ loadTestFile }) { loadTestFile(require.resolve('./index_management')); loadTestFile(require.resolve('./index_lifecycle_management')); loadTestFile(require.resolve('./snapshot_restore')); + loadTestFile(require.resolve('./ingest_pipelines')); }); } diff --git a/x-pack/test/api_integration/apis/management/ingest_pipelines/databases.ts b/x-pack/test/api_integration/apis/management/ingest_pipelines/databases.ts index 93a7ccc7d4088..3f1975cca3bc1 100644 --- a/x-pack/test/api_integration/apis/management/ingest_pipelines/databases.ts +++ b/x-pack/test/api_integration/apis/management/ingest_pipelines/databases.ts @@ -13,8 +13,10 @@ export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const ingestPipelines = getService('ingestPipelines'); const url = `/api/ingest_pipelines/databases`; - const databaseName = 'GeoIP2-Anonymous-IP'; - const normalizedDatabaseName = 'geoip2-anonymous-ip'; + const maxmindDatabaseName = 'GeoIP2-Anonymous-IP'; + const normalizedMaxmindDatabaseName = 'geoip2-anonymous-ip'; + const ipinfoDatabaseName = 'asn'; + const normalizedIpinfoDatabaseName = 'asn'; describe('Manage databases', function () { after(async () => { @@ -22,8 +24,12 @@ export default function ({ getService }: FtrProviderContext) { }); describe('Create', () => { - it('creates a geoip database when using a correct database name', async () => { - const database = { maxmind: '123456', databaseName }; + it('creates a maxmind geoip database when using a correct database name', async () => { + const database = { + databaseType: 'maxmind', + databaseName: maxmindDatabaseName, + maxmind: '123456', + }; const { body } = await supertest .post(url) .set('kbn-xsrf', 'xxx') @@ -31,13 +37,27 @@ export default function ({ getService }: FtrProviderContext) { .expect(200); expect(body).to.eql({ - name: databaseName, - id: normalizedDatabaseName, + name: maxmindDatabaseName, + id: normalizedMaxmindDatabaseName, }); }); - it('creates a geoip database when using an incorrect database name', async () => { - const database = { maxmind: '123456', databaseName: 'Test' }; + it('creates an ipinfo geoip database when using a correct database name', async () => { + const database = { databaseType: 'ipinfo', databaseName: ipinfoDatabaseName }; + const { body } = await supertest + .post(url) + .set('kbn-xsrf', 'xxx') + .send(database) + .expect(200); + + expect(body).to.eql({ + name: ipinfoDatabaseName, + id: normalizedIpinfoDatabaseName, + }); + }); + + it('returns error when creating a geoip database with an incorrect database name', async () => { + const database = { databaseType: 'maxmind', databaseName: 'Test', maxmind: '123456' }; await supertest.post(url).set('kbn-xsrf', 'xxx').send(database).expect(400); }); }); @@ -47,8 +67,13 @@ export default function ({ getService }: FtrProviderContext) { const { body } = await supertest.get(url).set('kbn-xsrf', 'xxx').expect(200); expect(body).to.eql([ { - id: normalizedDatabaseName, - name: databaseName, + id: normalizedIpinfoDatabaseName, + name: ipinfoDatabaseName, + type: 'ipinfo', + }, + { + id: normalizedMaxmindDatabaseName, + name: maxmindDatabaseName, type: 'maxmind', }, ]); @@ -58,7 +83,12 @@ export default function ({ getService }: FtrProviderContext) { describe('Delete', () => { it('deletes a geoip database', async () => { await supertest - .delete(`${url}/${normalizedDatabaseName}`) + .delete(`${url}/${normalizedMaxmindDatabaseName}`) + .set('kbn-xsrf', 'xxx') + .expect(200); + + await supertest + .delete(`${url}/${normalizedIpinfoDatabaseName}`) .set('kbn-xsrf', 'xxx') .expect(200); });