Skip to content

Commit

Permalink
Small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Jul 11, 2023
1 parent a9e3bd5 commit 72e9d72
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
20 changes: 0 additions & 20 deletions x-pack/plugins/actions/server/action_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -754,26 +754,6 @@ describe('actionTypeRegistry', () => {
expect(result).toEqual([]);
});

it('should return an empty array if the action type is not a system action but registers kibana privileges', () => {
const registry = new ActionTypeRegistry(actionTypeRegistryParams);

registry.register({
id: 'foo',
name: 'Foo',
minimumLicenseRequired: 'basic',
supportedFeatureIds: ['alerting'],
validate: {
config: { schema: schema.object({}) },
secrets: { schema: schema.object({}) },
params: { schema: schema.object({}) },
},
executor,
});

const result = registry.getSystemActionKibanaPrivileges('foo');
expect(result).toEqual([]);
});

it('should return an empty array if the action type is not a system action but defines kibana privileges', () => {
const registry = new ActionTypeRegistry(actionTypeRegistryParams);
const getKibanaPrivileges = jest.fn().mockReturnValue(['test/create']);
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 @@ -101,7 +101,7 @@ export class ActionTypeRegistry {
Boolean(this.actionTypes.get(actionTypeId)?.isSystemActionType);

/**
* Returns the kibana privileges of an action type
* Returns the kibana privileges of a system action type
*/
public getSystemActionKibanaPrivileges(
actionTypeId: string,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/actions/server/lib/action_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ export class ActionExecutor {
let rawResult: ActionTypeExecutorRawResult<unknown>;
try {
/**
* Perform additional authorization checks for system actions.
* Ensures correct permissions for execution and
* performs authorization checks for system actions.
* It will thrown an error in case of failure.
*
*/
await ensureAuthorizedToExecute({
params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,12 @@ export default function ({ getService }: FtrProviderContext) {
});

switch (scenario.id) {
/**
* The users in these scenarios may have access
* to Actions but do not have access to
* the system action. They should not be able to
* to execute even if they have access to Actions.
*/
case 'no_kibana_privileges at space1':
case 'space_1_all_alerts_none_actions at space1':
case 'space_1_all at space2':
Expand All @@ -529,6 +535,11 @@ export default function ({ getService }: FtrProviderContext) {
message: 'Unauthorized to execute actions',
});
break;
/**
* The users in these scenarios have access
* to Actions and to the system action. They should be able to
* execute.
*/
case 'superuser at space1':
case 'system_actions at space1':
expect(response.statusCode).to.eql(200);
Expand Down

0 comments on commit 72e9d72

Please sign in to comment.