-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add spaces only tests * Rename some tests to make more sense in spaces only context * Modify test suite titles * Apply changes from master * Loop only one scenario for now * Reduce amount of tests spaces_only runs * Fix failing test * Remove looping in spaces only tests
- Loading branch information
Showing
25 changed files
with
1,494 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
x-pack/test/alerting_api_integration/spaces_only/config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* 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 { createTestConfig } from '../common/config'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default createTestConfig('spaces_only', { disabledPlugins: ['security'], license: 'basic' }); |
17 changes: 17 additions & 0 deletions
17
x-pack/test/alerting_api_integration/spaces_only/scenarios.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* 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 { Space } from '../common/types'; | ||
|
||
const Space1: Space = { | ||
id: 'space1', | ||
name: 'Space 1', | ||
disabledFeatures: [], | ||
}; | ||
|
||
export const Spaces = { | ||
space1: Space1, | ||
}; |
133 changes: 133 additions & 0 deletions
133
.../test/alerting_api_integration/spaces_only/tests/actions/builtin_action_types/es_index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* 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 '../../../../common/ftr_provider_context'; | ||
|
||
const ES_TEST_INDEX_NAME = 'functional-test-actions-index'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default function indexTest({ getService }: FtrProviderContext) { | ||
const es = getService('es'); | ||
const supertest = getService('supertest'); | ||
const esArchiver = getService('esArchiver'); | ||
|
||
describe('index action', () => { | ||
after(() => esArchiver.unload('empty_kibana')); | ||
beforeEach(() => clearTestIndex(es)); | ||
|
||
let createdActionID: string; | ||
let createdActionIDWithIndex: string; | ||
|
||
it('should be created successfully', async () => { | ||
// create action with no config | ||
const { body: createdAction } = await supertest | ||
.post('/api/action') | ||
.set('kbn-xsrf', 'foo') | ||
.send({ | ||
description: 'An index action', | ||
actionTypeId: '.index', | ||
config: {}, | ||
secrets: {}, | ||
}) | ||
.expect(200); | ||
|
||
expect(createdAction).to.eql({ | ||
id: createdAction.id, | ||
description: 'An index action', | ||
actionTypeId: '.index', | ||
config: { | ||
index: null, | ||
}, | ||
}); | ||
createdActionID = createdAction.id; | ||
expect(typeof createdActionID).to.be('string'); | ||
|
||
const { body: fetchedAction } = await supertest | ||
.get(`/api/action/${createdActionID}`) | ||
.expect(200); | ||
|
||
expect(fetchedAction).to.eql({ | ||
id: fetchedAction.id, | ||
description: 'An index action', | ||
actionTypeId: '.index', | ||
config: { index: null }, | ||
}); | ||
|
||
// create action with index config | ||
const { body: createdActionWithIndex } = await supertest | ||
.post('/api/action') | ||
.set('kbn-xsrf', 'foo') | ||
.send({ | ||
description: 'An index action with index config', | ||
actionTypeId: '.index', | ||
config: { | ||
index: ES_TEST_INDEX_NAME, | ||
}, | ||
}) | ||
.expect(200); | ||
|
||
expect(createdActionWithIndex).to.eql({ | ||
id: createdActionWithIndex.id, | ||
description: 'An index action with index config', | ||
actionTypeId: '.index', | ||
config: { | ||
index: ES_TEST_INDEX_NAME, | ||
}, | ||
}); | ||
createdActionIDWithIndex = createdActionWithIndex.id; | ||
expect(typeof createdActionIDWithIndex).to.be('string'); | ||
|
||
const { body: fetchedActionWithIndex } = await supertest | ||
.get(`/api/action/${createdActionIDWithIndex}`) | ||
.expect(200); | ||
|
||
expect(fetchedActionWithIndex).to.eql({ | ||
id: fetchedActionWithIndex.id, | ||
description: 'An index action with index config', | ||
actionTypeId: '.index', | ||
config: { | ||
index: ES_TEST_INDEX_NAME, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should execute successly when expected for a single body', async () => { | ||
const { body: result } = await supertest | ||
.post(`/api/action/${createdActionID}/_execute`) | ||
.set('kbn-xsrf', 'foo') | ||
.send({ | ||
params: { | ||
index: ES_TEST_INDEX_NAME, | ||
documents: [{ testing: [1, 2, 3] }], | ||
refresh: true, | ||
}, | ||
}) | ||
.expect(200); | ||
expect(result.status).to.eql('ok'); | ||
|
||
const items = await getTestIndexItems(es); | ||
expect(items.length).to.eql(1); | ||
expect(items[0]._source).to.eql({ testing: [1, 2, 3] }); | ||
}); | ||
}); | ||
} | ||
|
||
async function clearTestIndex(es: any) { | ||
return await es.indices.delete({ | ||
index: ES_TEST_INDEX_NAME, | ||
ignoreUnavailable: true, | ||
}); | ||
} | ||
|
||
async function getTestIndexItems(es: any) { | ||
const result = await es.search({ | ||
index: ES_TEST_INDEX_NAME, | ||
}); | ||
|
||
return result.hits.hits; | ||
} |
49 changes: 49 additions & 0 deletions
49
x-pack/test/alerting_api_integration/spaces_only/tests/actions/create.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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 { Spaces } from '../../scenarios'; | ||
import { getUrlPrefix, ObjectRemover } from '../../../common/lib'; | ||
import { FtrProviderContext } from '../../../common/ftr_provider_context'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default function createActionTests({ getService }: FtrProviderContext) { | ||
const supertest = getService('supertest'); | ||
|
||
describe('create', () => { | ||
const objectRemover = new ObjectRemover(supertest); | ||
|
||
after(() => objectRemover.removeAll()); | ||
|
||
it('should handle create action request appropriately', async () => { | ||
const response = await supertest | ||
.post(`${getUrlPrefix(Spaces.space1.id)}/api/action`) | ||
.set('kbn-xsrf', 'foo') | ||
.send({ | ||
description: 'My action', | ||
actionTypeId: 'test.index-record', | ||
config: { | ||
unencrypted: `This value shouldn't get encrypted`, | ||
}, | ||
secrets: { | ||
encrypted: 'This value should be encrypted', | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).to.eql(200); | ||
expect(response.body).to.eql({ | ||
id: response.body.id, | ||
description: 'My action', | ||
actionTypeId: 'test.index-record', | ||
config: { | ||
unencrypted: `This value shouldn't get encrypted`, | ||
}, | ||
}); | ||
expect(typeof response.body.id).to.be('string'); | ||
objectRemover.add(Spaces.space1.id, response.body.id, 'action'); | ||
}); | ||
}); | ||
} |
53 changes: 53 additions & 0 deletions
53
x-pack/test/alerting_api_integration/spaces_only/tests/actions/delete.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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 { Spaces } from '../../scenarios'; | ||
import { getUrlPrefix, ObjectRemover } from '../../../common/lib'; | ||
import { FtrProviderContext } from '../../../common/ftr_provider_context'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default function deleteActionTests({ getService }: FtrProviderContext) { | ||
const supertest = getService('supertest'); | ||
|
||
describe('delete', () => { | ||
const objectRemover = new ObjectRemover(supertest); | ||
|
||
after(() => objectRemover.removeAll()); | ||
|
||
it('should handle delete action request appropriately', async () => { | ||
const { body: createdAction } = await supertest | ||
.post(`${getUrlPrefix(Spaces.space1.id)}/api/action`) | ||
.set('kbn-xsrf', 'foo') | ||
.send({ | ||
description: 'My action', | ||
actionTypeId: 'test.index-record', | ||
config: { | ||
unencrypted: `This value shouldn't get encrypted`, | ||
}, | ||
secrets: { | ||
encrypted: 'This value should be encrypted', | ||
}, | ||
}) | ||
.expect(200); | ||
|
||
await supertest | ||
.delete(`${getUrlPrefix(Spaces.space1.id)}/api/action/${createdAction.id}`) | ||
.set('kbn-xsrf', 'foo') | ||
.expect(204, ''); | ||
}); | ||
|
||
it(`should handle delete request appropriately when action doesn't exist`, async () => { | ||
await supertest | ||
.delete(`${getUrlPrefix(Spaces.space1.id)}/api/action/2`) | ||
.set('kbn-xsrf', 'foo') | ||
.expect(404, { | ||
statusCode: 404, | ||
error: 'Not Found', | ||
message: 'Saved object [action/2] not found', | ||
}); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.