Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
[BeatsCM] Beats without tags should return an empty array via the con…
Browse files Browse the repository at this point in the history
…fig API (elastic#24665)
  • Loading branch information
mattapperson committed Oct 29, 2018
1 parent 32df0ef commit 621d627
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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');
}
}
36 changes: 36 additions & 0 deletions x-pack/test/api_integration/apis/beats/get_beat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 621d627

Please sign in to comment.