Skip to content

Commit

Permalink
resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Dec 8, 2020
1 parent 126225e commit a0731bb
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
4 changes: 4 additions & 0 deletions x-pack/plugins/alerts/server/alerts_client/alerts_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,8 @@ export class AlertsClient {
{ id, data }: UpdateOptions,
{ attributes, version }: SavedObject<RawAlert>
): Promise<PartialAlert> {
this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId);

const alertType = this.alertTypeRegistry.get(attributes.alertTypeId);

// Validate
Expand Down Expand Up @@ -984,6 +986,8 @@ export class AlertsClient {
version = alert.version;
}

this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId);

try {
await this.authorization.ensureAuthorized(
attributes.alertTypeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ActionsAuthorization } from '../../../../actions/server';
import { getBeforeSetup, setGlobalDate } from './lib';
import { AlertExecutionStatusValues } from '../../types';
import { RecoveredActionGroup } from '../../../common';
import { RegistryAlertType } from '../../alert_type_registry';

const taskManager = taskManagerMock.createStart();
const alertTypeRegistry = alertTypeRegistryMock.create();
Expand Down Expand Up @@ -49,7 +50,7 @@ beforeEach(() => {
setGlobalDate();

describe('aggregate()', () => {
const listedTypes = new Set([
const listedTypes = new Set<RegistryAlertType>([
{
actionGroups: [],
actionVariables: undefined,
Expand Down
11 changes: 8 additions & 3 deletions x-pack/plugins/alerts/server/alerts_client/tests/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { auditServiceMock } from '../../../../security/server/audit/index.mock';
import { httpServerMock } from '../../../../../../src/core/server/mocks';
import { getBeforeSetup, setGlobalDate } from './lib';
import { RecoveredActionGroup } from '../../../common';
import { licenseStateMock } from '../../lib/license_state.mock';

jest.mock('../../../../../../src/core/server/saved_objects/service/lib/utils', () => ({
SavedObjectsUtils: {
Expand Down Expand Up @@ -1196,7 +1195,13 @@ describe('create()', () => {
);
});

it('ensures the action type gets validated for the license', async () => {
const licenseState = licenseStateMock.create();
test('throws error when ensureActionTypeEnabled throws', async () => {
const data = getMockData();
alertTypeRegistry.ensureAlertTypeEnabled.mockImplementation(() => {
throw new Error('Fail');
});
await expect(alertsClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
`"Fail"`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { httpServerMock } from '../../../../../../src/core/server/mocks';
import { auditServiceMock } from '../../../../security/server/audit/index.mock';
import { getBeforeSetup, setGlobalDate } from './lib';
import { RecoveredActionGroup } from '../../../common';
import { RegistryAlertType } from '../../alert_type_registry';

const taskManager = taskManagerMock.createStart();
const alertTypeRegistry = alertTypeRegistryMock.create();
Expand Down Expand Up @@ -53,7 +54,7 @@ beforeEach(() => {
setGlobalDate();

describe('find()', () => {
const listedTypes = new Set([
const listedTypes = new Set<RegistryAlertType>([
{
actionGroups: [],
recoveryActionGroup: RecoveredActionGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
import { alertsAuthorizationMock } from '../../authorization/alerts_authorization.mock';
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
import { AlertsAuthorization } from '../../authorization/alerts_authorization';
import {
AlertsAuthorization,
RegistryAlertTypeWithAuth,
} from '../../authorization/alerts_authorization';
import { ActionsAuthorization } from '../../../../actions/server';
import { getBeforeSetup } from './lib';
import { RecoveredActionGroup } from '../../../common';
import { RegistryAlertType } from '../../alert_type_registry';

const taskManager = taskManagerMock.createStart();
const alertTypeRegistry = alertTypeRegistryMock.create();
Expand Down Expand Up @@ -47,7 +51,7 @@ beforeEach(() => {

describe('listAlertTypes', () => {
let alertsClient: AlertsClient;
const alertingAlertType = {
const alertingAlertType: RegistryAlertType = {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
Expand All @@ -58,7 +62,7 @@ describe('listAlertTypes', () => {
producer: 'alerts',
enabledInLicense: true,
};
const myAppAlertType = {
const myAppAlertType: RegistryAlertType = {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
Expand All @@ -84,7 +88,7 @@ describe('listAlertTypes', () => {
test('should return a list of AlertTypes that exist in the registry', async () => {
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
authorization.filterByAlertTypeAuthorization.mockResolvedValue(
new Set([
new Set<RegistryAlertTypeWithAuth>([
{ ...myAppAlertType, authorizedConsumers },
{ ...alertingAlertType, authorizedConsumers },
])
Expand All @@ -98,7 +102,7 @@ describe('listAlertTypes', () => {
});

describe('authorization', () => {
const listedTypes = new Set([
const listedTypes = new Set<RegistryAlertType>([
{
actionGroups: [],
actionVariables: undefined,
Expand Down Expand Up @@ -126,7 +130,7 @@ describe('listAlertTypes', () => {
});

test('should return a list of AlertTypes that exist in the registry only if the user is authorised to get them', async () => {
const authorizedTypes = new Set([
const authorizedTypes = new Set<RegistryAlertTypeWithAuth>([
{
id: 'myType',
name: 'Test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { alertsAuthorizationAuditLoggerMock } from './audit_logger.mock';
import { AlertsAuthorizationAuditLogger, AuthorizationResult } from './audit_logger';
import uuid from 'uuid';
import { RecoveredActionGroup } from '../../common';
import { RegistryAlertType } from '../alert_type_registry';

const alertTypeRegistry = alertTypeRegistryMock.create();
const features: jest.Mocked<FeaturesStartContract> = featuresPluginMock.createStart();
Expand Down Expand Up @@ -533,7 +534,7 @@ describe('AlertsAuthorization', () => {
});

describe('getFindAuthorizationFilter', () => {
const myOtherAppAlertType = {
const myOtherAppAlertType: RegistryAlertType = {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
Expand All @@ -544,7 +545,7 @@ describe('AlertsAuthorization', () => {
producer: 'alerts',
enabledInLicense: true,
};
const myAppAlertType = {
const myAppAlertType: RegistryAlertType = {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
Expand All @@ -555,7 +556,7 @@ describe('AlertsAuthorization', () => {
producer: 'myApp',
enabledInLicense: true,
};
const mySecondAppAlertType = {
const mySecondAppAlertType: RegistryAlertType = {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
Expand Down Expand Up @@ -832,7 +833,7 @@ describe('AlertsAuthorization', () => {
});

describe('filterByAlertTypeAuthorization', () => {
const myOtherAppAlertType = {
const myOtherAppAlertType: RegistryAlertType = {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
Expand All @@ -843,7 +844,7 @@ describe('AlertsAuthorization', () => {
producer: 'myOtherApp',
enabledInLicense: true,
};
const myAppAlertType = {
const myAppAlertType: RegistryAlertType = {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
Expand Down
7 changes: 4 additions & 3 deletions x-pack/plugins/alerts/server/routes/list_alert_types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { verifyApiAccess } from '../lib/license_api_access';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { alertsClientMock } from '../alerts_client.mock';
import { RecoveredActionGroup } from '../../common';
import { RegistryAlertTypeWithAuth } from '../authorization';

const alertsClient = alertsClientMock.create();

Expand Down Expand Up @@ -53,7 +54,7 @@ describe('listAlertTypesRoute', () => {
},
producer: 'test',
enabledInLicense: true,
},
} as RegistryAlertTypeWithAuth,
];
alertsClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));

Expand Down Expand Up @@ -126,7 +127,7 @@ describe('listAlertTypesRoute', () => {
},
producer: 'alerts',
enabledInLicense: true,
},
} as RegistryAlertTypeWithAuth,
];

alertsClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));
Expand Down Expand Up @@ -178,7 +179,7 @@ describe('listAlertTypesRoute', () => {
},
producer: 'alerts',
enabledInLicense: true,
},
} as RegistryAlertTypeWithAuth,
];

alertsClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));
Expand Down

0 comments on commit a0731bb

Please sign in to comment.