Skip to content

Commit

Permalink
[Ingest Pipelines] Improve api integration tests (#196718)
Browse files Browse the repository at this point in the history
Follow-up to #190830

## Summary

I noticed that the api integration tests that have been added with
#190830 were not actually included
to run as part of the Management test suite. This PR adds them and it
also adds some test cases for the `ipinfo` database type.

(cherry picked from commit 727c19a)
  • Loading branch information
ElenaStoeva committed Oct 17, 2024
1 parent 4105d35 commit 1fc9421
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
1 change: 1 addition & 0 deletions x-pack/test/api_integration/apis/management/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,51 @@ 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 () => {
await ingestPipelines.api.deleteGeoipDatabases();
});

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')
.send(database)
.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);
});
});
Expand All @@ -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',
},
]);
Expand All @@ -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);
});
Expand Down

0 comments on commit 1fc9421

Please sign in to comment.