From 7bf18c42287220a7d60400745d111bef00a62b8f Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Wed, 27 May 2020 16:15:09 -0400 Subject: [PATCH] [Ingest Manager] Do not allow empty namespace (#67492) (#67532) --- .../list_page/components/create_config.tsx | 7 ++- .../server/types/models/agent_config.ts | 2 +- .../server/types/models/datasource.ts | 2 +- x-pack/test/api_integration/apis/index.js | 2 +- .../api_integration/apis/ingest/policies.ts | 59 ------------------- .../apis/ingest_manager/agent_config.ts | 40 +++++++++++++ .../apis/{ingest => ingest_manager}/index.js | 4 +- 7 files changed, 49 insertions(+), 67 deletions(-) delete mode 100644 x-pack/test/api_integration/apis/ingest/policies.ts create mode 100644 x-pack/test/api_integration/apis/ingest_manager/agent_config.ts rename x-pack/test/api_integration/apis/{ingest => ingest_manager}/index.js (75%) diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/list_page/components/create_config.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/list_page/components/create_config.tsx index 349ebe1151c80..f746fadc4b0a3 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/list_page/components/create_config.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/list_page/components/create_config.tsx @@ -32,7 +32,7 @@ export const CreateAgentConfigFlyout: React.FunctionComponent = ({ onClos const [agentConfig, setAgentConfig] = useState({ name: '', description: '', - namespace: '', + namespace: 'default', is_default: undefined, monitoring_enabled: ['logs', 'metrics'], }); @@ -102,6 +102,7 @@ export const CreateAgentConfigFlyout: React.FunctionComponent = ({ onClos setIsLoading(true); try { const { data, error } = await createAgentConfig(); + setIsLoading(false); if (data?.success) { notifications.toasts.addSuccess( i18n.translate( @@ -112,6 +113,7 @@ export const CreateAgentConfigFlyout: React.FunctionComponent = ({ onClos } ) ); + onClose(); } else { notifications.toasts.addDanger( error @@ -125,14 +127,13 @@ export const CreateAgentConfigFlyout: React.FunctionComponent = ({ onClos ); } } catch (e) { + setIsLoading(false); notifications.toasts.addDanger( i18n.translate('xpack.ingestManager.createAgentConfig.errorNotificationTitle', { defaultMessage: 'Unable to create agent config', }) ); } - setIsLoading(false); - onClose(); }} > { - await esArchiver.loadIfNeeded('ingest/policies'); - }); - after(async () => { - await esArchiver.unload('ingest/policies'); - }); - } - - describe.skip('ingest_policies', () => { - describe('POST /api/ingest/policies', () => { - useFixtures(); - - it('should return a 400 if the request is not valid', async () => { - await supertest.post(`/api/ingest/policies`).set('kbn-xsrf', 'xxx').send({}).expect(400); - }); - - it('should allow to create a new policy', async () => { - const { body: apiResponse } = await supertest - .post(`/api/ingest/policies`) - .set('kbn-xsrf', 'xxx') - .send({ - name: 'Policy from test 1', - description: 'I am a policy', - }) - .expect(200); - - expect(apiResponse.success).to.eql(true); - expect(apiResponse).to.have.keys('success', 'item', 'action'); - expect(apiResponse.item).to.have.keys('id', 'name', 'status', 'description'); - }); - }); - describe('GET /api/ingest/policies', () => { - useFixtures(); - it('should return the list of policies grouped by shared id', async () => { - const { body: apiResponse } = await supertest.get(`/api/ingest/policies`).expect(200); - expect(apiResponse).to.have.keys('success', 'page', 'total', 'list'); - expect(apiResponse.success).to.eql(true); - const policiesIds = (apiResponse.list as Array<{ id: string }>).map((i) => i.id); - expect(policiesIds.length).to.eql(3); - expect(policiesIds).to.contain('1'); - expect(policiesIds).to.contain('3'); - }); - }); - }); -} diff --git a/x-pack/test/api_integration/apis/ingest_manager/agent_config.ts b/x-pack/test/api_integration/apis/ingest_manager/agent_config.ts new file mode 100644 index 0000000000000..7281e6a06a064 --- /dev/null +++ b/x-pack/test/api_integration/apis/ingest_manager/agent_config.ts @@ -0,0 +1,40 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('ingest_manager_agent_configs', () => { + describe('POST /api/ingest_manager/agent_configs', () => { + it('should work with valid values', async () => { + const { body: apiResponse } = await supertest + .post(`/api/ingest_manager/agent_configs`) + .set('kbn-xsrf', 'xxxx') + .send({ + name: 'TEST', + namespace: 'default', + }) + .expect(200); + + expect(apiResponse.success).to.be(true); + }); + + it('should return a 400 with an invalid namespace', async () => { + await supertest + .post(`/api/ingest_manager/agent_configs`) + .set('kbn-xsrf', 'xxxx') + .send({ + name: 'TEST', + namespace: '', + }) + .expect(400); + }); + }); + }); +} diff --git a/x-pack/test/api_integration/apis/ingest/index.js b/x-pack/test/api_integration/apis/ingest_manager/index.js similarity index 75% rename from x-pack/test/api_integration/apis/ingest/index.js rename to x-pack/test/api_integration/apis/ingest_manager/index.js index 5dac999a86167..1671c423c03c0 100644 --- a/x-pack/test/api_integration/apis/ingest/index.js +++ b/x-pack/test/api_integration/apis/ingest_manager/index.js @@ -5,7 +5,7 @@ */ export default function loadTests({ loadTestFile }) { - describe('Ingest Endpoints', () => { - loadTestFile(require.resolve('./policies')); + describe('Ingest Manager Endpoints', () => { + loadTestFile(require.resolve('./agent_config')); }); }