From 763e05ffe86b969ef55c4b282b79c957e1486057 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Mon, 1 Apr 2024 19:21:45 +0300 Subject: [PATCH] PR feedback --- .../common/lib/alert_utils.ts | 2 - .../group1/tests/alerting/find.ts | 1 - .../group1/tests/alerting/get.ts | 1 - .../group2/tests/actions/get_all_system.ts | 63 ++++++++++++++++++- .../group3/tests/alerting/bulk_delete.ts | 1 - .../group3/tests/alerting/bulk_disable.ts | 1 - .../group3/tests/alerting/bulk_enable.ts | 1 - .../group3/tests/alerting/clone.ts | 1 - .../group3/tests/alerting/resolve.ts | 1 - .../tests/alerting/group1/create.ts | 1 - 10 files changed, 62 insertions(+), 11 deletions(-) diff --git a/x-pack/test/alerting_api_integration/common/lib/alert_utils.ts b/x-pack/test/alerting_api_integration/common/lib/alert_utils.ts index 70a57c386d050..90653108aa500 100644 --- a/x-pack/test/alerting_api_integration/common/lib/alert_utils.ts +++ b/x-pack/test/alerting_api_integration/common/lib/alert_utils.ts @@ -704,8 +704,6 @@ function getAlwaysFiringRuleWithSystemAction(reference: string) { actions: [ { id: 'system-connector-test.system-action-connector-adapter', - actionTypeId: 'test.system-action-connector-adapter', - uuid: '123', /** * The injected param required by the action will be set by the corresponding * connector adapter. Setting it here it will lead to a 400 error by the diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find.ts index 4b0382fe0cd54..22c2f9ce6489e 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find.ts @@ -603,7 +603,6 @@ const findTestUtils = ( }, { id: 'system-connector-test.system-action', - actionTypeId: 'test.system-action', params: {}, }, ], diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/get.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/get.ts index 467405266f98e..6d245ed28cc00 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/get.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/get.ts @@ -345,7 +345,6 @@ const getTestUtils = ( }, { id: 'system-connector-test.system-action', - actionTypeId: 'test.system-action', params: {}, }, ], diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/get_all_system.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/get_all_system.ts index 414894299edd5..2811c7e2d4ce2 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/get_all_system.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/get_all_system.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import { RULE_SAVED_OBJECT_TYPE } from '@kbn/alerting-plugin/server'; -import { UserAtSpaceScenarios } from '../../../scenarios'; +import { SuperuserAtSpace1, UserAtSpaceScenarios } from '../../../scenarios'; import { getUrlPrefix, getTestRuleData, ObjectRemover } from '../../../../common/lib'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; @@ -525,5 +525,66 @@ export default function getAllActionTests({ getService }: FtrProviderContext) { }); }); } + + describe('References', () => { + const systemAction = { + id: 'system-connector-test.system-action', + params: {}, + }; + + it('calculates the references correctly', async () => { + const { user, space } = SuperuserAtSpace1; + + const { body: createdAction } = await supertest + .post(`${getUrlPrefix(space.id)}/api/actions/connector`) + .set('kbn-xsrf', 'foo') + .auth(user.username, user.password) + .send({ + name: 'My action', + connector_type_id: 'test.index-record', + config: { + unencrypted: `This value shouldn't get encrypted`, + }, + secrets: { + encrypted: 'This value should be encrypted', + }, + }) + .expect(200); + + objectRemover.add(space.id, createdAction.id, 'action', 'actions'); + + const ruleRes = await supertest + .post(`${getUrlPrefix(space.id)}/api/alerting/rule`) + .set('kbn-xsrf', 'foo') + .send( + getTestRuleData({ + actions: [ + systemAction, + { + id: createdAction.id, + group: 'default', + params: {}, + }, + ], + }) + ) + .expect(200); + + objectRemover.add(space.id, ruleRes.body.id, 'rule', 'alerting'); + + const response = await supertestWithoutAuth + .get(`${getUrlPrefix(space.id)}/internal/actions/connectors`) + .auth(user.username, user.password) + .expect(200); + + const connectors = response.body as Array<{ id: string; referenced_by_count: number }>; + + const createdConnector = connectors.find((connector) => connector.id === createdAction.id); + const systemConnector = connectors.find((connector) => connector.id === systemAction.id); + + expect(createdConnector?.referenced_by_count).to.be(1); + expect(systemConnector?.referenced_by_count).to.be(0); + }); + }); }); } diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_delete.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_delete.ts index 927ea19396687..fc3526eebc6a4 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_delete.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_delete.ts @@ -703,7 +703,6 @@ export default ({ getService }: FtrProviderContext) => { }, { id: 'system-connector-test.system-action', - actionTypeId: 'test.system-action', params: {}, }, ], diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_disable.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_disable.ts index 22c9884ec0a29..d69055a92e1f4 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_disable.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_disable.ts @@ -571,7 +571,6 @@ export default ({ getService }: FtrProviderContext) => { }, { id: 'system-connector-test.system-action', - actionTypeId: 'test.system-action', params: {}, }, ], diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_enable.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_enable.ts index cd0cf5f75bc5a..d61810bb72fd3 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_enable.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_enable.ts @@ -543,7 +543,6 @@ export default ({ getService }: FtrProviderContext) => { }, { id: 'system-connector-test.system-action', - actionTypeId: 'test.system-action', params: {}, }, ], diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/clone.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/clone.ts index 2a08bb833a871..d76c4dbd1a239 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/clone.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/clone.ts @@ -278,7 +278,6 @@ export default function createAlertTests({ getService }: FtrProviderContext) { }, { id: 'system-connector-test.system-action', - actionTypeId: 'test.system-action', params: {}, }, ], diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/resolve.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/resolve.ts index fe9e733eea677..fe973b9dde73c 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/resolve.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/resolve.ts @@ -49,7 +49,6 @@ export default ({ getService }: FtrProviderContext) => { }, { id: 'system-connector-test.system-action', - actionTypeId: 'test.system-action', params: {}, }, ], diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/create.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/create.ts index 774b0e683d520..555c578612225 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/create.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/create.ts @@ -475,7 +475,6 @@ export default function createAlertTests({ getService }: FtrProviderContext) { describe('system actions', () => { const systemAction = { id: 'system-connector-test.system-action', - actionTypeId: 'test.system-action', params: {}, };