Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Actions] Pass the Kibana requests to the executor of system actions #173763

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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