Skip to content

Commit

Permalink
[Actions] Pass the Kibana requests to the executor of system actions (#…
Browse files Browse the repository at this point in the history
…173763)

## Summary

System actions, like the case action, may need access to the Kibana
request to initiate clients (cases client for example) or services. This
PR passes the Kibana request to the `executor` of system actions. It
does not pass the request to nonsystem action types.

### Checklist

Delete any items that are not applicable to this PR.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
  • Loading branch information
cnasikas authored Dec 20, 2023
1 parent 73f53f5 commit 4c2ea7d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
72 changes: 72 additions & 0 deletions x-pack/plugins/actions/server/lib/action_executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ test('successfully executes with system connector', async () => {
secrets: {},
params: { foo: true },
logger: loggerMock,
request: {},
});

expect(loggerMock.debug).toBeCalledWith(
Expand Down Expand Up @@ -812,6 +813,75 @@ test('successfully executes with system connector', async () => {
`);
});

test('passes the Kibana request on the executor of a system action', async () => {
const actionType: jest.Mocked<ActionType> = {
id: '.cases',
name: 'Cases',
minimumLicenseRequired: 'platinum',
supportedFeatureIds: ['alerting'],
isSystemActionType: true,
validate: {
config: { schema: schema.any() },
secrets: { schema: schema.any() },
params: { schema: schema.any() },
},
executor: jest.fn(),
};

actionTypeRegistry.get.mockReturnValueOnce(actionType);
await actionExecutor.execute({ ...executeParams, actionId: 'system-connector-.cases' });

expect(actionType.executor).toHaveBeenCalledWith({
actionId: 'system-connector-.cases',
services: expect.anything(),
config: {},
secrets: {},
params: { foo: true },
logger: loggerMock,
request: {},
});
});

test('does not pass the Kibana request on the executor if the action is not a system action', async () => {
const actionType: jest.Mocked<ActionType> = {
id: 'test',
name: 'Test',
minimumLicenseRequired: 'basic',
supportedFeatureIds: ['alerting'],
validate: {
config: { schema: schema.object({ bar: schema.boolean() }) },
secrets: { schema: schema.object({ baz: schema.boolean() }) },
params: { schema: schema.object({ foo: schema.boolean() }) },
},
executor: jest.fn(),
};

const actionSavedObject = {
id: '1',
type: 'action',
attributes: {
name: '1',
actionTypeId: 'test',
config: {
bar: true,
},
secrets: {
baz: true,
},
isMissingSecrets: false,
},
references: [],
};

encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce(actionSavedObject);
actionTypeRegistry.get.mockReturnValueOnce(actionType);
await actionExecutor.execute(executeParams);

const args = actionType.executor.mock.calls[0][0];

expect(args.request).toBeUndefined();
});

test('successfully authorize system actions', async () => {
const actionType: jest.Mocked<ActionType> = {
id: '.cases',
Expand Down Expand Up @@ -1278,6 +1348,7 @@ test('should not throws an error if actionType is system action', async () => {
secrets: {},
params: { foo: true },
logger: loggerMock,
request: {},
});
});

Expand Down Expand Up @@ -1510,6 +1581,7 @@ test('should not throw error if action is system action and isESOCanEncrypt is f
secrets: {},
params: { foo: true },
logger: loggerMock,
request: {},
});

expect(loggerMock.debug).toBeCalledWith(
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/actions/server/lib/action_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export class ActionExecutor {
configurationUtilities,
logger,
source,
...(actionType.isSystemActionType ? { request } : {}),
});
} catch (err) {
if (
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/actions/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface ActionTypeExecutorOptions<
taskInfo?: TaskInfo;
configurationUtilities: ActionsConfigurationUtilities;
source?: ActionExecutionSource<unknown>;
request?: KibanaRequest;
}

export type ActionResult = Connector;
Expand Down

0 comments on commit 4c2ea7d

Please sign in to comment.