From 46e8c540aa1ea80f8338c426e3418894109e1aa5 Mon Sep 17 00:00:00 2001 From: ymao1 Date: Mon, 7 Dec 2020 11:52:37 -0500 Subject: [PATCH] [Alerting] Fixes Failing test: X-Pack Alerting API Integration Tests.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 <42973632+kibanamachine@users.noreply.github.com> --- .../tests/alerting/delete.ts | 25 +++++++++-------- .../tests/alerting/disable.ts | 25 +++++++++-------- .../tests/alerting/enable.ts | 25 +++++++++-------- .../tests/alerting/event_log.ts | 22 ++++++++------- .../tests/alerting/execution_status.ts | 23 +++++++++------- .../tests/alerting/update.ts | 27 ++++++++++--------- .../tests/alerting/update_api_key.ts | 25 +++++++++-------- 7 files changed, 95 insertions(+), 77 deletions(-) diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/delete.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/delete.ts index fc453c8da72e..f55b930a264c 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/delete.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/delete.ts @@ -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', () => { @@ -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}`) diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/disable.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/disable.ts index 4e4f9053bd24..03d8f7789380 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/disable.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/disable.ts @@ -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'); @@ -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); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/enable.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/enable.ts index d7f6546bf34a..2444f37ea5b2 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/enable.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/enable.ts @@ -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'); @@ -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); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/event_log.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/event_log.ts index 459d214c8c99..564ab7b832dd 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/event_log.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/event_log.ts @@ -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 diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/execution_status.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/execution_status.ts index 4058b7135628..5295f5d90fb0 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/execution_status.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/execution_status.ts @@ -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; @@ -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(); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts index 9c3d2801c088..6b03492432ac 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts @@ -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()); @@ -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', diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update_api_key.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update_api_key.ts index 7dea591b895e..0b525fbf7e80 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update_api_key.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update_api_key.ts @@ -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'); @@ -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);