Skip to content

Commit

Permalink
[Alerting] Fixes Failing test: X-Pack Alerting API Integration Tests.…
Browse files Browse the repository at this point in the history
…x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting - alerting api integration security and spaces enabled Alerts do stuff when AAD is broken (#84707)

* Adding delay between creating and updating alert to avoid 409 conflicts

* Unskipping update test

* Using retry.try instead of delay

* PR fixes

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
ymao1 and kibanamachine authored Dec 7, 2020
1 parent 008c6a0 commit 46e8c54
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { FtrProviderContext } from '../../../common/ftr_provider_context';
export default function createDeleteTests({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const es = getService('legacyEs');
const retry = getService('retry');
const supertestWithoutAuth = getService('supertestWithoutAuth');

describe('delete', () => {
Expand Down Expand Up @@ -301,17 +302,19 @@ export default function createDeleteTests({ getService }: FtrProviderContext) {
.send(getTestAlertData())
.expect(200);

await supertest
.put(
`${getUrlPrefix(space.id)}/api/alerts_fixture/saved_object/alert/${createdAlert.id}`
)
.set('kbn-xsrf', 'foo')
.send({
attributes: {
name: 'bar',
},
})
.expect(200);
await retry.try(async () => {
await supertest
.put(
`${getUrlPrefix(space.id)}/api/alerts_fixture/saved_object/alert/${createdAlert.id}`
)
.set('kbn-xsrf', 'foo')
.send({
attributes: {
name: 'bar',
},
})
.expect(200);
});

const response = await supertestWithoutAuth
.delete(`${getUrlPrefix(space.id)}/api/alerts/alert/${createdAlert.id}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default function createDisableAlertTests({ getService }: FtrProviderContext) {
const es = getService('legacyEs');
const retry = getService('retry');
const supertest = getService('supertest');
const supertestWithoutAuth = getService('supertestWithoutAuth');

Expand Down Expand Up @@ -287,17 +288,19 @@ export default function createDisableAlertTests({ getService }: FtrProviderConte
.expect(200);
objectRemover.add(space.id, createdAlert.id, 'alert', 'alerts');

await supertest
.put(
`${getUrlPrefix(space.id)}/api/alerts_fixture/saved_object/alert/${createdAlert.id}`
)
.set('kbn-xsrf', 'foo')
.send({
attributes: {
name: 'bar',
},
})
.expect(200);
await retry.try(async () => {
await supertest
.put(
`${getUrlPrefix(space.id)}/api/alerts_fixture/saved_object/alert/${createdAlert.id}`
)
.set('kbn-xsrf', 'foo')
.send({
attributes: {
name: 'bar',
},
})
.expect(200);
});

const response = await alertUtils.getDisableRequest(createdAlert.id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
// eslint-disable-next-line import/no-default-export
export default function createEnableAlertTests({ getService }: FtrProviderContext) {
const es = getService('legacyEs');
const retry = getService('retry');
const supertest = getService('supertest');
const supertestWithoutAuth = getService('supertestWithoutAuth');

Expand Down Expand Up @@ -304,17 +305,19 @@ export default function createEnableAlertTests({ getService }: FtrProviderContex
.expect(200);
objectRemover.add(space.id, createdAlert.id, 'alert', 'alerts');

await supertest
.put(
`${getUrlPrefix(space.id)}/api/alerts_fixture/saved_object/alert/${createdAlert.id}`
)
.set('kbn-xsrf', 'foo')
.send({
attributes: {
name: 'bar',
},
})
.expect(200);
await retry.try(async () => {
await supertest
.put(
`${getUrlPrefix(space.id)}/api/alerts_fixture/saved_object/alert/${createdAlert.id}`
)
.set('kbn-xsrf', 'foo')
.send({
attributes: {
name: 'bar',
},
})
.expect(200);
});

const response = await alertUtils.getEnableRequest(createdAlert.id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ export default function eventLogTests({ getService }: FtrProviderContext) {
const alertId = response.body.id;
objectRemover.add(spaceId, alertId, 'alert', 'alerts');

// break AAD
await supertest
.put(`${getUrlPrefix(spaceId)}/api/alerts_fixture/saved_object/alert/${alertId}`)
.set('kbn-xsrf', 'foo')
.send({
attributes: {
name: 'bar',
},
})
.expect(200);
await retry.try(async () => {
// break AAD
await supertest
.put(`${getUrlPrefix(spaceId)}/api/alerts_fixture/saved_object/alert/${alertId}`)
.set('kbn-xsrf', 'foo')
.send({
attributes: {
name: 'bar',
},
})
.expect(200);
});

const events = await retry.try(async () => {
// there can be a successful execute before the error one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { FtrProviderContext } from '../../../common/ftr_provider_context';

// eslint-disable-next-line import/no-default-export
export default function executionStatusAlertTests({ getService }: FtrProviderContext) {
const retry = getService('retry');
const supertest = getService('supertest');
const spaceId = Spaces[0].id;

Expand All @@ -37,16 +38,18 @@ export default function executionStatusAlertTests({ getService }: FtrProviderCon

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);
await retry.try(async () => {
// 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
.then((response: SupertestResponse) => response.body);
}

// FLAKY: https://github.com/elastic/kibana/issues/82804
describe.skip('update', () => {
describe('update', () => {
const objectRemover = new ObjectRemover(supertest);

after(() => objectRemover.removeAll());
Expand Down Expand Up @@ -429,17 +428,19 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
.expect(200);
objectRemover.add(space.id, createdAlert.id, 'alert', 'alerts');

await supertest
.put(
`${getUrlPrefix(space.id)}/api/alerts_fixture/saved_object/alert/${createdAlert.id}`
)
.set('kbn-xsrf', 'foo')
.send({
attributes: {
name: 'bar',
},
})
.expect(200);
await retry.try(async () => {
await supertest
.put(
`${getUrlPrefix(space.id)}/api/alerts_fixture/saved_object/alert/${createdAlert.id}`
)
.set('kbn-xsrf', 'foo')
.send({
attributes: {
name: 'bar',
},
})
.expect(200);
});

const updatedData = {
name: 'bcd',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {

// eslint-disable-next-line import/no-default-export
export default function createUpdateApiKeyTests({ getService }: FtrProviderContext) {
const retry = getService('retry');
const supertest = getService('supertest');
const supertestWithoutAuth = getService('supertestWithoutAuth');

Expand Down Expand Up @@ -301,17 +302,19 @@ export default function createUpdateApiKeyTests({ getService }: FtrProviderConte
.expect(200);
objectRemover.add(space.id, createdAlert.id, 'alert', 'alerts');

await supertest
.put(
`${getUrlPrefix(space.id)}/api/alerts_fixture/saved_object/alert/${createdAlert.id}`
)
.set('kbn-xsrf', 'foo')
.send({
attributes: {
name: 'bar',
},
})
.expect(200);
await retry.try(async () => {
await supertest
.put(
`${getUrlPrefix(space.id)}/api/alerts_fixture/saved_object/alert/${createdAlert.id}`
)
.set('kbn-xsrf', 'foo')
.send({
attributes: {
name: 'bar',
},
})
.expect(200);
});

const response = await alertUtils.getUpdateApiKeyRequest(createdAlert.id);

Expand Down

0 comments on commit 46e8c54

Please sign in to comment.