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

Shallow clone properties when adding to alert or action registry #65309

Merged
merged 1 commit into from
May 6, 2020
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
13 changes: 13 additions & 0 deletions x-pack/plugins/actions/server/action_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ describe('register()', () => {
`);
});

test('shallow clones the given action type', () => {
const myType: ActionType = {
id: 'my-action-type',
name: 'My action type',
minimumLicenseRequired: 'basic',
executor,
};
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register(myType);
myType.name = 'Changed';
expect(actionTypeRegistry.get('my-action-type').name).toEqual('My action type');
});

test('throws error if action type already registered', () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);
actionTypeRegistry.register({
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/actions/server/action_type_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class ActionTypeRegistry {
)
);
}
this.actionTypes.set(actionType.id, actionType);
this.actionTypes.set(actionType.id, { ...actionType });
this.taskManager.registerTaskDefinitions({
[`actions:${actionType.id}`]: {
title: actionType.name,
Expand Down
19 changes: 19 additions & 0 deletions x-pack/plugins/alerting/server/alert_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ describe('register()', () => {
`);
});

test('shallow clones the given alert type', () => {
const alertType: AlertType = {
id: 'test',
name: 'Test',
actionGroups: [
{
id: 'default',
name: 'Default',
},
],
defaultActionGroupId: 'default',
executor: jest.fn(),
};
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
registry.register(alertType);
alertType.name = 'Changed';
expect(registry.get('test').name).toEqual('Test');
});

test('should throw an error if type is already registered', () => {
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
registry.register({
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/alert_type_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class AlertTypeRegistry {
);
}
alertType.actionVariables = normalizedActionVariables(alertType.actionVariables);
this.alertTypes.set(alertType.id, alertType);
this.alertTypes.set(alertType.id, { ...alertType });
this.taskManager.registerTaskDefinitions({
[`alerting:${alertType.id}`]: {
title: alertType.name,
Expand Down