diff --git a/x-pack/plugins/beats_management/server/lib/adapters/tags/elasticsearch_tags_adapter.ts b/x-pack/plugins/beats_management/server/lib/adapters/tags/elasticsearch_tags_adapter.ts index 78cb19c62701d..e3afa544fa0e1 100644 --- a/x-pack/plugins/beats_management/server/lib/adapters/tags/elasticsearch_tags_adapter.ts +++ b/x-pack/plugins/beats_management/server/lib/adapters/tags/elasticsearch_tags_adapter.ts @@ -106,9 +106,11 @@ export class ElasticsearchTagsAdapter implements CMTagsAdapter { } public async getTagsWithIds(user: FrameworkUser, tagIds: string[]) { + if (tagIds.length === 0) { + return []; + } const ids = tagIds.map(tag => `tag:${tag}`); - // TODO abstract to kibana adapter as the more generic getDocs const params = { _source: true, body: { @@ -142,7 +144,6 @@ export class ElasticsearchTagsAdapter implements CMTagsAdapter { }; const response = await this.database.index(user, params); - // TODO this is not something that works for TS... change this return type return get(response, 'result'); } } diff --git a/x-pack/test/api_integration/apis/beats/get_beat.js b/x-pack/test/api_integration/apis/beats/get_beat.js index 67cb26fc8ad74..67bff4c5727af 100644 --- a/x-pack/test/api_integration/apis/beats/get_beat.js +++ b/x-pack/test/api_integration/apis/beats/get_beat.js @@ -18,6 +18,42 @@ export default function ({ getService }) { beforeEach('load beats archive', () => esArchiver.load(archive)); afterEach('unload beats archive', () => esArchiver.unload(archive)); + it('should return no configurations for the beat without tags', async () => { + await es.index({ + index: ES_INDEX_NAME, + type: ES_TYPE_NAME, + id: `beat:empty`, + body: { + type: 'beat', + beat: { + type: 'filebeat', + active: true, + host_ip: '1.2.3.4', + host_name: 'empty.com', + id: 'empty', + name: 'empty_filebeat', + access_token: + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkIjoiMjAxOC0wNi0zMFQwMzo0MjoxNS4yMzBaIiwiaWF0IjoxNTMwMzMwMTM1fQ.SSsX2Byyo1B1bGxV8C3G4QldhE5iH87EY_1r21-bwbI', // eslint-disable-line + }, + }, + }); + + const { body: apiResponse } = await supertest + .get('/api/beats/agent/empty/configuration') + .set( + 'kbn-beats-access-token', + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.' + + 'eyJjcmVhdGVkIjoiMjAxOC0wNi0zMFQwMzo0MjoxNS4yMzBaIiwiaWF0IjoxNTMwMzMwMTM1fQ.' + + 'SSsX2Byyo1B1bGxV8C3G4QldhE5iH87EY_1r21-bwbI' + ) + .expect(200); + + const configurationBlocks = apiResponse.configuration_blocks; + + expect(configurationBlocks).to.be.an(Array); + expect(configurationBlocks.length).to.be(0); + }); + it('should return merged configuration for the beat', async () => { const { body: apiResponse } = await supertest .get('/api/beats/agent/foo/configuration')