-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
269 additions
and
88 deletions.
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
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
87 changes: 87 additions & 0 deletions
87
x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/execution_status.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,87 @@ | ||
/* | ||
* 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, getTestAlertData, ObjectRemover } from '../../../common/lib'; | ||
import { FtrProviderContext } from '../../../common/ftr_provider_context'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default function executionStatusAlertTests({ getService }: FtrProviderContext) { | ||
const supertest = getService('supertest'); | ||
const spaceId = Spaces[0].id; | ||
|
||
// the only tests here are those that can't be run in spaces_only | ||
describe('executionStatus', () => { | ||
const objectRemover = new ObjectRemover(supertest); | ||
|
||
after(async () => await objectRemover.removeAll()); | ||
|
||
it('should eventually have error reason "decrypt" when appropriate', async () => { | ||
const response = await supertest | ||
.post(`${getUrlPrefix(spaceId)}/api/alerts/alert`) | ||
.set('kbn-xsrf', 'foo') | ||
.send( | ||
getTestAlertData({ | ||
alertTypeId: 'test.noop', | ||
schedule: { interval: '1s' }, | ||
}) | ||
); | ||
expect(response.status).to.eql(200); | ||
const alertId = response.body.id; | ||
objectRemover.add(spaceId, alertId, 'alert', 'alerts'); | ||
|
||
let executionStatus = await waitForStatus(alertId, new Set(['ok']), 10000); | ||
|
||
// break AAD | ||
await supertest | ||
.put(`${getUrlPrefix(spaceId)}/api/alerts_fixture/saved_object/alert/${alertId}`) | ||
.set('kbn-xsrf', 'foo') | ||
.send({ | ||
attributes: { | ||
name: 'bar', | ||
}, | ||
}) | ||
.expect(200); | ||
|
||
executionStatus = await waitForStatus(alertId, new Set(['error'])); | ||
expect(executionStatus.error).to.be.ok(); | ||
expect(executionStatus.error.reason).to.be('decrypt'); | ||
expect(executionStatus.error.message).to.be('Unable to decrypt attribute "apiKey"'); | ||
}); | ||
}); | ||
|
||
const WaitForStatusIncrement = 500; | ||
|
||
async function waitForStatus( | ||
id: string, | ||
statuses: Set<string>, | ||
waitMillis: number = 10000 | ||
): Promise<Record<string, any>> { | ||
if (waitMillis < 0) { | ||
expect().fail(`waiting for alert ${id} statuses ${Array.from(statuses)} timed out`); | ||
} | ||
|
||
const response = await supertest.get(`${getUrlPrefix(spaceId)}/api/alerts/alert/${id}`); | ||
expect(response.status).to.eql(200); | ||
const { status } = response.body.executionStatus; | ||
if (statuses.has(status)) return response.body.executionStatus; | ||
|
||
// eslint-disable-next-line no-console | ||
console.log( | ||
`waitForStatus(${Array.from(statuses)}): got ${JSON.stringify( | ||
response.body.executionStatus | ||
)}, retrying` | ||
); | ||
|
||
await delay(WaitForStatusIncrement); | ||
return await waitForStatus(id, statuses, waitMillis - WaitForStatusIncrement); | ||
} | ||
} | ||
|
||
async function delay(millis: number): Promise<void> { | ||
await new Promise((resolve) => setTimeout(resolve, millis)); | ||
} |
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
Oops, something went wrong.