mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Alerting] Renamed Alerting framework AlertsClient to RulesClient according to the new terminology. (#106382)
* [Alerting] Renamed Alerting framework AlertsClient to RulesClient according to the new terminology. * fixed path * fixed type checks * fixed type checks
This commit is contained in:
parent
484998c0e8
commit
4c7037b44a
202 changed files with 1506 additions and 1512 deletions
|
@ -669,10 +669,10 @@
|
|||
"children": [
|
||||
{
|
||||
"parentPluginId": "alerting",
|
||||
"id": "def-server.AlertingApiRequestHandlerContext.getAlertsClient",
|
||||
"id": "def-server.AlertingApiRequestHandlerContext.getRulesClient",
|
||||
"type": "Function",
|
||||
"tags": [],
|
||||
"label": "getAlertsClient",
|
||||
"label": "getRulesClient",
|
||||
"description": [],
|
||||
"signature": [
|
||||
"() => ",
|
||||
|
@ -680,8 +680,8 @@
|
|||
"pluginId": "alerting",
|
||||
"scope": "server",
|
||||
"docId": "kibAlertingPluginApi",
|
||||
"section": "def-server.AlertsClient",
|
||||
"text": "AlertsClient"
|
||||
"section": "def-server.RulesClient",
|
||||
"text": "RulesClient"
|
||||
}
|
||||
],
|
||||
"source": {
|
||||
|
@ -1170,7 +1170,7 @@
|
|||
"<Params>"
|
||||
],
|
||||
"source": {
|
||||
"path": "x-pack/plugins/alerting/server/alerts_client/alerts_client.ts",
|
||||
"path": "x-pack/plugins/alerting/server/rules_client/rules_client.ts",
|
||||
"lineNumber": 140
|
||||
},
|
||||
"deprecated": false,
|
||||
|
@ -1183,7 +1183,7 @@
|
|||
"label": "page",
|
||||
"description": [],
|
||||
"source": {
|
||||
"path": "x-pack/plugins/alerting/server/alerts_client/alerts_client.ts",
|
||||
"path": "x-pack/plugins/alerting/server/rules_client/rules_client.ts",
|
||||
"lineNumber": 141
|
||||
},
|
||||
"deprecated": false
|
||||
|
@ -1196,7 +1196,7 @@
|
|||
"label": "perPage",
|
||||
"description": [],
|
||||
"source": {
|
||||
"path": "x-pack/plugins/alerting/server/alerts_client/alerts_client.ts",
|
||||
"path": "x-pack/plugins/alerting/server/rules_client/rules_client.ts",
|
||||
"lineNumber": 142
|
||||
},
|
||||
"deprecated": false
|
||||
|
@ -1209,7 +1209,7 @@
|
|||
"label": "total",
|
||||
"description": [],
|
||||
"source": {
|
||||
"path": "x-pack/plugins/alerting/server/alerts_client/alerts_client.ts",
|
||||
"path": "x-pack/plugins/alerting/server/rules_client/rules_client.ts",
|
||||
"lineNumber": 143
|
||||
},
|
||||
"deprecated": false
|
||||
|
@ -1233,7 +1233,7 @@
|
|||
"<Params>, \"enabled\" | \"id\" | \"name\" | \"params\" | \"actions\" | \"tags\" | \"alertTypeId\" | \"consumer\" | \"schedule\" | \"scheduledTaskId\" | \"createdBy\" | \"updatedBy\" | \"createdAt\" | \"updatedAt\" | \"apiKeyOwner\" | \"throttle\" | \"notifyWhen\" | \"muteAll\" | \"mutedInstanceIds\" | \"executionStatus\">[]"
|
||||
],
|
||||
"source": {
|
||||
"path": "x-pack/plugins/alerting/server/alerts_client/alerts_client.ts",
|
||||
"path": "x-pack/plugins/alerting/server/rules_client/rules_client.ts",
|
||||
"lineNumber": 144
|
||||
},
|
||||
"deprecated": false
|
||||
|
@ -1343,10 +1343,10 @@
|
|||
},
|
||||
{
|
||||
"parentPluginId": "alerting",
|
||||
"id": "def-server.PluginStartContract.getAlertsClientWithRequest",
|
||||
"id": "def-server.PluginStartContract.getRulesClientWithRequest",
|
||||
"type": "Function",
|
||||
"tags": [],
|
||||
"label": "getAlertsClientWithRequest",
|
||||
"label": "getRulesClientWithRequest",
|
||||
"description": [],
|
||||
"signature": [
|
||||
"(request: ",
|
||||
|
@ -1362,8 +1362,8 @@
|
|||
"pluginId": "alerting",
|
||||
"scope": "server",
|
||||
"docId": "kibAlertingPluginApi",
|
||||
"section": "def-server.AlertsClient",
|
||||
"text": "AlertsClient"
|
||||
"section": "def-server.RulesClient",
|
||||
"text": "RulesClient"
|
||||
},
|
||||
", \"get\" | \"delete\" | \"create\" | \"find\" | \"update\" | \"aggregate\" | \"enable\" | \"disable\" | \"muteAll\" | \"getAlertState\" | \"getAlertInstanceSummary\" | \"updateApiKey\" | \"unmuteAll\" | \"muteInstance\" | \"unmuteInstance\" | \"listAlertTypes\">"
|
||||
],
|
||||
|
@ -1375,7 +1375,7 @@
|
|||
"children": [
|
||||
{
|
||||
"parentPluginId": "alerting",
|
||||
"id": "def-server.PluginStartContract.getAlertsClientWithRequest.$1",
|
||||
"id": "def-server.PluginStartContract.getRulesClientWithRequest.$1",
|
||||
"type": "Object",
|
||||
"tags": [],
|
||||
"label": "request",
|
||||
|
@ -1571,10 +1571,10 @@
|
|||
},
|
||||
{
|
||||
"parentPluginId": "alerting",
|
||||
"id": "def-server.AlertsClient",
|
||||
"id": "def-server.RulesClient",
|
||||
"type": "Type",
|
||||
"tags": [],
|
||||
"label": "AlertsClient",
|
||||
"label": "RulesClient",
|
||||
"description": [],
|
||||
"signature": [
|
||||
"{ get: <Params extends Record<string, unknown> = never>({ id, }: { id: string; }) => Promise<Pick<",
|
||||
|
|
|
@ -26,8 +26,8 @@ warning: This document is auto-generated and is meant to be viewed inside our ex
|
|||
| <DocLink id="kibSecurityPluginApi" section="def-server.LegacyAuditLogger" text="LegacyAuditLogger"/> | [audit_logger.ts#L8](https://github.com/elastic/kibana/tree/master/x-pack/plugins/alerting/server/authorization/audit_logger.ts#L8) | - |
|
||||
| <DocLink id="kibSecurityPluginApi" section="def-server.LegacyAuditLogger" text="LegacyAuditLogger"/> | [audit_logger.ts#L21](https://github.com/elastic/kibana/tree/master/x-pack/plugins/alerting/server/authorization/audit_logger.ts#L21) | - |
|
||||
| <DocLink id="kibSecurityPluginApi" section="def-server.LegacyAuditLogger" text="LegacyAuditLogger"/> | [audit_logger.ts#L23](https://github.com/elastic/kibana/tree/master/x-pack/plugins/alerting/server/authorization/audit_logger.ts#L23) | - |
|
||||
| <DocLink id="kibSecurityPluginApi" section="def-server.LegacyAuditLogger" text="LegacyAuditLogger"/> | [alerts_client_factory.test.ts#L23](https://github.com/elastic/kibana/tree/master/x-pack/plugins/alerting/server/alerts_client_factory.test.ts#L23) | - |
|
||||
| <DocLink id="kibSecurityPluginApi" section="def-server.LegacyAuditLogger" text="LegacyAuditLogger"/> | [alerts_client_factory.test.ts#L98](https://github.com/elastic/kibana/tree/master/x-pack/plugins/alerting/server/alerts_client_factory.test.ts#L98) | - |
|
||||
| <DocLink id="kibSecurityPluginApi" section="def-server.LegacyAuditLogger" text="LegacyAuditLogger"/> | [rules_client_factory.test.ts#L23](https://github.com/elastic/kibana/tree/master/x-pack/plugins/alerting/server/rules_client_factory.test.ts#L23) | - |
|
||||
| <DocLink id="kibSecurityPluginApi" section="def-server.LegacyAuditLogger" text="LegacyAuditLogger"/> | [rules_client_factory.test.ts#L98](https://github.com/elastic/kibana/tree/master/x-pack/plugins/alerting/server/rules_client_factory.test.ts#L98) | - |
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1739,14 +1739,14 @@
|
|||
{
|
||||
"plugin": "alerting",
|
||||
"link": {
|
||||
"path": "x-pack/plugins/alerting/server/alerts_client_factory.test.ts",
|
||||
"path": "x-pack/plugins/alerting/server/rules_client_factory.test.ts",
|
||||
"lineNumber": 23
|
||||
}
|
||||
},
|
||||
{
|
||||
"plugin": "alerting",
|
||||
"link": {
|
||||
"path": "x-pack/plugins/alerting/server/alerts_client_factory.test.ts",
|
||||
"path": "x-pack/plugins/alerting/server/rules_client_factory.test.ts",
|
||||
"lineNumber": 98
|
||||
}
|
||||
}
|
||||
|
|
|
@ -639,7 +639,7 @@ Finally, all users, whether they're granted any role or not, are privileged to c
|
|||
|
||||
- `listAlertTypes`, but the output is limited to displaying the rule types the user is privileged to `get`.
|
||||
|
||||
Attempting to execute any operation the user isn't privileged to execute will result in an Authorization error thrown by the AlertsClient.
|
||||
Attempting to execute any operation the user isn't privileged to execute will result in an Authorization error thrown by the RulesClient.
|
||||
|
||||
## Alert Navigation
|
||||
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
*/
|
||||
|
||||
import type { PublicMethodsOf } from '@kbn/utility-types';
|
||||
import { AlertsClient as AlertsClientClass } from './alerts_client';
|
||||
import { RulesClient as RulesClientClass } from './rules_client';
|
||||
import { PluginConfigDescriptor, PluginInitializerContext } from '../../../../src/core/server';
|
||||
import { AlertingPlugin } from './plugin';
|
||||
import { configSchema } from './config';
|
||||
import { AlertsConfigType } from './types';
|
||||
|
||||
export type AlertsClient = PublicMethodsOf<AlertsClientClass>;
|
||||
export type RulesClient = PublicMethodsOf<RulesClientClass>;
|
||||
|
||||
export type {
|
||||
AlertType,
|
||||
|
@ -32,7 +32,7 @@ export type {
|
|||
} from './types';
|
||||
export { DEFAULT_MAX_EPHEMERAL_ACTIONS_PER_ALERT } from './config';
|
||||
export { PluginSetupContract, PluginStartContract } from './plugin';
|
||||
export { FindResult } from './alerts_client';
|
||||
export { FindResult } from './rules_client';
|
||||
export { PublicAlertInstance as AlertInstance } from './alert_instance';
|
||||
export { parseDuration } from './lib';
|
||||
export { getEsErrorMessage } from './lib/errors';
|
||||
|
|
|
@ -19,7 +19,7 @@ import {
|
|||
TaskManagerSetupContract,
|
||||
TaskManagerStartContract,
|
||||
} from '../../../task_manager/server';
|
||||
import { InvalidateAPIKeyResult } from '../alerts_client';
|
||||
import { InvalidateAPIKeyResult } from '../rules_client';
|
||||
import { AlertsConfig } from '../config';
|
||||
import { timePeriodBeforeDate } from '../lib/get_cadence';
|
||||
import { AlertingPluginsStart } from '../plugin';
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { alertsClientMock } from './alerts_client.mock';
|
||||
import { rulesClientMock } from './rules_client.mock';
|
||||
import { PluginSetupContract, PluginStartContract } from './plugin';
|
||||
import { AlertInstance } from './alert_instance';
|
||||
import {
|
||||
|
@ -14,7 +14,7 @@ import {
|
|||
} from '../../../../src/core/server/mocks';
|
||||
import { AlertInstanceContext, AlertInstanceState } from './types';
|
||||
|
||||
export { alertsClientMock };
|
||||
export { rulesClientMock };
|
||||
|
||||
const createSetupMock = () => {
|
||||
const mock: jest.Mocked<PluginSetupContract> = {
|
||||
|
@ -27,7 +27,7 @@ const createStartMock = () => {
|
|||
const mock: jest.Mocked<PluginStartContract> = {
|
||||
listTypes: jest.fn(),
|
||||
getAlertingAuthorizationWithRequest: jest.fn(),
|
||||
getAlertsClientWithRequest: jest.fn().mockResolvedValue(alertsClientMock.create()),
|
||||
getRulesClientWithRequest: jest.fn().mockResolvedValue(rulesClientMock.create()),
|
||||
getFrameworkHealth: jest.fn(),
|
||||
};
|
||||
return mock;
|
||||
|
|
|
@ -113,7 +113,7 @@ describe('Alerting Plugin', () => {
|
|||
});
|
||||
|
||||
describe('start()', () => {
|
||||
describe('getAlertsClientWithRequest()', () => {
|
||||
describe('getRulesClientWithRequest()', () => {
|
||||
it('throws error when encryptedSavedObjects plugin is missing encryption key', async () => {
|
||||
const context = coreMock.createPluginInitializerContext<AlertsConfig>({
|
||||
healthCheck: {
|
||||
|
@ -148,7 +148,7 @@ describe('Alerting Plugin', () => {
|
|||
|
||||
expect(encryptedSavedObjectsSetup.canEncrypt).toEqual(false);
|
||||
expect(() =>
|
||||
startContract.getAlertsClientWithRequest({} as KibanaRequest)
|
||||
startContract.getRulesClientWithRequest({} as KibanaRequest)
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Unable to create alerts client because the Encrypted Saved Objects plugin is missing encryption key. Please set xpack.encryptedSavedObjects.encryptionKey in the kibana.yml or use the bin/kibana-encryption-keys command."`
|
||||
);
|
||||
|
@ -204,7 +204,7 @@ describe('Alerting Plugin', () => {
|
|||
},
|
||||
getSavedObjectsClient: jest.fn(),
|
||||
} as unknown) as KibanaRequest;
|
||||
startContract.getAlertsClientWithRequest(fakeRequest);
|
||||
startContract.getRulesClientWithRequest(fakeRequest);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -17,10 +17,10 @@ import {
|
|||
} from '../../encrypted_saved_objects/server';
|
||||
import { TaskManagerSetupContract, TaskManagerStartContract } from '../../task_manager/server';
|
||||
import { SpacesPluginStart } from '../../spaces/server';
|
||||
import { AlertsClient } from './alerts_client';
|
||||
import { RulesClient } from './rules_client';
|
||||
import { AlertTypeRegistry } from './alert_type_registry';
|
||||
import { TaskRunnerFactory } from './task_runner';
|
||||
import { AlertsClientFactory } from './alerts_client_factory';
|
||||
import { RulesClientFactory } from './rules_client_factory';
|
||||
import { ILicenseState, LicenseState } from './lib/license_state';
|
||||
import {
|
||||
KibanaRequest,
|
||||
|
@ -108,7 +108,7 @@ export interface PluginSetupContract {
|
|||
|
||||
export interface PluginStartContract {
|
||||
listTypes: AlertTypeRegistry['list'];
|
||||
getAlertsClientWithRequest(request: KibanaRequest): PublicMethodsOf<AlertsClient>;
|
||||
getRulesClientWithRequest(request: KibanaRequest): PublicMethodsOf<RulesClient>;
|
||||
getAlertingAuthorizationWithRequest(
|
||||
request: KibanaRequest
|
||||
): PublicMethodsOf<AlertingAuthorization>;
|
||||
|
@ -144,7 +144,7 @@ export class AlertingPlugin {
|
|||
private licenseState: ILicenseState | null = null;
|
||||
private isESOCanEncrypt?: boolean;
|
||||
private security?: SecurityPluginSetup;
|
||||
private readonly alertsClientFactory: AlertsClientFactory;
|
||||
private readonly rulesClientFactory: RulesClientFactory;
|
||||
private readonly alertingAuthorizationClientFactory: AlertingAuthorizationClientFactory;
|
||||
private readonly telemetryLogger: Logger;
|
||||
private readonly kibanaVersion: PluginInitializerContext['env']['packageInfo']['version'];
|
||||
|
@ -157,7 +157,7 @@ export class AlertingPlugin {
|
|||
this.config = initializerContext.config.create<AlertsConfig>().pipe(first()).toPromise();
|
||||
this.logger = initializerContext.logger.get();
|
||||
this.taskRunnerFactory = new TaskRunnerFactory();
|
||||
this.alertsClientFactory = new AlertsClientFactory();
|
||||
this.rulesClientFactory = new RulesClientFactory();
|
||||
this.alertingAuthorizationClientFactory = new AlertingAuthorizationClientFactory();
|
||||
this.telemetryLogger = initializerContext.logger.get('usage');
|
||||
this.kibanaIndexConfig = initializerContext.config.legacy.globalConfig$;
|
||||
|
@ -310,7 +310,7 @@ export class AlertingPlugin {
|
|||
logger,
|
||||
taskRunnerFactory,
|
||||
alertTypeRegistry,
|
||||
alertsClientFactory,
|
||||
rulesClientFactory,
|
||||
alertingAuthorizationClientFactory,
|
||||
security,
|
||||
licenseState,
|
||||
|
@ -338,7 +338,7 @@ export class AlertingPlugin {
|
|||
features: plugins.features,
|
||||
});
|
||||
|
||||
alertsClientFactory.initialize({
|
||||
rulesClientFactory.initialize({
|
||||
alertTypeRegistry: alertTypeRegistry!,
|
||||
logger,
|
||||
taskManager: plugins.taskManager,
|
||||
|
@ -355,13 +355,13 @@ export class AlertingPlugin {
|
|||
authorization: alertingAuthorizationClientFactory,
|
||||
});
|
||||
|
||||
const getAlertsClientWithRequest = (request: KibanaRequest) => {
|
||||
const getRulesClientWithRequest = (request: KibanaRequest) => {
|
||||
if (isESOCanEncrypt !== true) {
|
||||
throw new Error(
|
||||
`Unable to create alerts client because the Encrypted Saved Objects plugin is missing encryption key. Please set xpack.encryptedSavedObjects.encryptionKey in the kibana.yml or use the bin/kibana-encryption-keys command.`
|
||||
);
|
||||
}
|
||||
return alertsClientFactory!.create(request, core.savedObjects);
|
||||
return rulesClientFactory!.create(request, core.savedObjects);
|
||||
};
|
||||
|
||||
const getAlertingAuthorizationWithRequest = (request: KibanaRequest) => {
|
||||
|
@ -371,7 +371,7 @@ export class AlertingPlugin {
|
|||
taskRunnerFactory.initialize({
|
||||
logger,
|
||||
getServices: this.getServicesFactory(core.savedObjects, core.elasticsearch),
|
||||
getAlertsClientWithRequest,
|
||||
getRulesClientWithRequest,
|
||||
spaceIdToNamespace,
|
||||
actionsPlugin: plugins.actions,
|
||||
encryptedSavedObjectsClient,
|
||||
|
@ -385,7 +385,7 @@ export class AlertingPlugin {
|
|||
});
|
||||
|
||||
this.eventLogService!.registerSavedObjectProvider('alert', (request) => {
|
||||
const client = getAlertsClientWithRequest(request);
|
||||
const client = getRulesClientWithRequest(request);
|
||||
return (objects?: SavedObjectsBulkGetObject[]) =>
|
||||
objects
|
||||
? Promise.all(objects.map(async (objectItem) => await client.get({ id: objectItem.id })))
|
||||
|
@ -400,7 +400,7 @@ export class AlertingPlugin {
|
|||
return {
|
||||
listTypes: alertTypeRegistry!.list.bind(this.alertTypeRegistry!),
|
||||
getAlertingAuthorizationWithRequest,
|
||||
getAlertsClientWithRequest,
|
||||
getRulesClientWithRequest,
|
||||
getFrameworkHealth: async () =>
|
||||
await getHealth(core.savedObjects.createInternalRepository(['alert'])),
|
||||
};
|
||||
|
@ -409,12 +409,12 @@ export class AlertingPlugin {
|
|||
private createRouteHandlerContext = (
|
||||
core: CoreSetup<AlertingPluginsStart, unknown>
|
||||
): IContextProvider<AlertingRequestHandlerContext, 'alerting'> => {
|
||||
const { alertTypeRegistry, alertsClientFactory } = this;
|
||||
const { alertTypeRegistry, rulesClientFactory } = this;
|
||||
return async function alertsRouteHandlerContext(context, request) {
|
||||
const [{ savedObjects }] = await core.getStartServices();
|
||||
return {
|
||||
getAlertsClient: () => {
|
||||
return alertsClientFactory!.create(request, savedObjects);
|
||||
getRulesClient: () => {
|
||||
return rulesClientFactory!.create(request, savedObjects);
|
||||
},
|
||||
listTypes: alertTypeRegistry!.list.bind(alertTypeRegistry!),
|
||||
getFrameworkHealth: async () =>
|
||||
|
|
|
@ -9,18 +9,18 @@ import { KibanaRequest, KibanaResponseFactory } from 'kibana/server';
|
|||
import { identity } from 'lodash';
|
||||
import type { MethodKeysOf } from '@kbn/utility-types';
|
||||
import { httpServerMock } from '../../../../../src/core/server/mocks';
|
||||
import { alertsClientMock, AlertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock, RulesClientMock } from '../rules_client.mock';
|
||||
import { AlertsHealth, AlertType } from '../../common';
|
||||
import type { AlertingRequestHandlerContext } from '../types';
|
||||
|
||||
export function mockHandlerArguments(
|
||||
{
|
||||
alertsClient = alertsClientMock.create(),
|
||||
rulesClient = rulesClientMock.create(),
|
||||
listTypes: listTypesRes = [],
|
||||
getFrameworkHealth,
|
||||
areApiKeysEnabled,
|
||||
}: {
|
||||
alertsClient?: AlertsClientMock;
|
||||
rulesClient?: RulesClientMock;
|
||||
listTypes?: AlertType[];
|
||||
getFrameworkHealth?: jest.MockInstance<Promise<AlertsHealth>, []> &
|
||||
(() => Promise<AlertsHealth>);
|
||||
|
@ -38,8 +38,8 @@ export function mockHandlerArguments(
|
|||
({
|
||||
alerting: {
|
||||
listTypes,
|
||||
getAlertsClient() {
|
||||
return alertsClient || alertsClientMock.create();
|
||||
getRulesClient() {
|
||||
return rulesClient || rulesClientMock.create();
|
||||
},
|
||||
getFrameworkHealth,
|
||||
areApiKeysEnabled: areApiKeysEnabled ? areApiKeysEnabled : () => Promise.resolve(true),
|
||||
|
|
|
@ -10,9 +10,9 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -42,10 +42,10 @@ describe('aggregateRulesRoute', () => {
|
|||
unknown: 0,
|
||||
},
|
||||
};
|
||||
alertsClient.aggregate.mockResolvedValueOnce(aggregateResult);
|
||||
rulesClient.aggregate.mockResolvedValueOnce(aggregateResult);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
query: {
|
||||
default_search_operator: 'AND',
|
||||
|
@ -68,8 +68,8 @@ describe('aggregateRulesRoute', () => {
|
|||
}
|
||||
`);
|
||||
|
||||
expect(alertsClient.aggregate).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.aggregate.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.aggregate).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.aggregate.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"options": Object {
|
||||
|
@ -100,7 +100,7 @@ describe('aggregateRulesRoute', () => {
|
|||
|
||||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
alertsClient.aggregate.mockResolvedValueOnce({
|
||||
rulesClient.aggregate.mockResolvedValueOnce({
|
||||
alertExecutionStatus: {
|
||||
ok: 15,
|
||||
error: 2,
|
||||
|
@ -111,7 +111,7 @@ describe('aggregateRulesRoute', () => {
|
|||
});
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
query: {
|
||||
default_search_operator: 'OR',
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { ILicenseState } from '../lib';
|
||||
import { AggregateResult, AggregateOptions } from '../alerts_client';
|
||||
import { AggregateResult, AggregateOptions } from '../rules_client';
|
||||
import { RewriteResponseCase, RewriteRequestCase, verifyAccessAndContext } from './lib';
|
||||
import { AlertingRequestHandlerContext, INTERNAL_BASE_ALERTING_API_PATH } from '../types';
|
||||
|
||||
|
@ -64,12 +64,12 @@ export const aggregateRulesRoute = (
|
|||
},
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const options = rewriteQueryReq({
|
||||
...req.query,
|
||||
has_reference: req.query.has_reference || undefined,
|
||||
});
|
||||
const aggregateResult = await alertsClient.aggregate({ options });
|
||||
const aggregateResult = await rulesClient.aggregate({ options });
|
||||
return res.ok({
|
||||
body: rewriteBodyRes(aggregateResult),
|
||||
});
|
||||
|
|
|
@ -11,13 +11,13 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { CreateOptions } from '../alerts_client';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { CreateOptions } from '../rules_client';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../lib';
|
||||
import { AsApiContract } from './lib';
|
||||
import { SanitizedAlert } from '../types';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -112,10 +112,10 @@ describe('createRuleRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerting/rule/{id?}"`);
|
||||
|
||||
alertsClient.create.mockResolvedValueOnce(mockedAlert);
|
||||
rulesClient.create.mockResolvedValueOnce(mockedAlert);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
body: ruleToCreate,
|
||||
},
|
||||
|
@ -124,8 +124,8 @@ describe('createRuleRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual({ body: createResult });
|
||||
|
||||
expect(alertsClient.create).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.create.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.create).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.create.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"data": Object {
|
||||
|
@ -180,13 +180,13 @@ describe('createRuleRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerting/rule/{id?}"`);
|
||||
|
||||
alertsClient.create.mockResolvedValueOnce({
|
||||
rulesClient.create.mockResolvedValueOnce({
|
||||
...mockedAlert,
|
||||
id: 'custom-id',
|
||||
});
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: { id: 'custom-id' },
|
||||
body: ruleToCreate,
|
||||
|
@ -196,8 +196,8 @@ describe('createRuleRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual({ body: expectedResult });
|
||||
|
||||
expect(alertsClient.create).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.create.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.create).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.create.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"data": Object {
|
||||
|
@ -246,9 +246,9 @@ describe('createRuleRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.create.mockResolvedValueOnce(mockedAlert);
|
||||
rulesClient.create.mockResolvedValueOnce(mockedAlert);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { body: ruleToCreate });
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { body: ruleToCreate });
|
||||
|
||||
await handler(context, req, res);
|
||||
|
||||
|
@ -267,9 +267,9 @@ describe('createRuleRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.create.mockResolvedValueOnce(mockedAlert);
|
||||
rulesClient.create.mockResolvedValueOnce(mockedAlert);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, {});
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, {});
|
||||
|
||||
expect(handler(context, req, res)).rejects.toMatchInlineSnapshot(`[Error: OMG]`);
|
||||
|
||||
|
@ -284,9 +284,9 @@ describe('createRuleRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.create.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
rulesClient.create.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { body: ruleToCreate }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { body: ruleToCreate }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { validateDurationSchema, ILicenseState, AlertTypeDisabledError } from '../lib';
|
||||
import { CreateOptions } from '../alerts_client';
|
||||
import { CreateOptions } from '../rules_client';
|
||||
import {
|
||||
RewriteRequestCase,
|
||||
RewriteResponseCase,
|
||||
|
@ -112,11 +112,11 @@ export const createRuleRoute = (
|
|||
handleDisabledApiKeysError(
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const rule = req.body;
|
||||
const params = req.params;
|
||||
try {
|
||||
const createdRule: SanitizedAlert<AlertTypeParams> = await alertsClient.create<AlertTypeParams>(
|
||||
const createdRule: SanitizedAlert<AlertTypeParams> = await rulesClient.create<AlertTypeParams>(
|
||||
{
|
||||
data: rewriteBodyReq({
|
||||
...rule,
|
||||
|
|
|
@ -10,9 +10,9 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -33,10 +33,10 @@ describe('deleteRuleRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerting/rule/{id}"`);
|
||||
|
||||
alertsClient.delete.mockResolvedValueOnce({});
|
||||
rulesClient.delete.mockResolvedValueOnce({});
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -47,8 +47,8 @@ describe('deleteRuleRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.delete).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.delete.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.delete).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.delete.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -67,10 +67,10 @@ describe('deleteRuleRoute', () => {
|
|||
|
||||
const [, handler] = router.delete.mock.calls[0];
|
||||
|
||||
alertsClient.delete.mockResolvedValueOnce({});
|
||||
rulesClient.delete.mockResolvedValueOnce({});
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: { id: '1' },
|
||||
}
|
||||
|
@ -93,10 +93,10 @@ describe('deleteRuleRoute', () => {
|
|||
|
||||
const [, handler] = router.delete.mock.calls[0];
|
||||
|
||||
alertsClient.delete.mockResolvedValueOnce({});
|
||||
rulesClient.delete.mockResolvedValueOnce({});
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
id: '1',
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ export const deleteRuleRoute = (
|
|||
},
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
await alertsClient.delete({ id });
|
||||
await rulesClient.delete({ id });
|
||||
return res.noContent();
|
||||
})
|
||||
)
|
||||
|
|
|
@ -9,10 +9,10 @@ import { disableRuleRoute } from './disable_rule';
|
|||
import { httpServiceMock } from 'src/core/server/mocks';
|
||||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -33,10 +33,10 @@ describe('disableRuleRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerting/rule/{id}/_disable"`);
|
||||
|
||||
alertsClient.disable.mockResolvedValueOnce();
|
||||
rulesClient.disable.mockResolvedValueOnce();
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -47,8 +47,8 @@ describe('disableRuleRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.disable).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.disable.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.disable).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.disable.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -67,9 +67,9 @@ describe('disableRuleRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.disable.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
rulesClient.disable.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -28,10 +28,10 @@ export const disableRuleRoute = (
|
|||
},
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
try {
|
||||
await alertsClient.disable({ id });
|
||||
await rulesClient.disable({ id });
|
||||
return res.noContent();
|
||||
} catch (e) {
|
||||
if (e instanceof AlertTypeDisabledError) {
|
||||
|
|
|
@ -9,10 +9,10 @@ import { enableRuleRoute } from './enable_rule';
|
|||
import { httpServiceMock } from 'src/core/server/mocks';
|
||||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -33,10 +33,10 @@ describe('enableRuleRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerting/rule/{id}/_enable"`);
|
||||
|
||||
alertsClient.enable.mockResolvedValueOnce();
|
||||
rulesClient.enable.mockResolvedValueOnce();
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -47,8 +47,8 @@ describe('enableRuleRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.enable).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.enable.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.enable).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.enable.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -67,9 +67,9 @@ describe('enableRuleRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.enable.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
rulesClient.enable.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -28,10 +28,10 @@ export const enableRuleRoute = (
|
|||
},
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
try {
|
||||
await alertsClient.enable({ id });
|
||||
await rulesClient.enable({ id });
|
||||
return res.noContent();
|
||||
} catch (e) {
|
||||
if (e instanceof AlertTypeDisabledError) {
|
||||
|
|
|
@ -10,9 +10,9 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -39,10 +39,10 @@ describe('findRulesRoute', () => {
|
|||
total: 0,
|
||||
data: [],
|
||||
};
|
||||
alertsClient.find.mockResolvedValueOnce(findResult);
|
||||
rulesClient.find.mockResolvedValueOnce(findResult);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
query: {
|
||||
per_page: 1,
|
||||
|
@ -64,8 +64,8 @@ describe('findRulesRoute', () => {
|
|||
}
|
||||
`);
|
||||
|
||||
expect(alertsClient.find).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.find.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.find).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.find.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"options": Object {
|
||||
|
@ -95,7 +95,7 @@ describe('findRulesRoute', () => {
|
|||
|
||||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
alertsClient.find.mockResolvedValueOnce({
|
||||
rulesClient.find.mockResolvedValueOnce({
|
||||
page: 1,
|
||||
perPage: 1,
|
||||
total: 0,
|
||||
|
@ -103,7 +103,7 @@ describe('findRulesRoute', () => {
|
|||
});
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
query: {
|
||||
per_page: 1,
|
||||
|
|
|
@ -9,7 +9,7 @@ import { omit } from 'lodash';
|
|||
import { IRouter } from 'kibana/server';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { ILicenseState } from '../lib';
|
||||
import { FindOptions, FindResult } from '../alerts_client';
|
||||
import { FindOptions, FindResult } from '../rules_client';
|
||||
import { RewriteRequestCase, RewriteResponseCase, verifyAccessAndContext } from './lib';
|
||||
import { AlertTypeParams, AlertingRequestHandlerContext, BASE_ALERTING_API_PATH } from '../types';
|
||||
|
||||
|
@ -118,7 +118,7 @@ export const findRulesRoute = (
|
|||
},
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
|
||||
const options = rewriteQueryReq({
|
||||
...req.query,
|
||||
|
@ -126,7 +126,7 @@ export const findRulesRoute = (
|
|||
search_fields: searchFieldsAsArray(req.query.search_fields),
|
||||
});
|
||||
|
||||
const findResult = await alertsClient.find({ options });
|
||||
const findResult = await rulesClient.find({ options });
|
||||
return res.ok({
|
||||
body: rewriteBodyRes(findResult),
|
||||
});
|
||||
|
|
|
@ -11,11 +11,11 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
import { SanitizedAlert } from '../types';
|
||||
import { AsApiContract } from './lib';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -98,10 +98,10 @@ describe('getRuleRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerting/rule/{id}"`);
|
||||
|
||||
alertsClient.get.mockResolvedValueOnce(mockedAlert);
|
||||
rulesClient.get.mockResolvedValueOnce(mockedAlert);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: { id: '1' },
|
||||
},
|
||||
|
@ -109,8 +109,8 @@ describe('getRuleRoute', () => {
|
|||
);
|
||||
await handler(context, req, res);
|
||||
|
||||
expect(alertsClient.get).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.get.mock.calls[0][0].id).toEqual('1');
|
||||
expect(rulesClient.get).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.get.mock.calls[0][0].id).toEqual('1');
|
||||
|
||||
expect(res.ok).toHaveBeenCalledWith({
|
||||
body: getResult,
|
||||
|
@ -125,10 +125,10 @@ describe('getRuleRoute', () => {
|
|||
|
||||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
alertsClient.get.mockResolvedValueOnce(mockedAlert);
|
||||
rulesClient.get.mockResolvedValueOnce(mockedAlert);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: { id: '1' },
|
||||
},
|
||||
|
@ -152,10 +152,10 @@ describe('getRuleRoute', () => {
|
|||
|
||||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
alertsClient.get.mockResolvedValueOnce(mockedAlert);
|
||||
rulesClient.get.mockResolvedValueOnce(mockedAlert);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: { id: '1' },
|
||||
},
|
||||
|
|
|
@ -72,9 +72,9 @@ export const getRuleRoute = (
|
|||
},
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
const rule = await alertsClient.get({ id });
|
||||
const rule = await rulesClient.get({ id });
|
||||
return res.ok({
|
||||
body: rewriteBodyRes(rule),
|
||||
});
|
||||
|
|
|
@ -10,10 +10,10 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { SavedObjectsErrorHelpers } from 'src/core/server';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
import { AlertInstanceSummary } from '../types';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -50,10 +50,10 @@ describe('getRuleAlertSummaryRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/internal/alerting/rule/{id}/_alert_summary"`);
|
||||
|
||||
alertsClient.getAlertInstanceSummary.mockResolvedValueOnce(mockedAlertInstanceSummary);
|
||||
rulesClient.getAlertInstanceSummary.mockResolvedValueOnce(mockedAlertInstanceSummary);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -65,8 +65,8 @@ describe('getRuleAlertSummaryRoute', () => {
|
|||
|
||||
await handler(context, req, res);
|
||||
|
||||
expect(alertsClient.getAlertInstanceSummary).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.getAlertInstanceSummary.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.getAlertInstanceSummary).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.getAlertInstanceSummary.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"dateStart": undefined,
|
||||
|
@ -86,12 +86,12 @@ describe('getRuleAlertSummaryRoute', () => {
|
|||
|
||||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
alertsClient.getAlertInstanceSummary = jest
|
||||
rulesClient.getAlertInstanceSummary = jest
|
||||
.fn()
|
||||
.mockResolvedValueOnce(SavedObjectsErrorHelpers.createGenericNotFoundError('alert', '1'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { ILicenseState } from '../lib';
|
||||
import { GetAlertInstanceSummaryParams } from '../alerts_client';
|
||||
import { GetAlertInstanceSummaryParams } from '../rules_client';
|
||||
import { RewriteRequestCase, RewriteResponseCase, verifyAccessAndContext } from './lib';
|
||||
import {
|
||||
AlertingRequestHandlerContext,
|
||||
|
@ -65,11 +65,9 @@ export const getRuleAlertSummaryRoute = (
|
|||
},
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
const summary = await alertsClient.getAlertInstanceSummary(
|
||||
rewriteReq({ id, ...req.query })
|
||||
);
|
||||
const summary = await rulesClient.getAlertInstanceSummary(rewriteReq({ id, ...req.query }));
|
||||
return res.ok({ body: rewriteBodyRes(summary) });
|
||||
})
|
||||
)
|
||||
|
|
|
@ -10,9 +10,9 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { SavedObjectsErrorHelpers } from 'src/core/server';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -50,10 +50,10 @@ describe('getRuleStateRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/internal/alerting/rule/{id}/state"`);
|
||||
|
||||
alertsClient.getAlertState.mockResolvedValueOnce(mockedAlertState);
|
||||
rulesClient.getAlertState.mockResolvedValueOnce(mockedAlertState);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -64,8 +64,8 @@ describe('getRuleStateRoute', () => {
|
|||
|
||||
await handler(context, req, res);
|
||||
|
||||
expect(alertsClient.getAlertState).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.getAlertState.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.getAlertState).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.getAlertState.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -86,10 +86,10 @@ describe('getRuleStateRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/internal/alerting/rule/{id}/state"`);
|
||||
|
||||
alertsClient.getAlertState.mockResolvedValueOnce(undefined);
|
||||
rulesClient.getAlertState.mockResolvedValueOnce(undefined);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -100,8 +100,8 @@ describe('getRuleStateRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.getAlertState).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.getAlertState.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.getAlertState).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.getAlertState.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -122,12 +122,12 @@ describe('getRuleStateRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/internal/alerting/rule/{id}/state"`);
|
||||
|
||||
alertsClient.getAlertState = jest
|
||||
rulesClient.getAlertState = jest
|
||||
.fn()
|
||||
.mockResolvedValueOnce(SavedObjectsErrorHelpers.createGenericNotFoundError('alert', '1'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -138,8 +138,8 @@ describe('getRuleStateRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.getAlertState).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.getAlertState.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.getAlertState).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.getAlertState.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
|
|
@ -44,9 +44,9 @@ export const getRuleStateRoute = (
|
|||
},
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
const state = await alertsClient.getAlertState({ id });
|
||||
const state = await rulesClient.getAlertState({ id });
|
||||
return state ? res.ok({ body: rewriteBodyRes(state) }) : res.noContent();
|
||||
})
|
||||
)
|
||||
|
|
|
@ -11,10 +11,10 @@ import { mockHandlerArguments } from './_mock_handler_arguments';
|
|||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../encrypted_saved_objects/server/mocks';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
import { HealthStatus } from '../types';
|
||||
import { alertsMock } from '../mocks';
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -62,7 +62,7 @@ describe('healthRoute', () => {
|
|||
healthRoute(router, licenseState, encryptedSavedObjects);
|
||||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, {}, ['ok']);
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, {}, ['ok']);
|
||||
|
||||
await handler(context, req, res);
|
||||
|
||||
|
@ -78,7 +78,7 @@ describe('healthRoute', () => {
|
|||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{ rulesClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{},
|
||||
['ok']
|
||||
);
|
||||
|
@ -114,7 +114,7 @@ describe('healthRoute', () => {
|
|||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{ rulesClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{},
|
||||
['ok']
|
||||
);
|
||||
|
@ -150,7 +150,7 @@ describe('healthRoute', () => {
|
|||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{ rulesClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{},
|
||||
['ok']
|
||||
);
|
||||
|
@ -187,7 +187,7 @@ describe('healthRoute', () => {
|
|||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{
|
||||
alertsClient,
|
||||
rulesClient,
|
||||
getFrameworkHealth: alerting.getFrameworkHealth,
|
||||
areApiKeysEnabled: () => Promise.resolve(false),
|
||||
},
|
||||
|
@ -227,7 +227,7 @@ describe('healthRoute', () => {
|
|||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{
|
||||
alertsClient,
|
||||
rulesClient,
|
||||
getFrameworkHealth: alerting.getFrameworkHealth,
|
||||
areApiKeysEnabled: () => Promise.resolve(false),
|
||||
},
|
||||
|
@ -266,7 +266,7 @@ describe('healthRoute', () => {
|
|||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{ rulesClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{},
|
||||
['ok']
|
||||
);
|
||||
|
|
|
@ -10,9 +10,9 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { verifyApiAccess } from '../../lib/license_api_access';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -42,10 +42,10 @@ describe('aggregateAlertRoute', () => {
|
|||
unknown: 0,
|
||||
},
|
||||
};
|
||||
alertsClient.aggregate.mockResolvedValueOnce(aggregateResult);
|
||||
rulesClient.aggregate.mockResolvedValueOnce(aggregateResult);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
query: {
|
||||
default_search_operator: 'AND',
|
||||
|
@ -68,8 +68,8 @@ describe('aggregateAlertRoute', () => {
|
|||
}
|
||||
`);
|
||||
|
||||
expect(alertsClient.aggregate).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.aggregate.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.aggregate).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.aggregate.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"options": Object {
|
||||
|
@ -92,7 +92,7 @@ describe('aggregateAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
alertsClient.aggregate.mockResolvedValueOnce({
|
||||
rulesClient.aggregate.mockResolvedValueOnce({
|
||||
alertExecutionStatus: {
|
||||
ok: 15,
|
||||
error: 2,
|
||||
|
@ -103,7 +103,7 @@ describe('aggregateAlertRoute', () => {
|
|||
});
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
query: {
|
||||
default_search_operator: 'OR',
|
||||
|
|
|
@ -11,7 +11,7 @@ import { ILicenseState } from '../../lib/license_state';
|
|||
import { verifyApiAccess } from '../../lib/license_api_access';
|
||||
import { LEGACY_BASE_ALERT_API_PATH } from '../../../common';
|
||||
import { renameKeys } from './../lib/rename_keys';
|
||||
import { FindOptions } from '../../alerts_client';
|
||||
import { FindOptions } from '../../rules_client';
|
||||
|
||||
// config definition
|
||||
const querySchema = schema.object({
|
||||
|
@ -46,7 +46,7 @@ export const aggregateAlertRoute = (router: AlertingRouter, licenseState: ILicen
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
|
||||
const query = req.query;
|
||||
const renameMap = {
|
||||
|
@ -64,7 +64,7 @@ export const aggregateAlertRoute = (router: AlertingRouter, licenseState: ILicen
|
|||
: [query.search_fields];
|
||||
}
|
||||
|
||||
const aggregateResult = await alertsClient.aggregate({ options });
|
||||
const aggregateResult = await rulesClient.aggregate({ options });
|
||||
return res.ok({
|
||||
body: aggregateResult,
|
||||
});
|
||||
|
|
|
@ -10,11 +10,11 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { verifyApiAccess } from '../../lib/license_api_access';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
import { Alert } from '../../../common/alert';
|
||||
import { AlertTypeDisabledError } from '../../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -85,10 +85,10 @@ describe('createAlertRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id?}"`);
|
||||
|
||||
alertsClient.create.mockResolvedValueOnce(createResult);
|
||||
rulesClient.create.mockResolvedValueOnce(createResult);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
body: mockedAlert,
|
||||
},
|
||||
|
@ -97,8 +97,8 @@ describe('createAlertRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual({ body: createResult });
|
||||
|
||||
expect(alertsClient.create).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.create.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.create).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.create.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"data": Object {
|
||||
|
@ -152,10 +152,10 @@ describe('createAlertRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id?}"`);
|
||||
|
||||
alertsClient.create.mockResolvedValueOnce(expectedResult);
|
||||
rulesClient.create.mockResolvedValueOnce(expectedResult);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: { id: 'custom-id' },
|
||||
body: mockedAlert,
|
||||
|
@ -165,8 +165,8 @@ describe('createAlertRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual({ body: expectedResult });
|
||||
|
||||
expect(alertsClient.create).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.create.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.create).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.create.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"data": Object {
|
||||
|
@ -214,9 +214,9 @@ describe('createAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.create.mockResolvedValueOnce(createResult);
|
||||
rulesClient.create.mockResolvedValueOnce(createResult);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, {});
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, {});
|
||||
|
||||
await handler(context, req, res);
|
||||
|
||||
|
@ -235,9 +235,9 @@ describe('createAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.create.mockResolvedValueOnce(createResult);
|
||||
rulesClient.create.mockResolvedValueOnce(createResult);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, {});
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, {});
|
||||
|
||||
expect(handler(context, req, res)).rejects.toMatchInlineSnapshot(`[Error: OMG]`);
|
||||
|
||||
|
@ -252,9 +252,9 @@ describe('createAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.create.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
rulesClient.create.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, {}, ['ok', 'forbidden']);
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, {}, ['ok', 'forbidden']);
|
||||
|
||||
await handler(context, req, res);
|
||||
|
||||
|
|
|
@ -63,12 +63,12 @@ export const createAlertRoute = (router: AlertingRouter, licenseState: ILicenseS
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const alert = req.body;
|
||||
const params = req.params;
|
||||
const notifyWhen = alert?.notifyWhen ? (alert.notifyWhen as AlertNotifyWhenType) : null;
|
||||
try {
|
||||
const alertRes: SanitizedAlert<AlertTypeParams> = await alertsClient.create<AlertTypeParams>(
|
||||
const alertRes: SanitizedAlert<AlertTypeParams> = await rulesClient.create<AlertTypeParams>(
|
||||
{
|
||||
data: { ...alert, notifyWhen },
|
||||
options: { id: params?.id },
|
||||
|
|
|
@ -10,9 +10,9 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { verifyApiAccess } from '../../lib/license_api_access';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -33,10 +33,10 @@ describe('deleteAlertRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}"`);
|
||||
|
||||
alertsClient.delete.mockResolvedValueOnce({});
|
||||
rulesClient.delete.mockResolvedValueOnce({});
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -47,8 +47,8 @@ describe('deleteAlertRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.delete).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.delete.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.delete).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.delete.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -67,10 +67,10 @@ describe('deleteAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.delete.mock.calls[0];
|
||||
|
||||
alertsClient.delete.mockResolvedValueOnce({});
|
||||
rulesClient.delete.mockResolvedValueOnce({});
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: { id: '1' },
|
||||
}
|
||||
|
@ -93,10 +93,10 @@ describe('deleteAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.delete.mock.calls[0];
|
||||
|
||||
alertsClient.delete.mockResolvedValueOnce({});
|
||||
rulesClient.delete.mockResolvedValueOnce({});
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
id: '1',
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ export const deleteAlertRoute = (router: AlertingRouter, licenseState: ILicenseS
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
await alertsClient.delete({ id });
|
||||
await rulesClient.delete({ id });
|
||||
return res.noContent();
|
||||
})
|
||||
);
|
||||
|
|
|
@ -9,10 +9,10 @@ import { disableAlertRoute } from './disable';
|
|||
import { httpServiceMock } from 'src/core/server/mocks';
|
||||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -33,10 +33,10 @@ describe('disableAlertRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/_disable"`);
|
||||
|
||||
alertsClient.disable.mockResolvedValueOnce();
|
||||
rulesClient.disable.mockResolvedValueOnce();
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -47,8 +47,8 @@ describe('disableAlertRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.disable).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.disable.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.disable).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.disable.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -67,9 +67,9 @@ describe('disableAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.disable.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
rulesClient.disable.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -29,10 +29,10 @@ export const disableAlertRoute = (router: AlertingRouter, licenseState: ILicense
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
try {
|
||||
await alertsClient.disable({ id });
|
||||
await rulesClient.disable({ id });
|
||||
return res.noContent();
|
||||
} catch (e) {
|
||||
if (e instanceof AlertTypeDisabledError) {
|
||||
|
|
|
@ -9,10 +9,10 @@ import { enableAlertRoute } from './enable';
|
|||
import { httpServiceMock } from 'src/core/server/mocks';
|
||||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -33,10 +33,10 @@ describe('enableAlertRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/_enable"`);
|
||||
|
||||
alertsClient.enable.mockResolvedValueOnce();
|
||||
rulesClient.enable.mockResolvedValueOnce();
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -47,8 +47,8 @@ describe('enableAlertRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.enable).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.enable.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.enable).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.enable.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -67,9 +67,9 @@ describe('enableAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.enable.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
rulesClient.enable.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -31,10 +31,10 @@ export const enableAlertRoute = (router: AlertingRouter, licenseState: ILicenseS
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
try {
|
||||
await alertsClient.enable({ id });
|
||||
await rulesClient.enable({ id });
|
||||
return res.noContent();
|
||||
} catch (e) {
|
||||
if (e instanceof AlertTypeDisabledError) {
|
||||
|
|
|
@ -10,9 +10,9 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { verifyApiAccess } from '../../lib/license_api_access';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -39,10 +39,10 @@ describe('findAlertRoute', () => {
|
|||
total: 0,
|
||||
data: [],
|
||||
};
|
||||
alertsClient.find.mockResolvedValueOnce(findResult);
|
||||
rulesClient.find.mockResolvedValueOnce(findResult);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
query: {
|
||||
per_page: 1,
|
||||
|
@ -64,8 +64,8 @@ describe('findAlertRoute', () => {
|
|||
}
|
||||
`);
|
||||
|
||||
expect(alertsClient.find).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.find.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.find).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.find.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"options": Object {
|
||||
|
@ -90,7 +90,7 @@ describe('findAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
alertsClient.find.mockResolvedValueOnce({
|
||||
rulesClient.find.mockResolvedValueOnce({
|
||||
page: 1,
|
||||
perPage: 1,
|
||||
total: 0,
|
||||
|
@ -98,7 +98,7 @@ describe('findAlertRoute', () => {
|
|||
});
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
query: {
|
||||
per_page: 1,
|
||||
|
|
|
@ -12,7 +12,7 @@ import { ILicenseState } from '../../lib/license_state';
|
|||
import { verifyApiAccess } from '../../lib/license_api_access';
|
||||
import { LEGACY_BASE_ALERT_API_PATH } from '../../../common';
|
||||
import { renameKeys } from './../lib/rename_keys';
|
||||
import { FindOptions } from '../../alerts_client';
|
||||
import { FindOptions } from '../../rules_client';
|
||||
|
||||
// config definition
|
||||
const querySchema = schema.object({
|
||||
|
@ -52,7 +52,7 @@ export const findAlertRoute = (router: AlertingRouter, licenseState: ILicenseSta
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
|
||||
const query = req.query;
|
||||
const renameMap = {
|
||||
|
@ -75,7 +75,7 @@ export const findAlertRoute = (router: AlertingRouter, licenseState: ILicenseSta
|
|||
: [query.search_fields];
|
||||
}
|
||||
|
||||
const findResult = await alertsClient.find({ options });
|
||||
const findResult = await rulesClient.find({ options });
|
||||
return res.ok({
|
||||
body: findResult,
|
||||
});
|
||||
|
|
|
@ -10,10 +10,10 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { verifyApiAccess } from '../../lib/license_api_access';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
import { Alert } from '../../../common';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -71,10 +71,10 @@ describe('getAlertRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}"`);
|
||||
|
||||
alertsClient.get.mockResolvedValueOnce(mockedAlert);
|
||||
rulesClient.get.mockResolvedValueOnce(mockedAlert);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: { id: '1' },
|
||||
},
|
||||
|
@ -82,8 +82,8 @@ describe('getAlertRoute', () => {
|
|||
);
|
||||
await handler(context, req, res);
|
||||
|
||||
expect(alertsClient.get).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.get.mock.calls[0][0].id).toEqual('1');
|
||||
expect(rulesClient.get).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.get.mock.calls[0][0].id).toEqual('1');
|
||||
|
||||
expect(res.ok).toHaveBeenCalledWith({
|
||||
body: mockedAlert,
|
||||
|
@ -98,10 +98,10 @@ describe('getAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
alertsClient.get.mockResolvedValueOnce(mockedAlert);
|
||||
rulesClient.get.mockResolvedValueOnce(mockedAlert);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: { id: '1' },
|
||||
},
|
||||
|
@ -125,10 +125,10 @@ describe('getAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
alertsClient.get.mockResolvedValueOnce(mockedAlert);
|
||||
rulesClient.get.mockResolvedValueOnce(mockedAlert);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: { id: '1' },
|
||||
},
|
||||
|
|
|
@ -28,10 +28,10 @@ export const getAlertRoute = (router: AlertingRouter, licenseState: ILicenseStat
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
return res.ok({
|
||||
body: await alertsClient.get({ id }),
|
||||
body: await rulesClient.get({ id }),
|
||||
});
|
||||
})
|
||||
);
|
||||
|
|
|
@ -10,10 +10,10 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { SavedObjectsErrorHelpers } from 'src/core/server';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
import { AlertInstanceSummary } from '../../types';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -50,10 +50,10 @@ describe('getAlertInstanceSummaryRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/_instance_summary"`);
|
||||
|
||||
alertsClient.getAlertInstanceSummary.mockResolvedValueOnce(mockedAlertInstanceSummary);
|
||||
rulesClient.getAlertInstanceSummary.mockResolvedValueOnce(mockedAlertInstanceSummary);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -65,8 +65,8 @@ describe('getAlertInstanceSummaryRoute', () => {
|
|||
|
||||
await handler(context, req, res);
|
||||
|
||||
expect(alertsClient.getAlertInstanceSummary).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.getAlertInstanceSummary.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.getAlertInstanceSummary).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.getAlertInstanceSummary.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"dateStart": undefined,
|
||||
|
@ -86,12 +86,12 @@ describe('getAlertInstanceSummaryRoute', () => {
|
|||
|
||||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
alertsClient.getAlertInstanceSummary = jest
|
||||
rulesClient.getAlertInstanceSummary = jest
|
||||
.fn()
|
||||
.mockResolvedValueOnce(SavedObjectsErrorHelpers.createGenericNotFoundError('alert', '1'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
|
|
@ -36,10 +36,10 @@ export const getAlertInstanceSummaryRoute = (
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
const { dateStart } = req.query;
|
||||
const summary = await alertsClient.getAlertInstanceSummary({ id, dateStart });
|
||||
const summary = await rulesClient.getAlertInstanceSummary({ id, dateStart });
|
||||
return res.ok({ body: summary });
|
||||
})
|
||||
);
|
||||
|
|
|
@ -10,9 +10,9 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { SavedObjectsErrorHelpers } from 'src/core/server';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -50,10 +50,10 @@ describe('getAlertStateRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/state"`);
|
||||
|
||||
alertsClient.getAlertState.mockResolvedValueOnce(mockedAlertState);
|
||||
rulesClient.getAlertState.mockResolvedValueOnce(mockedAlertState);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -64,8 +64,8 @@ describe('getAlertStateRoute', () => {
|
|||
|
||||
await handler(context, req, res);
|
||||
|
||||
expect(alertsClient.getAlertState).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.getAlertState.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.getAlertState).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.getAlertState.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -86,10 +86,10 @@ describe('getAlertStateRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/state"`);
|
||||
|
||||
alertsClient.getAlertState.mockResolvedValueOnce(undefined);
|
||||
rulesClient.getAlertState.mockResolvedValueOnce(undefined);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -100,8 +100,8 @@ describe('getAlertStateRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.getAlertState).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.getAlertState.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.getAlertState).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.getAlertState.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -122,12 +122,12 @@ describe('getAlertStateRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/state"`);
|
||||
|
||||
alertsClient.getAlertState = jest
|
||||
rulesClient.getAlertState = jest
|
||||
.fn()
|
||||
.mockResolvedValueOnce(SavedObjectsErrorHelpers.createGenericNotFoundError('alert', '1'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -138,8 +138,8 @@ describe('getAlertStateRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.getAlertState).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.getAlertState.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.getAlertState).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.getAlertState.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
|
|
@ -28,9 +28,9 @@ export const getAlertStateRoute = (router: AlertingRouter, licenseState: ILicens
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
const state = await alertsClient.getAlertState({ id });
|
||||
const state = await rulesClient.getAlertState({ id });
|
||||
return state ? res.ok({ body: state }) : res.noContent();
|
||||
})
|
||||
);
|
||||
|
|
|
@ -10,10 +10,10 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
import { HealthStatus } from '../../types';
|
||||
import { alertsMock } from '../../mocks';
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -62,7 +62,7 @@ describe('healthRoute', () => {
|
|||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{ rulesClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{},
|
||||
['ok']
|
||||
);
|
||||
|
@ -98,7 +98,7 @@ describe('healthRoute', () => {
|
|||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{ rulesClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{},
|
||||
['ok']
|
||||
);
|
||||
|
@ -134,7 +134,7 @@ describe('healthRoute', () => {
|
|||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{ rulesClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{},
|
||||
['ok']
|
||||
);
|
||||
|
@ -171,7 +171,7 @@ describe('healthRoute', () => {
|
|||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{
|
||||
alertsClient,
|
||||
rulesClient,
|
||||
getFrameworkHealth: alerting.getFrameworkHealth,
|
||||
areApiKeysEnabled: () => Promise.resolve(false),
|
||||
},
|
||||
|
@ -211,7 +211,7 @@ describe('healthRoute', () => {
|
|||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{
|
||||
alertsClient,
|
||||
rulesClient,
|
||||
getFrameworkHealth: alerting.getFrameworkHealth,
|
||||
areApiKeysEnabled: () => Promise.resolve(false),
|
||||
},
|
||||
|
@ -250,7 +250,7 @@ describe('healthRoute', () => {
|
|||
const [, handler] = router.get.mock.calls[0];
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{ rulesClient, getFrameworkHealth: alerting.getFrameworkHealth },
|
||||
{},
|
||||
['ok']
|
||||
);
|
||||
|
|
|
@ -10,11 +10,11 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { verifyApiAccess } from '../../lib/license_api_access';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
import { RecoveredActionGroup } from '../../../common';
|
||||
import { RegistryAlertTypeWithAuth } from '../../authorization';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -58,9 +58,9 @@ describe('listAlertTypesRoute', () => {
|
|||
enabledInLicense: true,
|
||||
} as RegistryAlertTypeWithAuth,
|
||||
];
|
||||
alertsClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));
|
||||
rulesClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, {}, ['ok']);
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, {}, ['ok']);
|
||||
|
||||
expect(await handler(context, req, res)).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
|
@ -93,7 +93,7 @@ describe('listAlertTypesRoute', () => {
|
|||
}
|
||||
`);
|
||||
|
||||
expect(alertsClient.listAlertTypes).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.listAlertTypes).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(res.ok).toHaveBeenCalledWith({
|
||||
body: listTypes,
|
||||
|
@ -134,10 +134,10 @@ describe('listAlertTypesRoute', () => {
|
|||
} as RegistryAlertTypeWithAuth,
|
||||
];
|
||||
|
||||
alertsClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));
|
||||
rulesClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: { id: '1' },
|
||||
},
|
||||
|
@ -187,10 +187,10 @@ describe('listAlertTypesRoute', () => {
|
|||
} as RegistryAlertTypeWithAuth,
|
||||
];
|
||||
|
||||
alertsClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));
|
||||
rulesClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: { id: '1' },
|
||||
},
|
||||
|
|
|
@ -22,7 +22,7 @@ export const listAlertTypesRoute = (router: AlertingRouter, licenseState: ILicen
|
|||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
return res.ok({
|
||||
body: Array.from(await context.alerting.getAlertsClient().listAlertTypes()),
|
||||
body: Array.from(await context.alerting.getRulesClient().listAlertTypes()),
|
||||
});
|
||||
})
|
||||
);
|
||||
|
|
|
@ -9,10 +9,10 @@ import { muteAllAlertRoute } from './mute_all';
|
|||
import { httpServiceMock } from 'src/core/server/mocks';
|
||||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -32,10 +32,10 @@ describe('muteAllAlertRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/_mute_all"`);
|
||||
|
||||
alertsClient.muteAll.mockResolvedValueOnce();
|
||||
rulesClient.muteAll.mockResolvedValueOnce();
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -46,8 +46,8 @@ describe('muteAllAlertRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.muteAll).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.muteAll.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.muteAll).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.muteAll.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -66,9 +66,9 @@ describe('muteAllAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.muteAll.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
rulesClient.muteAll.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -29,10 +29,10 @@ export const muteAllAlertRoute = (router: AlertingRouter, licenseState: ILicense
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
try {
|
||||
await alertsClient.muteAll({ id });
|
||||
await rulesClient.muteAll({ id });
|
||||
return res.noContent();
|
||||
} catch (e) {
|
||||
if (e instanceof AlertTypeDisabledError) {
|
||||
|
|
|
@ -9,10 +9,10 @@ import { muteAlertInstanceRoute } from './mute_instance';
|
|||
import { httpServiceMock } from 'src/core/server/mocks';
|
||||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -34,10 +34,10 @@ describe('muteAlertInstanceRoute', () => {
|
|||
`"/api/alerts/alert/{alert_id}/alert_instance/{alert_instance_id}/_mute"`
|
||||
);
|
||||
|
||||
alertsClient.muteInstance.mockResolvedValueOnce();
|
||||
rulesClient.muteInstance.mockResolvedValueOnce();
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
alert_id: '1',
|
||||
|
@ -49,8 +49,8 @@ describe('muteAlertInstanceRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.muteInstance).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.muteInstance.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.muteInstance).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.muteInstance.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"alertId": "1",
|
||||
|
@ -70,11 +70,11 @@ describe('muteAlertInstanceRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.muteInstance.mockRejectedValue(
|
||||
rulesClient.muteInstance.mockRejectedValue(
|
||||
new AlertTypeDisabledError('Fail', 'license_invalid')
|
||||
);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -11,7 +11,7 @@ import { ILicenseState } from '../../lib/license_state';
|
|||
import { verifyApiAccess } from '../../lib/license_api_access';
|
||||
import { LEGACY_BASE_ALERT_API_PATH } from '../../../common';
|
||||
import { renameKeys } from './../lib/rename_keys';
|
||||
import { MuteOptions } from '../../alerts_client';
|
||||
import { MuteOptions } from '../../rules_client';
|
||||
import { AlertTypeDisabledError } from '../../lib/errors/alert_type_disabled';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
|
@ -32,7 +32,7 @@ export const muteAlertInstanceRoute = (router: AlertingRouter, licenseState: ILi
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
|
||||
const renameMap = {
|
||||
alert_id: 'alertId',
|
||||
|
@ -41,7 +41,7 @@ export const muteAlertInstanceRoute = (router: AlertingRouter, licenseState: ILi
|
|||
|
||||
const renamedQuery = renameKeys<MuteOptions, Record<string, unknown>>(renameMap, req.params);
|
||||
try {
|
||||
await alertsClient.muteInstance(renamedQuery);
|
||||
await rulesClient.muteInstance(renamedQuery);
|
||||
return res.noContent();
|
||||
} catch (e) {
|
||||
if (e instanceof AlertTypeDisabledError) {
|
||||
|
|
|
@ -9,10 +9,10 @@ import { unmuteAllAlertRoute } from './unmute_all';
|
|||
import { httpServiceMock } from 'src/core/server/mocks';
|
||||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -32,10 +32,10 @@ describe('unmuteAllAlertRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/_unmute_all"`);
|
||||
|
||||
alertsClient.unmuteAll.mockResolvedValueOnce();
|
||||
rulesClient.unmuteAll.mockResolvedValueOnce();
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -46,8 +46,8 @@ describe('unmuteAllAlertRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.unmuteAll).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.unmuteAll.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.unmuteAll).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.unmuteAll.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -66,9 +66,9 @@ describe('unmuteAllAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.unmuteAll.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
rulesClient.unmuteAll.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -29,10 +29,10 @@ export const unmuteAllAlertRoute = (router: AlertingRouter, licenseState: ILicen
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
try {
|
||||
await alertsClient.unmuteAll({ id });
|
||||
await rulesClient.unmuteAll({ id });
|
||||
return res.noContent();
|
||||
} catch (e) {
|
||||
if (e instanceof AlertTypeDisabledError) {
|
||||
|
|
|
@ -9,10 +9,10 @@ import { unmuteAlertInstanceRoute } from './unmute_instance';
|
|||
import { httpServiceMock } from 'src/core/server/mocks';
|
||||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -34,10 +34,10 @@ describe('unmuteAlertInstanceRoute', () => {
|
|||
`"/api/alerts/alert/{alertId}/alert_instance/{alertInstanceId}/_unmute"`
|
||||
);
|
||||
|
||||
alertsClient.unmuteInstance.mockResolvedValueOnce();
|
||||
rulesClient.unmuteInstance.mockResolvedValueOnce();
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
alertId: '1',
|
||||
|
@ -49,8 +49,8 @@ describe('unmuteAlertInstanceRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.unmuteInstance).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.unmuteInstance.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.unmuteInstance).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.unmuteInstance.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"alertId": "1",
|
||||
|
@ -70,11 +70,11 @@ describe('unmuteAlertInstanceRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.unmuteInstance.mockRejectedValue(
|
||||
rulesClient.unmuteInstance.mockRejectedValue(
|
||||
new AlertTypeDisabledError('Fail', 'license_invalid')
|
||||
);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -30,10 +30,10 @@ export const unmuteAlertInstanceRoute = (router: AlertingRouter, licenseState: I
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { alertId, alertInstanceId } = req.params;
|
||||
try {
|
||||
await alertsClient.unmuteInstance({ alertId, alertInstanceId });
|
||||
await rulesClient.unmuteInstance({ alertId, alertInstanceId });
|
||||
return res.noContent();
|
||||
} catch (e) {
|
||||
if (e instanceof AlertTypeDisabledError) {
|
||||
|
|
|
@ -10,11 +10,11 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { verifyApiAccess } from '../../lib/license_api_access';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../../lib/errors/alert_type_disabled';
|
||||
import { AlertNotifyWhenType } from '../../../common';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -57,10 +57,10 @@ describe('updateAlertRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}"`);
|
||||
|
||||
alertsClient.update.mockResolvedValueOnce(mockedResponse);
|
||||
rulesClient.update.mockResolvedValueOnce(mockedResponse);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -90,8 +90,8 @@ describe('updateAlertRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual({ body: mockedResponse });
|
||||
|
||||
expect(alertsClient.update).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.update.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.update).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.update.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"data": Object {
|
||||
|
@ -133,10 +133,10 @@ describe('updateAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.put.mock.calls[0];
|
||||
|
||||
alertsClient.update.mockResolvedValueOnce(mockedResponse);
|
||||
rulesClient.update.mockResolvedValueOnce(mockedResponse);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -180,10 +180,10 @@ describe('updateAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.put.mock.calls[0];
|
||||
|
||||
alertsClient.update.mockResolvedValueOnce(mockedResponse);
|
||||
rulesClient.update.mockResolvedValueOnce(mockedResponse);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -223,9 +223,9 @@ describe('updateAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.put.mock.calls[0];
|
||||
|
||||
alertsClient.update.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
rulesClient.update.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -57,11 +57,11 @@ export const updateAlertRoute = (router: AlertingRouter, licenseState: ILicenseS
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
const { name, actions, params, schedule, tags, throttle, notifyWhen } = req.body;
|
||||
try {
|
||||
const alertRes = await alertsClient.update({
|
||||
const alertRes = await rulesClient.update({
|
||||
id,
|
||||
data: {
|
||||
name,
|
||||
|
|
|
@ -9,10 +9,10 @@ import { updateApiKeyRoute } from './update_api_key';
|
|||
import { httpServiceMock } from 'src/core/server/mocks';
|
||||
import { licenseStateMock } from '../../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './../_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../../alerts_client.mock';
|
||||
import { rulesClientMock } from '../../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -32,10 +32,10 @@ describe('updateApiKeyRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerts/alert/{id}/_update_api_key"`);
|
||||
|
||||
alertsClient.updateApiKey.mockResolvedValueOnce();
|
||||
rulesClient.updateApiKey.mockResolvedValueOnce();
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -46,8 +46,8 @@ describe('updateApiKeyRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.updateApiKey).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.updateApiKey.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.updateApiKey).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.updateApiKey.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -66,11 +66,11 @@ describe('updateApiKeyRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.updateApiKey.mockRejectedValue(
|
||||
rulesClient.updateApiKey.mockRejectedValue(
|
||||
new AlertTypeDisabledError('Fail', 'license_invalid')
|
||||
);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -31,10 +31,10 @@ export const updateApiKeyRoute = (router: AlertingRouter, licenseState: ILicense
|
|||
if (!context.alerting) {
|
||||
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
|
||||
}
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
try {
|
||||
await alertsClient.updateApiKey({ id });
|
||||
await rulesClient.updateApiKey({ id });
|
||||
return res.noContent();
|
||||
} catch (e) {
|
||||
if (e instanceof AlertTypeDisabledError) {
|
||||
|
|
|
@ -9,10 +9,10 @@ import { muteAlertRoute } from './mute_alert';
|
|||
import { httpServiceMock } from 'src/core/server/mocks';
|
||||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -34,10 +34,10 @@ describe('muteAlertRoute', () => {
|
|||
`"/api/alerting/rule/{rule_id}/alert/{alert_id}/_mute"`
|
||||
);
|
||||
|
||||
alertsClient.muteInstance.mockResolvedValueOnce();
|
||||
rulesClient.muteInstance.mockResolvedValueOnce();
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
rule_id: '1',
|
||||
|
@ -49,8 +49,8 @@ describe('muteAlertRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.muteInstance).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.muteInstance.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.muteInstance).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.muteInstance.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"alertId": "1",
|
||||
|
@ -70,11 +70,11 @@ describe('muteAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.muteInstance.mockRejectedValue(
|
||||
rulesClient.muteInstance.mockRejectedValue(
|
||||
new AlertTypeDisabledError('Fail', 'license_invalid')
|
||||
);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { ILicenseState, AlertTypeDisabledError } from '../lib';
|
||||
import { MuteOptions } from '../alerts_client';
|
||||
import { MuteOptions } from '../rules_client';
|
||||
import { RewriteRequestCase, verifyAccessAndContext } from './lib';
|
||||
import { AlertingRequestHandlerContext, BASE_ALERTING_API_PATH } from '../types';
|
||||
|
||||
|
@ -38,10 +38,10 @@ export const muteAlertRoute = (
|
|||
},
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const params = rewriteParamsReq(req.params);
|
||||
try {
|
||||
await alertsClient.muteInstance(params);
|
||||
await rulesClient.muteInstance(params);
|
||||
return res.noContent();
|
||||
} catch (e) {
|
||||
if (e instanceof AlertTypeDisabledError) {
|
||||
|
|
|
@ -9,10 +9,10 @@ import { muteAllRuleRoute } from './mute_all_rule';
|
|||
import { httpServiceMock } from 'src/core/server/mocks';
|
||||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -32,10 +32,10 @@ describe('muteAllRuleRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerting/rule/{id}/_mute_all"`);
|
||||
|
||||
alertsClient.muteAll.mockResolvedValueOnce();
|
||||
rulesClient.muteAll.mockResolvedValueOnce();
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -46,8 +46,8 @@ describe('muteAllRuleRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.muteAll).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.muteAll.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.muteAll).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.muteAll.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -66,9 +66,9 @@ describe('muteAllRuleRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.muteAll.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
rulesClient.muteAll.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -28,10 +28,10 @@ export const muteAllRuleRoute = (
|
|||
},
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
try {
|
||||
await alertsClient.muteAll({ id });
|
||||
await rulesClient.muteAll({ id });
|
||||
return res.noContent();
|
||||
} catch (e) {
|
||||
if (e instanceof AlertTypeDisabledError) {
|
||||
|
|
|
@ -10,12 +10,12 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
import { RecoveredActionGroup } from '../../common';
|
||||
import { RegistryAlertTypeWithAuth } from '../authorization';
|
||||
import { AsApiContract } from './lib';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
|
@ -82,9 +82,9 @@ describe('ruleTypesRoute', () => {
|
|||
enabled_in_license: true,
|
||||
},
|
||||
];
|
||||
alertsClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));
|
||||
rulesClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, {}, ['ok']);
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, {}, ['ok']);
|
||||
|
||||
expect(await handler(context, req, res)).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
|
@ -117,7 +117,7 @@ describe('ruleTypesRoute', () => {
|
|||
}
|
||||
`);
|
||||
|
||||
expect(alertsClient.listAlertTypes).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.listAlertTypes).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(res.ok).toHaveBeenCalledWith({
|
||||
body: expectedResult,
|
||||
|
@ -158,10 +158,10 @@ describe('ruleTypesRoute', () => {
|
|||
} as RegistryAlertTypeWithAuth,
|
||||
];
|
||||
|
||||
alertsClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));
|
||||
rulesClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: { id: '1' },
|
||||
},
|
||||
|
@ -211,10 +211,10 @@ describe('ruleTypesRoute', () => {
|
|||
} as RegistryAlertTypeWithAuth,
|
||||
];
|
||||
|
||||
alertsClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));
|
||||
rulesClient.listAlertTypes.mockResolvedValueOnce(new Set(listTypes));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: { id: '1' },
|
||||
},
|
||||
|
|
|
@ -48,7 +48,7 @@ export const ruleTypesRoute = (
|
|||
},
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const ruleTypes = Array.from(await context.alerting.getAlertsClient().listAlertTypes());
|
||||
const ruleTypes = Array.from(await context.alerting.getRulesClient().listAlertTypes());
|
||||
return res.ok({
|
||||
body: rewriteBodyRes(ruleTypes),
|
||||
});
|
||||
|
|
|
@ -9,10 +9,10 @@ import { unmuteAlertRoute } from './unmute_alert';
|
|||
import { httpServiceMock } from 'src/core/server/mocks';
|
||||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -34,10 +34,10 @@ describe('unmuteAlertRoute', () => {
|
|||
`"/api/alerting/rule/{rule_id}/alert/{alert_id}/_unmute"`
|
||||
);
|
||||
|
||||
alertsClient.unmuteInstance.mockResolvedValueOnce();
|
||||
rulesClient.unmuteInstance.mockResolvedValueOnce();
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
rule_id: '1',
|
||||
|
@ -49,8 +49,8 @@ describe('unmuteAlertRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.unmuteInstance).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.unmuteInstance.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.unmuteInstance).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.unmuteInstance.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"alertId": "1",
|
||||
|
@ -70,11 +70,11 @@ describe('unmuteAlertRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.unmuteInstance.mockRejectedValue(
|
||||
rulesClient.unmuteInstance.mockRejectedValue(
|
||||
new AlertTypeDisabledError('Fail', 'license_invalid')
|
||||
);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { IRouter } from 'kibana/server';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { ILicenseState, AlertTypeDisabledError } from '../lib';
|
||||
import { MuteOptions } from '../alerts_client';
|
||||
import { MuteOptions } from '../rules_client';
|
||||
import { RewriteRequestCase, verifyAccessAndContext } from './lib';
|
||||
import { AlertingRequestHandlerContext, BASE_ALERTING_API_PATH } from '../types';
|
||||
|
||||
|
@ -38,10 +38,10 @@ export const unmuteAlertRoute = (
|
|||
},
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const params = rewriteParamsReq(req.params);
|
||||
try {
|
||||
await alertsClient.unmuteInstance(params);
|
||||
await rulesClient.unmuteInstance(params);
|
||||
return res.noContent();
|
||||
} catch (e) {
|
||||
if (e instanceof AlertTypeDisabledError) {
|
||||
|
|
|
@ -9,10 +9,10 @@ import { unmuteAllRuleRoute } from './unmute_all_rule';
|
|||
import { httpServiceMock } from 'src/core/server/mocks';
|
||||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -32,10 +32,10 @@ describe('unmuteAllRuleRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerting/rule/{id}/_unmute_all"`);
|
||||
|
||||
alertsClient.unmuteAll.mockResolvedValueOnce();
|
||||
rulesClient.unmuteAll.mockResolvedValueOnce();
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -46,8 +46,8 @@ describe('unmuteAllRuleRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.unmuteAll).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.unmuteAll.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.unmuteAll).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.unmuteAll.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -66,9 +66,9 @@ describe('unmuteAllRuleRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.unmuteAll.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
rulesClient.unmuteAll.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -28,10 +28,10 @@ export const unmuteAllRuleRoute = (
|
|||
},
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
try {
|
||||
await alertsClient.unmuteAll({ id });
|
||||
await rulesClient.unmuteAll({ id });
|
||||
return res.noContent();
|
||||
} catch (e) {
|
||||
if (e instanceof AlertTypeDisabledError) {
|
||||
|
|
|
@ -11,14 +11,14 @@ import { httpServiceMock } from 'src/core/server/mocks';
|
|||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { UpdateOptions } from '../alerts_client';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { UpdateOptions } from '../rules_client';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled';
|
||||
import { AlertNotifyWhenType } from '../../common';
|
||||
import { AsApiContract } from './lib';
|
||||
import { PartialAlert } from '../types';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -87,10 +87,10 @@ describe('updateRuleRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/api/alerting/rule/{id}"`);
|
||||
|
||||
alertsClient.update.mockResolvedValueOnce(mockedAlert);
|
||||
rulesClient.update.mockResolvedValueOnce(mockedAlert);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -102,8 +102,8 @@ describe('updateRuleRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual({ body: updateResult });
|
||||
|
||||
expect(alertsClient.update).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.update.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.update).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.update.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"data": Object {
|
||||
|
@ -145,10 +145,10 @@ describe('updateRuleRoute', () => {
|
|||
|
||||
const [, handler] = router.put.mock.calls[0];
|
||||
|
||||
alertsClient.update.mockResolvedValueOnce(mockedAlert);
|
||||
rulesClient.update.mockResolvedValueOnce(mockedAlert);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -175,10 +175,10 @@ describe('updateRuleRoute', () => {
|
|||
|
||||
const [, handler] = router.put.mock.calls[0];
|
||||
|
||||
alertsClient.update.mockResolvedValueOnce(mockedAlert);
|
||||
rulesClient.update.mockResolvedValueOnce(mockedAlert);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -201,9 +201,9 @@ describe('updateRuleRoute', () => {
|
|||
|
||||
const [, handler] = router.put.mock.calls[0];
|
||||
|
||||
alertsClient.update.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
rulesClient.update.mockRejectedValue(new AlertTypeDisabledError('Fail', 'license_invalid'));
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -9,7 +9,7 @@ import { schema } from '@kbn/config-schema';
|
|||
import { IRouter } from 'kibana/server';
|
||||
import { ILicenseState, AlertTypeDisabledError, validateDurationSchema } from '../lib';
|
||||
import { AlertNotifyWhenType } from '../../common';
|
||||
import { UpdateOptions } from '../alerts_client';
|
||||
import { UpdateOptions } from '../rules_client';
|
||||
import {
|
||||
verifyAccessAndContext,
|
||||
RewriteResponseCase,
|
||||
|
@ -118,11 +118,11 @@ export const updateRuleRoute = (
|
|||
handleDisabledApiKeysError(
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
const rule = req.body;
|
||||
try {
|
||||
const alertRes = await alertsClient.update(
|
||||
const alertRes = await rulesClient.update(
|
||||
rewriteBodyReq({
|
||||
id,
|
||||
data: {
|
||||
|
|
|
@ -9,10 +9,10 @@ import { updateRuleApiKeyRoute } from './update_rule_api_key';
|
|||
import { httpServiceMock } from 'src/core/server/mocks';
|
||||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
import { mockHandlerArguments } from './_mock_handler_arguments';
|
||||
import { alertsClientMock } from '../alerts_client.mock';
|
||||
import { rulesClientMock } from '../rules_client.mock';
|
||||
import { AlertTypeDisabledError } from '../lib/errors/alert_type_disabled';
|
||||
|
||||
const alertsClient = alertsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
jest.mock('../lib/license_api_access.ts', () => ({
|
||||
verifyApiAccess: jest.fn(),
|
||||
}));
|
||||
|
@ -32,10 +32,10 @@ describe('updateRuleApiKeyRoute', () => {
|
|||
|
||||
expect(config.path).toMatchInlineSnapshot(`"/internal/alerting/rule/{id}/_update_api_key"`);
|
||||
|
||||
alertsClient.updateApiKey.mockResolvedValueOnce();
|
||||
rulesClient.updateApiKey.mockResolvedValueOnce();
|
||||
|
||||
const [context, req, res] = mockHandlerArguments(
|
||||
{ alertsClient },
|
||||
{ rulesClient },
|
||||
{
|
||||
params: {
|
||||
id: '1',
|
||||
|
@ -46,8 +46,8 @@ describe('updateRuleApiKeyRoute', () => {
|
|||
|
||||
expect(await handler(context, req, res)).toEqual(undefined);
|
||||
|
||||
expect(alertsClient.updateApiKey).toHaveBeenCalledTimes(1);
|
||||
expect(alertsClient.updateApiKey.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
expect(rulesClient.updateApiKey).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClient.updateApiKey.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"id": "1",
|
||||
|
@ -66,11 +66,11 @@ describe('updateRuleApiKeyRoute', () => {
|
|||
|
||||
const [, handler] = router.post.mock.calls[0];
|
||||
|
||||
alertsClient.updateApiKey.mockRejectedValue(
|
||||
rulesClient.updateApiKey.mockRejectedValue(
|
||||
new AlertTypeDisabledError('Fail', 'license_invalid')
|
||||
);
|
||||
|
||||
const [context, req, res] = mockHandlerArguments({ alertsClient }, { params: {}, body: {} }, [
|
||||
const [context, req, res] = mockHandlerArguments({ rulesClient }, { params: {}, body: {} }, [
|
||||
'ok',
|
||||
'forbidden',
|
||||
]);
|
||||
|
|
|
@ -28,10 +28,10 @@ export const updateRuleApiKeyRoute = (
|
|||
},
|
||||
router.handleLegacyErrors(
|
||||
verifyAccessAndContext(licenseState, async function (context, req, res) {
|
||||
const alertsClient = context.alerting.getAlertsClient();
|
||||
const rulesClient = context.alerting.getRulesClient();
|
||||
const { id } = req.params;
|
||||
try {
|
||||
await alertsClient.updateApiKey({ id });
|
||||
await rulesClient.updateApiKey({ id });
|
||||
return res.noContent();
|
||||
} catch (e) {
|
||||
if (e instanceof AlertTypeDisabledError) {
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
*/
|
||||
|
||||
import type { PublicMethodsOf } from '@kbn/utility-types';
|
||||
import { AlertsClient } from './alerts_client';
|
||||
import { RulesClient } from './rules_client';
|
||||
|
||||
type Schema = PublicMethodsOf<AlertsClient>;
|
||||
export type AlertsClientMock = jest.Mocked<Schema>;
|
||||
type Schema = PublicMethodsOf<RulesClient>;
|
||||
export type RulesClientMock = jest.Mocked<Schema>;
|
||||
|
||||
const createAlertsClientMock = () => {
|
||||
const mocked: AlertsClientMock = {
|
||||
const createRulesClientMock = () => {
|
||||
const mocked: RulesClientMock = {
|
||||
aggregate: jest.fn(),
|
||||
create: jest.fn(),
|
||||
get: jest.fn(),
|
||||
|
@ -33,8 +33,8 @@ const createAlertsClientMock = () => {
|
|||
return mocked;
|
||||
};
|
||||
|
||||
export const alertsClientMock: {
|
||||
create: () => AlertsClientMock;
|
||||
export const rulesClientMock: {
|
||||
create: () => RulesClientMock;
|
||||
} = {
|
||||
create: createAlertsClientMock,
|
||||
create: createRulesClientMock,
|
||||
};
|
|
@ -5,4 +5,4 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
export * from './alerts_client';
|
||||
export * from './rules_client';
|
|
@ -55,7 +55,7 @@ import {
|
|||
AlertingAuthorizationFilterType,
|
||||
AlertingAuthorizationFilterOpts,
|
||||
} from '../authorization';
|
||||
import { IEventLogClient } from '../../../../plugins/event_log/server';
|
||||
import { IEventLogClient } from '../../../event_log/server';
|
||||
import { parseIsoOrRelativeDate } from '../lib/iso_or_relative_date';
|
||||
import { alertInstanceSummaryFromEventLog } from '../lib/alert_instance_summary_from_event_log';
|
||||
import { IEvent } from '../../../event_log/server';
|
||||
|
@ -191,7 +191,7 @@ const alertingAuthorizationFilterOpts: AlertingAuthorizationFilterOpts = {
|
|||
type: AlertingAuthorizationFilterType.KQL,
|
||||
fieldNames: { ruleTypeId: 'alert.attributes.alertTypeId', consumer: 'alert.attributes.consumer' },
|
||||
};
|
||||
export class AlertsClient {
|
||||
export class RulesClient {
|
||||
private readonly logger: Logger;
|
||||
private readonly getUserName: () => Promise<string | null>;
|
||||
private readonly spaceId?: string;
|
||||
|
@ -462,7 +462,7 @@ export class AlertsClient {
|
|||
events = queryResults.data;
|
||||
} catch (err) {
|
||||
this.logger.debug(
|
||||
`alertsClient.getAlertInstanceSummary(): error searching event log for alert ${id}: ${err.message}`
|
||||
`rulesClient.getAlertInstanceSummary(): error searching event log for alert ${id}: ${err.message}`
|
||||
);
|
||||
events = [];
|
||||
}
|
||||
|
@ -679,7 +679,7 @@ export class AlertsClient {
|
|||
}: UpdateOptions<Params>): Promise<PartialAlert<Params>> {
|
||||
return await retryIfConflicts(
|
||||
this.logger,
|
||||
`alertsClient.update('${id}')`,
|
||||
`rulesClient.update('${id}')`,
|
||||
async () => await this.updateWithOCC<Params>({ id, data })
|
||||
);
|
||||
}
|
||||
|
@ -859,7 +859,7 @@ export class AlertsClient {
|
|||
public async updateApiKey({ id }: { id: string }): Promise<void> {
|
||||
return await retryIfConflicts(
|
||||
this.logger,
|
||||
`alertsClient.updateApiKey('${id}')`,
|
||||
`rulesClient.updateApiKey('${id}')`,
|
||||
async () => await this.updateApiKeyWithOCC({ id })
|
||||
);
|
||||
}
|
||||
|
@ -964,7 +964,7 @@ export class AlertsClient {
|
|||
public async enable({ id }: { id: string }): Promise<void> {
|
||||
return await retryIfConflicts(
|
||||
this.logger,
|
||||
`alertsClient.enable('${id}')`,
|
||||
`rulesClient.enable('${id}')`,
|
||||
async () => await this.enableWithOCC({ id })
|
||||
);
|
||||
}
|
||||
|
@ -1082,7 +1082,7 @@ export class AlertsClient {
|
|||
public async disable({ id }: { id: string }): Promise<void> {
|
||||
return await retryIfConflicts(
|
||||
this.logger,
|
||||
`alertsClient.disable('${id}')`,
|
||||
`rulesClient.disable('${id}')`,
|
||||
async () => await this.disableWithOCC({ id })
|
||||
);
|
||||
}
|
||||
|
@ -1174,7 +1174,7 @@ export class AlertsClient {
|
|||
public async muteAll({ id }: { id: string }): Promise<void> {
|
||||
return await retryIfConflicts(
|
||||
this.logger,
|
||||
`alertsClient.muteAll('${id}')`,
|
||||
`rulesClient.muteAll('${id}')`,
|
||||
async () => await this.muteAllWithOCC({ id })
|
||||
);
|
||||
}
|
||||
|
@ -1236,7 +1236,7 @@ export class AlertsClient {
|
|||
public async unmuteAll({ id }: { id: string }): Promise<void> {
|
||||
return await retryIfConflicts(
|
||||
this.logger,
|
||||
`alertsClient.unmuteAll('${id}')`,
|
||||
`rulesClient.unmuteAll('${id}')`,
|
||||
async () => await this.unmuteAllWithOCC({ id })
|
||||
);
|
||||
}
|
||||
|
@ -1298,7 +1298,7 @@ export class AlertsClient {
|
|||
public async muteInstance({ alertId, alertInstanceId }: MuteOptions): Promise<void> {
|
||||
return await retryIfConflicts(
|
||||
this.logger,
|
||||
`alertsClient.muteInstance('${alertId}')`,
|
||||
`rulesClient.muteInstance('${alertId}')`,
|
||||
async () => await this.muteInstanceWithOCC({ alertId, alertInstanceId })
|
||||
);
|
||||
}
|
||||
|
@ -1360,7 +1360,7 @@ export class AlertsClient {
|
|||
public async unmuteInstance({ alertId, alertInstanceId }: MuteOptions): Promise<void> {
|
||||
return await retryIfConflicts(
|
||||
this.logger,
|
||||
`alertsClient.unmuteInstance('${alertId}')`,
|
||||
`rulesClient.unmuteInstance('${alertId}')`,
|
||||
async () => await this.unmuteInstanceWithOCC({ alertId, alertInstanceId })
|
||||
);
|
||||
}
|
||||
|
@ -1539,7 +1539,7 @@ export class AlertsClient {
|
|||
|
||||
if (actionsUsingConnectorsWithMissingSecrets.length) {
|
||||
throw Boom.badRequest(
|
||||
i18n.translate('xpack.alerting.alertsClient.validateActions.misconfiguredConnector', {
|
||||
i18n.translate('xpack.alerting.rulesClient.validateActions.misconfiguredConnector', {
|
||||
defaultMessage: 'Invalid connectors: {groups}',
|
||||
values: {
|
||||
groups: actionsUsingConnectorsWithMissingSecrets
|
||||
|
@ -1559,7 +1559,7 @@ export class AlertsClient {
|
|||
);
|
||||
if (invalidActionGroups.length) {
|
||||
throw Boom.badRequest(
|
||||
i18n.translate('xpack.alerting.alertsClient.validateActions.invalidGroups', {
|
||||
i18n.translate('xpack.alerting.rulesClient.validateActions.invalidGroups', {
|
||||
defaultMessage: 'Invalid action groups: {groups}',
|
||||
values: {
|
||||
groups: invalidActionGroups.join(', '),
|
||||
|
@ -1704,7 +1704,7 @@ function parseDate(dateString: string | undefined, propertyName: string, default
|
|||
const parsedDate = parseIsoOrRelativeDate(dateString);
|
||||
if (parsedDate === undefined) {
|
||||
throw Boom.badRequest(
|
||||
i18n.translate('xpack.alerting.alertsClient.invalidDate', {
|
||||
i18n.translate('xpack.alerting.rulesClient.invalidDate', {
|
||||
defaultMessage: 'Invalid date for parameter {field}: "{dateValue}"',
|
||||
values: {
|
||||
field: propertyName,
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { AlertsClient, ConstructorOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -28,7 +28,7 @@ const authorization = alertingAuthorizationMock.create();
|
|||
const actionsAuthorization = actionsAuthorizationMock.create();
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -46,7 +46,7 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
});
|
||||
|
||||
setGlobalDate();
|
||||
|
@ -124,8 +124,8 @@ describe('aggregate()', () => {
|
|||
});
|
||||
|
||||
test('calls saved objects client with given params to perform aggregation', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const result = await alertsClient.aggregate({ options: {} });
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
const result = await rulesClient.aggregate({ options: {} });
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"alertExecutionStatus": Object {
|
||||
|
@ -154,8 +154,8 @@ describe('aggregate()', () => {
|
|||
});
|
||||
|
||||
test('supports filters when aggregating', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
await alertsClient.aggregate({ options: { filter: 'someTerm' } });
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
await rulesClient.aggregate({ options: { filter: 'someTerm' } });
|
||||
|
||||
expect(unsecuredSavedObjectsClient.find).toHaveBeenCalledTimes(
|
||||
AlertExecutionStatusValues.length
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { AlertsClient, ConstructorOptions, CreateOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions, CreateOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -36,7 +36,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKibanaRequest());
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -55,7 +55,7 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
@ -92,12 +92,12 @@ function getMockData(
|
|||
}
|
||||
|
||||
describe('create()', () => {
|
||||
let alertsClient: AlertsClient;
|
||||
let rulesClient: RulesClient;
|
||||
let actionsClient: jest.Mocked<ActionsClient>;
|
||||
|
||||
beforeEach(async () => {
|
||||
alertsClient = new AlertsClient(alertsClientParams);
|
||||
actionsClient = (await alertsClientParams.getActionsClient()) as jest.Mocked<ActionsClient>;
|
||||
rulesClient = new RulesClient(rulesClientParams);
|
||||
actionsClient = (await rulesClientParams.getActionsClient()) as jest.Mocked<ActionsClient>;
|
||||
actionsClient.getBulk.mockReset();
|
||||
actionsClient.getBulk.mockResolvedValue([
|
||||
{
|
||||
|
@ -116,7 +116,7 @@ describe('create()', () => {
|
|||
isPreconfigured: false,
|
||||
},
|
||||
]);
|
||||
alertsClientParams.getActionsClient.mockResolvedValue(actionsClient);
|
||||
rulesClientParams.getActionsClient.mockResolvedValue(actionsClient);
|
||||
});
|
||||
|
||||
describe('authorization', () => {
|
||||
|
@ -183,7 +183,7 @@ describe('create()', () => {
|
|||
],
|
||||
});
|
||||
|
||||
return alertsClient.create(options);
|
||||
return rulesClient.create(options);
|
||||
}
|
||||
|
||||
test('ensures user is authorised to create this type of alert under the consumer', async () => {
|
||||
|
@ -237,7 +237,7 @@ describe('create()', () => {
|
|||
attributes: data,
|
||||
references: [],
|
||||
});
|
||||
await alertsClient.create({ data });
|
||||
await rulesClient.create({ data });
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
||||
|
@ -253,7 +253,7 @@ describe('create()', () => {
|
|||
authorization.ensureAuthorized.mockRejectedValue(new Error('Unauthorized'));
|
||||
|
||||
await expect(
|
||||
alertsClient.create({
|
||||
rulesClient.create({
|
||||
data: getMockData({
|
||||
enabled: false,
|
||||
actions: [],
|
||||
|
@ -347,7 +347,7 @@ describe('create()', () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
const result = await alertsClient.create({ data });
|
||||
const result = await rulesClient.create({ data });
|
||||
expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
|
||||
entity: 'rule',
|
||||
consumer: 'bar',
|
||||
|
@ -537,7 +537,7 @@ describe('create()', () => {
|
|||
params: {},
|
||||
ownerId: null,
|
||||
});
|
||||
const result = await alertsClient.create({ data, options: { id: '123' } });
|
||||
const result = await rulesClient.create({ data, options: { id: '123' } });
|
||||
expect(result.id).toEqual('123');
|
||||
expect(unsecuredSavedObjectsClient.create.mock.calls[0][2]).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
|
@ -691,7 +691,7 @@ describe('create()', () => {
|
|||
},
|
||||
references: [],
|
||||
});
|
||||
const result = await alertsClient.create({ data });
|
||||
const result = await rulesClient.create({ data });
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"actions": Array [
|
||||
|
@ -770,7 +770,7 @@ describe('create()', () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
const result = await alertsClient.create({ data });
|
||||
const result = await rulesClient.create({ data });
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"actions": Array [
|
||||
|
@ -900,7 +900,7 @@ describe('create()', () => {
|
|||
},
|
||||
references: [],
|
||||
});
|
||||
const result = await alertsClient.create({ data });
|
||||
const result = await rulesClient.create({ data });
|
||||
|
||||
expect(extractReferencesFn).toHaveBeenCalledWith(ruleParams);
|
||||
expect(unsecuredSavedObjectsClient.create).toHaveBeenCalledWith(
|
||||
|
@ -1077,7 +1077,7 @@ describe('create()', () => {
|
|||
},
|
||||
references: [],
|
||||
});
|
||||
const result = await alertsClient.create({ data });
|
||||
const result = await rulesClient.create({ data });
|
||||
|
||||
expect(extractReferencesFn).toHaveBeenCalledWith(ruleParams);
|
||||
expect(unsecuredSavedObjectsClient.create).toHaveBeenCalledWith(
|
||||
|
@ -1203,8 +1203,8 @@ describe('create()', () => {
|
|||
ownerId: null,
|
||||
});
|
||||
|
||||
await alertsClient.create({ data });
|
||||
expect(alertsClientParams.createAPIKey).toHaveBeenCalledWith('Alerting: 123/my alert name');
|
||||
await rulesClient.create({ data });
|
||||
expect(rulesClientParams.createAPIKey).toHaveBeenCalledWith('Alerting: 123/my alert name');
|
||||
});
|
||||
|
||||
test('should create alert with given notifyWhen value if notifyWhen is not null', async () => {
|
||||
|
@ -1259,7 +1259,7 @@ describe('create()', () => {
|
|||
params: {},
|
||||
ownerId: null,
|
||||
});
|
||||
const result = await alertsClient.create({ data });
|
||||
const result = await rulesClient.create({ data });
|
||||
expect(unsecuredSavedObjectsClient.create).toHaveBeenCalledWith(
|
||||
'alert',
|
||||
{
|
||||
|
@ -1399,7 +1399,7 @@ describe('create()', () => {
|
|||
params: {},
|
||||
ownerId: null,
|
||||
});
|
||||
const result = await alertsClient.create({ data });
|
||||
const result = await rulesClient.create({ data });
|
||||
expect(unsecuredSavedObjectsClient.create).toHaveBeenCalledWith(
|
||||
'alert',
|
||||
{
|
||||
|
@ -1539,7 +1539,7 @@ describe('create()', () => {
|
|||
params: {},
|
||||
ownerId: null,
|
||||
});
|
||||
const result = await alertsClient.create({ data });
|
||||
const result = await rulesClient.create({ data });
|
||||
expect(unsecuredSavedObjectsClient.create).toHaveBeenCalledWith(
|
||||
'alert',
|
||||
{
|
||||
|
@ -1651,7 +1651,7 @@ describe('create()', () => {
|
|||
async executor() {},
|
||||
producer: 'alerts',
|
||||
});
|
||||
await expect(alertsClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"params invalid: [param1]: expected value of type [string] but got [undefined]"`
|
||||
);
|
||||
});
|
||||
|
@ -1661,7 +1661,7 @@ describe('create()', () => {
|
|||
// Reset from default behaviour
|
||||
actionsClient.getBulk.mockReset();
|
||||
actionsClient.getBulk.mockRejectedValueOnce(new Error('Test Error'));
|
||||
await expect(alertsClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Test Error"`
|
||||
);
|
||||
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
|
||||
|
@ -1670,7 +1670,7 @@ describe('create()', () => {
|
|||
|
||||
test('throws error and add API key to invalidatePendingApiKey SO when create saved object fails', async () => {
|
||||
const data = getMockData();
|
||||
alertsClientParams.createAPIKey.mockResolvedValueOnce({
|
||||
rulesClientParams.createAPIKey.mockResolvedValueOnce({
|
||||
apiKeysEnabled: true,
|
||||
result: { id: '123', name: '123', api_key: 'abc' },
|
||||
});
|
||||
|
@ -1685,7 +1685,7 @@ describe('create()', () => {
|
|||
},
|
||||
references: [],
|
||||
});
|
||||
await expect(alertsClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Test failure"`
|
||||
);
|
||||
expect(taskManager.schedule).not.toHaveBeenCalled();
|
||||
|
@ -1728,7 +1728,7 @@ describe('create()', () => {
|
|||
});
|
||||
taskManager.schedule.mockRejectedValueOnce(new Error('Test failure'));
|
||||
unsecuredSavedObjectsClient.delete.mockResolvedValueOnce({});
|
||||
await expect(alertsClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Test failure"`
|
||||
);
|
||||
expect(unsecuredSavedObjectsClient.delete).toHaveBeenCalledTimes(1);
|
||||
|
@ -1774,10 +1774,10 @@ describe('create()', () => {
|
|||
unsecuredSavedObjectsClient.delete.mockRejectedValueOnce(
|
||||
new Error('Saved object delete error')
|
||||
);
|
||||
await expect(alertsClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Task manager error"`
|
||||
);
|
||||
expect(alertsClientParams.logger.error).toHaveBeenCalledWith(
|
||||
expect(rulesClientParams.logger.error).toHaveBeenCalledWith(
|
||||
'Failed to cleanup alert "1" after scheduling task failed. Error: Saved object delete error'
|
||||
);
|
||||
});
|
||||
|
@ -1787,14 +1787,14 @@ describe('create()', () => {
|
|||
alertTypeRegistry.get.mockImplementation(() => {
|
||||
throw new Error('Invalid type');
|
||||
});
|
||||
await expect(alertsClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Invalid type"`
|
||||
);
|
||||
});
|
||||
|
||||
test('calls the API key function', async () => {
|
||||
const data = getMockData();
|
||||
alertsClientParams.createAPIKey.mockResolvedValueOnce({
|
||||
rulesClientParams.createAPIKey.mockResolvedValueOnce({
|
||||
apiKeysEnabled: true,
|
||||
result: { id: '123', name: '123', api_key: 'abc' },
|
||||
});
|
||||
|
@ -1854,9 +1854,9 @@ describe('create()', () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
await alertsClient.create({ data });
|
||||
await rulesClient.create({ data });
|
||||
|
||||
expect(alertsClientParams.createAPIKey).toHaveBeenCalledTimes(1);
|
||||
expect(rulesClientParams.createAPIKey).toHaveBeenCalledTimes(1);
|
||||
expect(unsecuredSavedObjectsClient.create).toHaveBeenCalledWith(
|
||||
'alert',
|
||||
{
|
||||
|
@ -1965,9 +1965,9 @@ describe('create()', () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
await alertsClient.create({ data });
|
||||
await rulesClient.create({ data });
|
||||
|
||||
expect(alertsClientParams.createAPIKey).not.toHaveBeenCalled();
|
||||
expect(rulesClientParams.createAPIKey).not.toHaveBeenCalled();
|
||||
expect(unsecuredSavedObjectsClient.create).toHaveBeenCalledWith(
|
||||
'alert',
|
||||
{
|
||||
|
@ -2020,11 +2020,11 @@ describe('create()', () => {
|
|||
|
||||
test('throws an error if API key creation throws', async () => {
|
||||
const data = getMockData();
|
||||
alertsClientParams.createAPIKey.mockImplementation(() => {
|
||||
rulesClientParams.createAPIKey.mockImplementation(() => {
|
||||
throw new Error('no');
|
||||
});
|
||||
expect(
|
||||
async () => await alertsClient.create({ data })
|
||||
async () => await rulesClient.create({ data })
|
||||
).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Error creating rule: could not create API key - no"`
|
||||
);
|
||||
|
@ -2035,9 +2035,7 @@ describe('create()', () => {
|
|||
alertTypeRegistry.ensureAlertTypeEnabled.mockImplementation(() => {
|
||||
throw new Error('Fail');
|
||||
});
|
||||
await expect(alertsClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Fail"`
|
||||
);
|
||||
await expect(rulesClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(`"Fail"`);
|
||||
});
|
||||
|
||||
test('throws error when adding action using connector with missing secrets', async () => {
|
||||
|
@ -2061,7 +2059,7 @@ describe('create()', () => {
|
|||
isPreconfigured: false,
|
||||
},
|
||||
]);
|
||||
await expect(alertsClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Invalid connectors: email connector"`
|
||||
);
|
||||
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { AlertsClient, ConstructorOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -27,7 +27,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKibanaRequest());
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -46,12 +46,12 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
describe('delete()', () => {
|
||||
let alertsClient: AlertsClient;
|
||||
let rulesClient: RulesClient;
|
||||
const existingAlert = {
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -91,7 +91,7 @@ describe('delete()', () => {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
alertsClient = new AlertsClient(alertsClientParams);
|
||||
rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValue(existingAlert);
|
||||
unsecuredSavedObjectsClient.delete.mockResolvedValue({
|
||||
success: true,
|
||||
|
@ -109,7 +109,7 @@ describe('delete()', () => {
|
|||
},
|
||||
references: [],
|
||||
});
|
||||
const result = await alertsClient.delete({ id: '1' });
|
||||
const result = await rulesClient.delete({ id: '1' });
|
||||
expect(result).toEqual({ success: true });
|
||||
expect(unsecuredSavedObjectsClient.delete).toHaveBeenCalledWith('alert', '1');
|
||||
expect(taskManager.removeIfExists).toHaveBeenCalledWith('task-123');
|
||||
|
@ -134,13 +134,13 @@ describe('delete()', () => {
|
|||
references: [],
|
||||
});
|
||||
|
||||
const result = await alertsClient.delete({ id: '1' });
|
||||
const result = await rulesClient.delete({ id: '1' });
|
||||
expect(result).toEqual({ success: true });
|
||||
expect(unsecuredSavedObjectsClient.delete).toHaveBeenCalledWith('alert', '1');
|
||||
expect(taskManager.removeIfExists).toHaveBeenCalledWith('task-123');
|
||||
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
|
||||
expect(unsecuredSavedObjectsClient.get).toHaveBeenCalledWith('alert', '1');
|
||||
expect(alertsClientParams.logger.error).toHaveBeenCalledWith(
|
||||
expect(rulesClientParams.logger.error).toHaveBeenCalledWith(
|
||||
'delete(): Failed to load API key to invalidate on alert 1: Fail'
|
||||
);
|
||||
});
|
||||
|
@ -154,7 +154,7 @@ describe('delete()', () => {
|
|||
},
|
||||
});
|
||||
|
||||
await alertsClient.delete({ id: '1' });
|
||||
await rulesClient.delete({ id: '1' });
|
||||
expect(taskManager.removeIfExists).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
@ -176,17 +176,17 @@ describe('delete()', () => {
|
|||
},
|
||||
});
|
||||
|
||||
await alertsClient.delete({ id: '1' });
|
||||
await rulesClient.delete({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('swallows error when invalidate API key throws', async () => {
|
||||
unsecuredSavedObjectsClient.create.mockRejectedValueOnce(new Error('Fail'));
|
||||
await alertsClient.delete({ id: '1' });
|
||||
await rulesClient.delete({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.create.mock.calls[0][0]).toBe(
|
||||
'api_key_pending_invalidation'
|
||||
);
|
||||
expect(alertsClientParams.logger.error).toHaveBeenCalledWith(
|
||||
expect(rulesClientParams.logger.error).toHaveBeenCalledWith(
|
||||
'Failed to mark for API key [id="MTIzOmFiYw=="] for invalidation: Fail'
|
||||
);
|
||||
});
|
||||
|
@ -203,9 +203,9 @@ describe('delete()', () => {
|
|||
});
|
||||
encryptedSavedObjects.getDecryptedAsInternalUser.mockRejectedValue(new Error('Fail'));
|
||||
|
||||
await alertsClient.delete({ id: '1' });
|
||||
await rulesClient.delete({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
|
||||
expect(alertsClientParams.logger.error).toHaveBeenCalledWith(
|
||||
expect(rulesClientParams.logger.error).toHaveBeenCalledWith(
|
||||
'delete(): Failed to load API key to invalidate on alert 1: Fail'
|
||||
);
|
||||
});
|
||||
|
@ -214,7 +214,7 @@ describe('delete()', () => {
|
|||
encryptedSavedObjects.getDecryptedAsInternalUser.mockRejectedValue(new Error('Fail'));
|
||||
unsecuredSavedObjectsClient.get.mockRejectedValue(new Error('SOC Fail'));
|
||||
|
||||
await expect(alertsClient.delete({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.delete({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"SOC Fail"`
|
||||
);
|
||||
});
|
||||
|
@ -222,14 +222,14 @@ describe('delete()', () => {
|
|||
test('throws error when taskManager.removeIfExists throws an error', async () => {
|
||||
taskManager.removeIfExists.mockRejectedValue(new Error('TM Fail'));
|
||||
|
||||
await expect(alertsClient.delete({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.delete({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"TM Fail"`
|
||||
);
|
||||
});
|
||||
|
||||
describe('authorization', () => {
|
||||
test('ensures user is authorised to delete this type of alert under the consumer', async () => {
|
||||
await alertsClient.delete({ id: '1' });
|
||||
await rulesClient.delete({ id: '1' });
|
||||
|
||||
expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
|
||||
entity: 'rule',
|
||||
|
@ -244,7 +244,7 @@ describe('delete()', () => {
|
|||
new Error(`Unauthorized to delete a "myType" alert for "myApp"`)
|
||||
);
|
||||
|
||||
await expect(alertsClient.delete({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
await expect(rulesClient.delete({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
`[Error: Unauthorized to delete a "myType" alert for "myApp"]`
|
||||
);
|
||||
|
||||
|
@ -259,7 +259,7 @@ describe('delete()', () => {
|
|||
|
||||
describe('auditLogger', () => {
|
||||
test('logs audit event when deleting a rule', async () => {
|
||||
await alertsClient.delete({ id: '1' });
|
||||
await rulesClient.delete({ id: '1' });
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
||||
|
@ -274,7 +274,7 @@ describe('delete()', () => {
|
|||
test('logs audit event when not authorised to delete a rule', async () => {
|
||||
authorization.ensureAuthorized.mockRejectedValue(new Error('Unauthorized'));
|
||||
|
||||
await expect(alertsClient.delete({ id: '1' })).rejects.toThrow();
|
||||
await expect(rulesClient.delete({ id: '1' })).rejects.toThrow();
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { AlertsClient, ConstructorOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -28,7 +28,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKibanaRequest());
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -47,14 +47,14 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
setGlobalDate();
|
||||
|
||||
describe('disable()', () => {
|
||||
let alertsClient: AlertsClient;
|
||||
let rulesClient: RulesClient;
|
||||
const existingAlert = {
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -90,14 +90,14 @@ describe('disable()', () => {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
alertsClient = new AlertsClient(alertsClientParams);
|
||||
rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValue(existingAlert);
|
||||
encryptedSavedObjects.getDecryptedAsInternalUser.mockResolvedValue(existingDecryptedAlert);
|
||||
});
|
||||
|
||||
describe('authorization', () => {
|
||||
test('ensures user is authorised to disable this type of alert under the consumer', async () => {
|
||||
await alertsClient.disable({ id: '1' });
|
||||
await rulesClient.disable({ id: '1' });
|
||||
|
||||
expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
|
||||
entity: 'rule',
|
||||
|
@ -112,7 +112,7 @@ describe('disable()', () => {
|
|||
new Error(`Unauthorized to disable a "myType" alert for "myApp"`)
|
||||
);
|
||||
|
||||
await expect(alertsClient.disable({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
await expect(rulesClient.disable({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
`[Error: Unauthorized to disable a "myType" alert for "myApp"]`
|
||||
);
|
||||
|
||||
|
@ -127,7 +127,7 @@ describe('disable()', () => {
|
|||
|
||||
describe('auditLogger', () => {
|
||||
test('logs audit event when disabling a rule', async () => {
|
||||
await alertsClient.disable({ id: '1' });
|
||||
await rulesClient.disable({ id: '1' });
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
||||
|
@ -142,7 +142,7 @@ describe('disable()', () => {
|
|||
test('logs audit event when not authorised to disable a rule', async () => {
|
||||
authorization.ensureAuthorized.mockRejectedValue(new Error('Unauthorized'));
|
||||
|
||||
await expect(alertsClient.disable({ id: '1' })).rejects.toThrow();
|
||||
await expect(rulesClient.disable({ id: '1' })).rejects.toThrow();
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
||||
|
@ -174,7 +174,7 @@ describe('disable()', () => {
|
|||
},
|
||||
references: [],
|
||||
});
|
||||
await alertsClient.disable({ id: '1' });
|
||||
await rulesClient.disable({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.get).not.toHaveBeenCalled();
|
||||
expect(encryptedSavedObjects.getDecryptedAsInternalUser).toHaveBeenCalledWith('alert', '1', {
|
||||
namespace: 'default',
|
||||
|
@ -229,7 +229,7 @@ describe('disable()', () => {
|
|||
references: [],
|
||||
});
|
||||
|
||||
await alertsClient.disable({ id: '1' });
|
||||
await rulesClient.disable({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.get).toHaveBeenCalledWith('alert', '1');
|
||||
expect(encryptedSavedObjects.getDecryptedAsInternalUser).toHaveBeenCalledWith('alert', '1', {
|
||||
namespace: 'default',
|
||||
|
@ -290,7 +290,7 @@ describe('disable()', () => {
|
|||
references: [],
|
||||
});
|
||||
|
||||
await alertsClient.disable({ id: '1' });
|
||||
await rulesClient.disable({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.update).not.toHaveBeenCalled();
|
||||
expect(taskManager.removeIfExists).not.toHaveBeenCalled();
|
||||
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
|
||||
|
@ -308,7 +308,7 @@ describe('disable()', () => {
|
|||
});
|
||||
encryptedSavedObjects.getDecryptedAsInternalUser.mockResolvedValueOnce(existingAlert);
|
||||
|
||||
await alertsClient.disable({ id: '1' });
|
||||
await rulesClient.disable({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
@ -324,11 +324,11 @@ describe('disable()', () => {
|
|||
});
|
||||
encryptedSavedObjects.getDecryptedAsInternalUser.mockRejectedValueOnce(new Error('Fail'));
|
||||
|
||||
await alertsClient.disable({ id: '1' });
|
||||
await rulesClient.disable({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.update).toHaveBeenCalled();
|
||||
expect(taskManager.removeIfExists).toHaveBeenCalled();
|
||||
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
|
||||
expect(alertsClientParams.logger.error).toHaveBeenCalledWith(
|
||||
expect(rulesClientParams.logger.error).toHaveBeenCalledWith(
|
||||
'disable(): Failed to load API key to invalidate on alert 1: Fail'
|
||||
);
|
||||
});
|
||||
|
@ -336,15 +336,15 @@ describe('disable()', () => {
|
|||
test('throws when unsecuredSavedObjectsClient update fails', async () => {
|
||||
unsecuredSavedObjectsClient.update.mockRejectedValueOnce(new Error('Failed to update'));
|
||||
|
||||
await expect(alertsClient.disable({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.disable({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Failed to update"`
|
||||
);
|
||||
});
|
||||
|
||||
test('swallows error when invalidate API key throws', async () => {
|
||||
unsecuredSavedObjectsClient.create.mockRejectedValueOnce(new Error('Fail'));
|
||||
await alertsClient.disable({ id: '1' });
|
||||
expect(alertsClientParams.logger.error).toHaveBeenCalledWith(
|
||||
await rulesClient.disable({ id: '1' });
|
||||
expect(rulesClientParams.logger.error).toHaveBeenCalledWith(
|
||||
'Failed to mark for API key [id="MTIzOmFiYw=="] for invalidation: Fail'
|
||||
);
|
||||
});
|
||||
|
@ -352,7 +352,7 @@ describe('disable()', () => {
|
|||
test('throws when failing to remove task from task manager', async () => {
|
||||
taskManager.removeIfExists.mockRejectedValueOnce(new Error('Failed to remove task'));
|
||||
|
||||
await expect(alertsClient.disable({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.disable({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Failed to remove task"`
|
||||
);
|
||||
});
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { AlertsClient, ConstructorOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -29,7 +29,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKibanaRequest());
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -48,14 +48,14 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
setGlobalDate();
|
||||
|
||||
describe('enable()', () => {
|
||||
let alertsClient: AlertsClient;
|
||||
let rulesClient: RulesClient;
|
||||
const existingAlert = {
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -81,10 +81,10 @@ describe('enable()', () => {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
alertsClient = new AlertsClient(alertsClientParams);
|
||||
rulesClient = new RulesClient(rulesClientParams);
|
||||
encryptedSavedObjects.getDecryptedAsInternalUser.mockResolvedValue(existingAlert);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValue(existingAlert);
|
||||
alertsClientParams.createAPIKey.mockResolvedValue({
|
||||
rulesClientParams.createAPIKey.mockResolvedValue({
|
||||
apiKeysEnabled: false,
|
||||
});
|
||||
unsecuredSavedObjectsClient.create.mockResolvedValueOnce({
|
||||
|
@ -116,7 +116,7 @@ describe('enable()', () => {
|
|||
beforeEach(() => {
|
||||
encryptedSavedObjects.getDecryptedAsInternalUser.mockResolvedValue(existingAlert);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValue(existingAlert);
|
||||
alertsClientParams.createAPIKey.mockResolvedValue({
|
||||
rulesClientParams.createAPIKey.mockResolvedValue({
|
||||
apiKeysEnabled: false,
|
||||
});
|
||||
taskManager.schedule.mockResolvedValue({
|
||||
|
@ -135,7 +135,7 @@ describe('enable()', () => {
|
|||
});
|
||||
|
||||
test('ensures user is authorised to enable this type of alert under the consumer', async () => {
|
||||
await alertsClient.enable({ id: '1' });
|
||||
await rulesClient.enable({ id: '1' });
|
||||
|
||||
expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
|
||||
entity: 'rule',
|
||||
|
@ -151,7 +151,7 @@ describe('enable()', () => {
|
|||
new Error(`Unauthorized to enable a "myType" alert for "myApp"`)
|
||||
);
|
||||
|
||||
await expect(alertsClient.enable({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
await expect(rulesClient.enable({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
`[Error: Unauthorized to enable a "myType" alert for "myApp"]`
|
||||
);
|
||||
|
||||
|
@ -166,7 +166,7 @@ describe('enable()', () => {
|
|||
|
||||
describe('auditLogger', () => {
|
||||
test('logs audit event when enabling a rule', async () => {
|
||||
await alertsClient.enable({ id: '1' });
|
||||
await rulesClient.enable({ id: '1' });
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
||||
|
@ -181,7 +181,7 @@ describe('enable()', () => {
|
|||
test('logs audit event when not authorised to enable a rule', async () => {
|
||||
authorization.ensureAuthorized.mockRejectedValue(new Error('Unauthorized'));
|
||||
|
||||
await expect(alertsClient.enable({ id: '1' })).rejects.toThrow();
|
||||
await expect(rulesClient.enable({ id: '1' })).rejects.toThrow();
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
||||
|
@ -225,13 +225,13 @@ describe('enable()', () => {
|
|||
references: [],
|
||||
});
|
||||
|
||||
await alertsClient.enable({ id: '1' });
|
||||
await rulesClient.enable({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.get).not.toHaveBeenCalled();
|
||||
expect(encryptedSavedObjects.getDecryptedAsInternalUser).toHaveBeenCalledWith('alert', '1', {
|
||||
namespace: 'default',
|
||||
});
|
||||
expect(unsecuredSavedObjectsClient.create).not.toBeCalledWith('api_key_pending_invalidation');
|
||||
expect(alertsClientParams.createAPIKey).toHaveBeenCalled();
|
||||
expect(rulesClientParams.createAPIKey).toHaveBeenCalled();
|
||||
expect(unsecuredSavedObjectsClient.update).toHaveBeenCalledWith(
|
||||
'alert',
|
||||
'1',
|
||||
|
@ -308,7 +308,7 @@ describe('enable()', () => {
|
|||
references: [],
|
||||
});
|
||||
|
||||
await alertsClient.enable({ id: '1' });
|
||||
await rulesClient.enable({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.get).not.toHaveBeenCalled();
|
||||
expect(encryptedSavedObjects.getDecryptedAsInternalUser).toHaveBeenCalledWith('alert', '1', {
|
||||
namespace: 'default',
|
||||
|
@ -327,20 +327,20 @@ describe('enable()', () => {
|
|||
},
|
||||
});
|
||||
|
||||
await alertsClient.enable({ id: '1' });
|
||||
expect(alertsClientParams.getUserName).not.toHaveBeenCalled();
|
||||
expect(alertsClientParams.createAPIKey).not.toHaveBeenCalled();
|
||||
await rulesClient.enable({ id: '1' });
|
||||
expect(rulesClientParams.getUserName).not.toHaveBeenCalled();
|
||||
expect(rulesClientParams.createAPIKey).not.toHaveBeenCalled();
|
||||
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
|
||||
expect(taskManager.schedule).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('sets API key when createAPIKey returns one', async () => {
|
||||
alertsClientParams.createAPIKey.mockResolvedValueOnce({
|
||||
rulesClientParams.createAPIKey.mockResolvedValueOnce({
|
||||
apiKeysEnabled: true,
|
||||
result: { id: '123', name: '123', api_key: 'abc' },
|
||||
});
|
||||
|
||||
await alertsClient.enable({ id: '1' });
|
||||
await rulesClient.enable({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.update).toHaveBeenCalledWith(
|
||||
'alert',
|
||||
'1',
|
||||
|
@ -380,11 +380,11 @@ describe('enable()', () => {
|
|||
});
|
||||
|
||||
test('throws an error if API key creation throws', async () => {
|
||||
alertsClientParams.createAPIKey.mockImplementation(() => {
|
||||
rulesClientParams.createAPIKey.mockImplementation(() => {
|
||||
throw new Error('no');
|
||||
});
|
||||
expect(
|
||||
async () => await alertsClient.enable({ id: '1' })
|
||||
async () => await rulesClient.enable({ id: '1' })
|
||||
).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Error enabling rule: could not create API key - no"`
|
||||
);
|
||||
|
@ -393,9 +393,9 @@ describe('enable()', () => {
|
|||
test('falls back when failing to getDecryptedAsInternalUser', async () => {
|
||||
encryptedSavedObjects.getDecryptedAsInternalUser.mockRejectedValue(new Error('Fail'));
|
||||
|
||||
await alertsClient.enable({ id: '1' });
|
||||
await rulesClient.enable({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.get).toHaveBeenCalledWith('alert', '1');
|
||||
expect(alertsClientParams.logger.error).toHaveBeenCalledWith(
|
||||
expect(rulesClientParams.logger.error).toHaveBeenCalledWith(
|
||||
'enable(): Failed to load API key to invalidate on alert 1: Fail'
|
||||
);
|
||||
});
|
||||
|
@ -404,18 +404,18 @@ describe('enable()', () => {
|
|||
encryptedSavedObjects.getDecryptedAsInternalUser.mockRejectedValue(new Error('Fail'));
|
||||
unsecuredSavedObjectsClient.get.mockRejectedValueOnce(new Error('Fail to get'));
|
||||
|
||||
await expect(alertsClient.enable({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.enable({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Fail to get"`
|
||||
);
|
||||
expect(alertsClientParams.getUserName).not.toHaveBeenCalled();
|
||||
expect(alertsClientParams.createAPIKey).not.toHaveBeenCalled();
|
||||
expect(rulesClientParams.getUserName).not.toHaveBeenCalled();
|
||||
expect(rulesClientParams.createAPIKey).not.toHaveBeenCalled();
|
||||
expect(unsecuredSavedObjectsClient.update).not.toHaveBeenCalled();
|
||||
expect(taskManager.schedule).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('throws error when failing to update the first time', async () => {
|
||||
const createdAt = new Date().toISOString();
|
||||
alertsClientParams.createAPIKey.mockResolvedValueOnce({
|
||||
rulesClientParams.createAPIKey.mockResolvedValueOnce({
|
||||
apiKeysEnabled: true,
|
||||
result: { id: '123', name: '123', api_key: 'abc' },
|
||||
});
|
||||
|
@ -431,11 +431,11 @@ describe('enable()', () => {
|
|||
references: [],
|
||||
});
|
||||
|
||||
await expect(alertsClient.enable({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.enable({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Fail to update"`
|
||||
);
|
||||
expect(alertsClientParams.getUserName).toHaveBeenCalled();
|
||||
expect(alertsClientParams.createAPIKey).toHaveBeenCalled();
|
||||
expect(rulesClientParams.getUserName).toHaveBeenCalled();
|
||||
expect(rulesClientParams.createAPIKey).toHaveBeenCalled();
|
||||
expect(
|
||||
(unsecuredSavedObjectsClient.create.mock.calls[0][1] as InvalidatePendingApiKey).apiKeyId
|
||||
).toBe('123');
|
||||
|
@ -456,11 +456,11 @@ describe('enable()', () => {
|
|||
new Error('Fail to update second time')
|
||||
);
|
||||
|
||||
await expect(alertsClient.enable({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.enable({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Fail to update second time"`
|
||||
);
|
||||
expect(alertsClientParams.getUserName).toHaveBeenCalled();
|
||||
expect(alertsClientParams.createAPIKey).toHaveBeenCalled();
|
||||
expect(rulesClientParams.getUserName).toHaveBeenCalled();
|
||||
expect(rulesClientParams.createAPIKey).toHaveBeenCalled();
|
||||
expect(unsecuredSavedObjectsClient.update).toHaveBeenCalledTimes(2);
|
||||
expect(taskManager.schedule).toHaveBeenCalled();
|
||||
});
|
||||
|
@ -468,11 +468,11 @@ describe('enable()', () => {
|
|||
test('throws error when failing to schedule task', async () => {
|
||||
taskManager.schedule.mockRejectedValueOnce(new Error('Fail to schedule'));
|
||||
|
||||
await expect(alertsClient.enable({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.enable({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Fail to schedule"`
|
||||
);
|
||||
expect(alertsClientParams.getUserName).toHaveBeenCalled();
|
||||
expect(alertsClientParams.createAPIKey).toHaveBeenCalled();
|
||||
expect(rulesClientParams.getUserName).toHaveBeenCalled();
|
||||
expect(rulesClientParams.createAPIKey).toHaveBeenCalled();
|
||||
expect(unsecuredSavedObjectsClient.update).toHaveBeenCalled();
|
||||
});
|
||||
});
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { AlertsClient, ConstructorOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -31,7 +31,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKibanaRequest());
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -49,7 +49,7 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
@ -139,8 +139,8 @@ describe('find()', () => {
|
|||
});
|
||||
|
||||
test('calls saved objects client with given params', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const result = await alertsClient.find({ options: {} });
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
const result = await rulesClient.find({ options: {} });
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"data": Array [
|
||||
|
@ -186,8 +186,8 @@ describe('find()', () => {
|
|||
});
|
||||
|
||||
test('calls mapSortField', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
await alertsClient.find({ options: { sortField: 'name' } });
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
await rulesClient.find({ options: { sortField: 'name' } });
|
||||
expect(jest.requireMock('../lib/map_sort_field').mapSortField).toHaveBeenCalledWith('name');
|
||||
});
|
||||
|
||||
|
@ -319,8 +319,8 @@ describe('find()', () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const result = await alertsClient.find({ options: {} });
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
const result = await rulesClient.find({ options: {} });
|
||||
|
||||
expect(injectReferencesFn).toHaveBeenCalledTimes(1);
|
||||
expect(injectReferencesFn).toHaveBeenCalledWith(
|
||||
|
@ -514,8 +514,8 @@ describe('find()', () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
await expect(alertsClient.find({ options: {} })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
await expect(rulesClient.find({ options: {} })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Error injecting reference into rule params for rule id 2 - something went wrong!"`
|
||||
);
|
||||
});
|
||||
|
@ -531,8 +531,8 @@ describe('find()', () => {
|
|||
logSuccessfulAuthorization() {},
|
||||
});
|
||||
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
await alertsClient.find({ options: { filter: 'someTerm' } });
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
await rulesClient.find({ options: { filter: 'someTerm' } });
|
||||
|
||||
const [options] = unsecuredSavedObjectsClient.find.mock.calls[0];
|
||||
expect(options.filter).toEqual(
|
||||
|
@ -542,9 +542,9 @@ describe('find()', () => {
|
|||
});
|
||||
|
||||
test('throws if user is not authorized to find any types', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
authorization.getFindAuthorizationFilter.mockRejectedValue(new Error('not authorized'));
|
||||
await expect(alertsClient.find({ options: {} })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.find({ options: {} })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"not authorized"`
|
||||
);
|
||||
});
|
||||
|
@ -578,8 +578,8 @@ describe('find()', () => {
|
|||
],
|
||||
});
|
||||
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
expect(await alertsClient.find({ options: { fields: ['tags'] } })).toMatchInlineSnapshot(`
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
expect(await rulesClient.find({ options: { fields: ['tags'] } })).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"data": Array [
|
||||
Object {
|
||||
|
@ -610,8 +610,8 @@ describe('find()', () => {
|
|||
|
||||
describe('auditLogger', () => {
|
||||
test('logs audit event when searching rules', async () => {
|
||||
const alertsClient = new AlertsClient({ ...alertsClientParams, auditLogger });
|
||||
await alertsClient.find();
|
||||
const rulesClient = new RulesClient({ ...rulesClientParams, auditLogger });
|
||||
await rulesClient.find();
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
||||
|
@ -624,10 +624,10 @@ describe('find()', () => {
|
|||
});
|
||||
|
||||
test('logs audit event when not authorised to search rules', async () => {
|
||||
const alertsClient = new AlertsClient({ ...alertsClientParams, auditLogger });
|
||||
const rulesClient = new RulesClient({ ...rulesClientParams, auditLogger });
|
||||
authorization.getFindAuthorizationFilter.mockRejectedValue(new Error('Unauthorized'));
|
||||
|
||||
await expect(alertsClient.find()).rejects.toThrow();
|
||||
await expect(rulesClient.find()).rejects.toThrow();
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
||||
|
@ -643,7 +643,7 @@ describe('find()', () => {
|
|||
});
|
||||
|
||||
test('logs audit event when not authorised to search rule type', async () => {
|
||||
const alertsClient = new AlertsClient({ ...alertsClientParams, auditLogger });
|
||||
const rulesClient = new RulesClient({ ...rulesClientParams, auditLogger });
|
||||
authorization.getFindAuthorizationFilter.mockResolvedValue({
|
||||
ensureRuleTypeIsAuthorized: jest.fn(() => {
|
||||
throw new Error('Unauthorized');
|
||||
|
@ -651,7 +651,7 @@ describe('find()', () => {
|
|||
logSuccessfulAuthorization: jest.fn(),
|
||||
});
|
||||
|
||||
await expect(async () => await alertsClient.find()).rejects.toThrow();
|
||||
await expect(async () => await rulesClient.find()).rejects.toThrow();
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { AlertsClient, ConstructorOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -28,7 +28,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKibanaRequest());
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -46,7 +46,7 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
@ -54,7 +54,7 @@ setGlobalDate();
|
|||
|
||||
describe('get()', () => {
|
||||
test('calls saved objects client with given params', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -85,7 +85,7 @@ describe('get()', () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
const result = await alertsClient.get({ id: '1' });
|
||||
const result = await rulesClient.get({ id: '1' });
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"actions": Array [
|
||||
|
@ -139,7 +139,7 @@ describe('get()', () => {
|
|||
injectReferences: injectReferencesFn,
|
||||
},
|
||||
}));
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -176,7 +176,7 @@ describe('get()', () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
const result = await alertsClient.get({ id: '1' });
|
||||
const result = await rulesClient.get({ id: '1' });
|
||||
|
||||
expect(injectReferencesFn).toHaveBeenCalledWith(
|
||||
{
|
||||
|
@ -213,7 +213,7 @@ describe('get()', () => {
|
|||
});
|
||||
|
||||
test(`throws an error when references aren't found`, async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -235,7 +235,7 @@ describe('get()', () => {
|
|||
},
|
||||
references: [],
|
||||
});
|
||||
await expect(alertsClient.get({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.get({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Action reference \\"action_0\\" not found in alert id: 1"`
|
||||
);
|
||||
});
|
||||
|
@ -259,7 +259,7 @@ describe('get()', () => {
|
|||
injectReferences: injectReferencesFn,
|
||||
},
|
||||
}));
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -296,7 +296,7 @@ describe('get()', () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
await expect(alertsClient.get({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
await expect(rulesClient.get({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Error injecting reference into rule params for rule id 1 - something went wrong!"`
|
||||
);
|
||||
});
|
||||
|
@ -334,8 +334,8 @@ describe('get()', () => {
|
|||
});
|
||||
|
||||
test('ensures user is authorised to get this type of alert under the consumer', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
await alertsClient.get({ id: '1' });
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
await rulesClient.get({ id: '1' });
|
||||
|
||||
expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
|
||||
entity: 'rule',
|
||||
|
@ -346,12 +346,12 @@ describe('get()', () => {
|
|||
});
|
||||
|
||||
test('throws when user is not authorised to get this type of alert', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
authorization.ensureAuthorized.mockRejectedValue(
|
||||
new Error(`Unauthorized to get a "myType" alert for "myApp"`)
|
||||
);
|
||||
|
||||
await expect(alertsClient.get({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
await expect(rulesClient.get({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
`[Error: Unauthorized to get a "myType" alert for "myApp"]`
|
||||
);
|
||||
|
||||
|
@ -382,8 +382,8 @@ describe('get()', () => {
|
|||
});
|
||||
|
||||
test('logs audit event when getting a rule', async () => {
|
||||
const alertsClient = new AlertsClient({ ...alertsClientParams, auditLogger });
|
||||
await alertsClient.get({ id: '1' });
|
||||
const rulesClient = new RulesClient({ ...rulesClientParams, auditLogger });
|
||||
await rulesClient.get({ id: '1' });
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
||||
|
@ -396,10 +396,10 @@ describe('get()', () => {
|
|||
});
|
||||
|
||||
test('logs audit event when not authorised to get a rule', async () => {
|
||||
const alertsClient = new AlertsClient({ ...alertsClientParams, auditLogger });
|
||||
const rulesClient = new RulesClient({ ...rulesClientParams, auditLogger });
|
||||
authorization.ensureAuthorized.mockRejectedValue(new Error('Unauthorized'));
|
||||
|
||||
await expect(alertsClient.get({ id: '1' })).rejects.toThrow();
|
||||
await expect(rulesClient.get({ id: '1' })).rejects.toThrow();
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { AlertsClient, ConstructorOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -31,7 +31,7 @@ const authorization = alertingAuthorizationMock.create();
|
|||
const actionsAuthorization = actionsAuthorizationMock.create();
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -49,7 +49,7 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry, eventLogClient);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry, eventLogClient);
|
||||
});
|
||||
|
||||
setGlobalDate();
|
||||
|
@ -104,10 +104,10 @@ function getAlertInstanceSummarySavedObject(
|
|||
}
|
||||
|
||||
describe('getAlertInstanceSummary()', () => {
|
||||
let alertsClient: AlertsClient;
|
||||
let rulesClient: RulesClient;
|
||||
|
||||
beforeEach(() => {
|
||||
alertsClient = new AlertsClient(alertsClientParams);
|
||||
rulesClient = new RulesClient(rulesClientParams);
|
||||
});
|
||||
|
||||
test('runs as expected with some event log data', async () => {
|
||||
|
@ -137,7 +137,7 @@ describe('getAlertInstanceSummary()', () => {
|
|||
|
||||
const dateStart = new Date(Date.now() - 60 * 1000).toISOString();
|
||||
|
||||
const result = await alertsClient.getAlertInstanceSummary({ id: '1', dateStart });
|
||||
const result = await rulesClient.getAlertInstanceSummary({ id: '1', dateStart });
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"alertTypeId": "123",
|
||||
|
@ -194,7 +194,7 @@ describe('getAlertInstanceSummary()', () => {
|
|||
AlertInstanceSummaryFindEventsResult
|
||||
);
|
||||
|
||||
await alertsClient.getAlertInstanceSummary({ id: '1' });
|
||||
await rulesClient.getAlertInstanceSummary({ id: '1' });
|
||||
|
||||
expect(unsecuredSavedObjectsClient.get).toHaveBeenCalledTimes(1);
|
||||
expect(eventLogClient.findEventsBySavedObjectIds).toHaveBeenCalledTimes(1);
|
||||
|
@ -233,7 +233,7 @@ describe('getAlertInstanceSummary()', () => {
|
|||
const dateStart = new Date(
|
||||
Date.now() - 60 * AlertInstanceSummaryIntervalSeconds * 1000
|
||||
).toISOString();
|
||||
await alertsClient.getAlertInstanceSummary({ id: '1', dateStart });
|
||||
await rulesClient.getAlertInstanceSummary({ id: '1', dateStart });
|
||||
|
||||
expect(unsecuredSavedObjectsClient.get).toHaveBeenCalledTimes(1);
|
||||
expect(eventLogClient.findEventsBySavedObjectIds).toHaveBeenCalledTimes(1);
|
||||
|
@ -254,7 +254,7 @@ describe('getAlertInstanceSummary()', () => {
|
|||
);
|
||||
|
||||
const dateStart = '2m';
|
||||
await alertsClient.getAlertInstanceSummary({ id: '1', dateStart });
|
||||
await rulesClient.getAlertInstanceSummary({ id: '1', dateStart });
|
||||
|
||||
expect(unsecuredSavedObjectsClient.get).toHaveBeenCalledTimes(1);
|
||||
expect(eventLogClient.findEventsBySavedObjectIds).toHaveBeenCalledTimes(1);
|
||||
|
@ -276,7 +276,7 @@ describe('getAlertInstanceSummary()', () => {
|
|||
|
||||
const dateStart = 'ain"t no way this will get parsed as a date';
|
||||
expect(
|
||||
alertsClient.getAlertInstanceSummary({ id: '1', dateStart })
|
||||
rulesClient.getAlertInstanceSummary({ id: '1', dateStart })
|
||||
).rejects.toMatchInlineSnapshot(
|
||||
`[Error: Invalid date for parameter dateStart: "ain"t no way this will get parsed as a date"]`
|
||||
);
|
||||
|
@ -288,7 +288,7 @@ describe('getAlertInstanceSummary()', () => {
|
|||
AlertInstanceSummaryFindEventsResult
|
||||
);
|
||||
|
||||
expect(alertsClient.getAlertInstanceSummary({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
expect(rulesClient.getAlertInstanceSummary({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
`[Error: OMG!]`
|
||||
);
|
||||
});
|
||||
|
@ -298,6 +298,6 @@ describe('getAlertInstanceSummary()', () => {
|
|||
eventLogClient.findEventsBySavedObjectIds.mockRejectedValueOnce(new Error('OMG 2!'));
|
||||
|
||||
// error eaten but logged
|
||||
await alertsClient.getAlertInstanceSummary({ id: '1' });
|
||||
await rulesClient.getAlertInstanceSummary({ id: '1' });
|
||||
});
|
||||
});
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { AlertsClient, ConstructorOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -26,7 +26,7 @@ const authorization = alertingAuthorizationMock.create();
|
|||
const actionsAuthorization = actionsAuthorizationMock.create();
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -44,12 +44,12 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
});
|
||||
|
||||
describe('getAlertState()', () => {
|
||||
test('calls saved objects client with given params', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -92,7 +92,7 @@ describe('getAlertState()', () => {
|
|||
ownerId: null,
|
||||
});
|
||||
|
||||
await alertsClient.getAlertState({ id: '1' });
|
||||
await rulesClient.getAlertState({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.get).toHaveBeenCalledTimes(1);
|
||||
expect(unsecuredSavedObjectsClient.get.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
|
@ -103,7 +103,7 @@ describe('getAlertState()', () => {
|
|||
});
|
||||
|
||||
test('gets the underlying task from TaskManager', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
|
||||
const scheduledTaskId = 'task-123';
|
||||
|
||||
|
@ -155,7 +155,7 @@ describe('getAlertState()', () => {
|
|||
ownerId: null,
|
||||
});
|
||||
|
||||
await alertsClient.getAlertState({ id: '1' });
|
||||
await rulesClient.getAlertState({ id: '1' });
|
||||
expect(taskManager.get).toHaveBeenCalledTimes(1);
|
||||
expect(taskManager.get).toHaveBeenCalledWith(scheduledTaskId);
|
||||
});
|
||||
|
@ -207,8 +207,8 @@ describe('getAlertState()', () => {
|
|||
});
|
||||
|
||||
test('ensures user is authorised to get this type of alert under the consumer', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
await alertsClient.getAlertState({ id: '1' });
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
await rulesClient.getAlertState({ id: '1' });
|
||||
|
||||
expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
|
||||
entity: 'rule',
|
||||
|
@ -219,7 +219,7 @@ describe('getAlertState()', () => {
|
|||
});
|
||||
|
||||
test('throws when user is not authorised to getAlertState this type of alert', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
// `get` check
|
||||
authorization.ensureAuthorized.mockResolvedValueOnce();
|
||||
// `getRuleState` check
|
||||
|
@ -227,7 +227,7 @@ describe('getAlertState()', () => {
|
|||
new Error(`Unauthorized to getRuleState a "myType" alert for "myApp"`)
|
||||
);
|
||||
|
||||
await expect(alertsClient.getAlertState({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
await expect(rulesClient.getAlertState({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
`[Error: Unauthorized to getRuleState a "myType" alert for "myApp"]`
|
||||
);
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { IEventLogClient } from '../../../../event_log/server';
|
||||
import { actionsClientMock } from '../../../../actions/server/mocks';
|
||||
import { ConstructorOptions } from '../alerts_client';
|
||||
import { ConstructorOptions } from '../rules_client';
|
||||
import { eventLogClientMock } from '../../../../event_log/server/mocks';
|
||||
import { AlertTypeRegistry } from '../../alert_type_registry';
|
||||
import { RecoveredActionGroup } from '../../../common';
|
||||
|
@ -42,14 +42,14 @@ export function setGlobalDate() {
|
|||
}
|
||||
|
||||
export function getBeforeSetup(
|
||||
alertsClientParams: jest.Mocked<ConstructorOptions>,
|
||||
rulesClientParams: jest.Mocked<ConstructorOptions>,
|
||||
taskManager: ReturnType<typeof taskManagerMock.createStart>,
|
||||
alertTypeRegistry: jest.Mocked<Pick<AlertTypeRegistry, 'get' | 'has' | 'register' | 'list'>>,
|
||||
eventLogClient?: jest.Mocked<IEventLogClient>
|
||||
) {
|
||||
jest.resetAllMocks();
|
||||
alertsClientParams.createAPIKey.mockResolvedValue({ apiKeysEnabled: false });
|
||||
alertsClientParams.getUserName.mockResolvedValue('elastic');
|
||||
rulesClientParams.createAPIKey.mockResolvedValue({ apiKeysEnabled: false });
|
||||
rulesClientParams.getUserName.mockResolvedValue('elastic');
|
||||
taskManager.runNow.mockResolvedValue({ id: '' });
|
||||
const actionsClient = actionsClientMock.create();
|
||||
|
||||
|
@ -79,7 +79,7 @@ export function getBeforeSetup(
|
|||
name: 'test',
|
||||
},
|
||||
]);
|
||||
alertsClientParams.getActionsClient.mockResolvedValue(actionsClient);
|
||||
rulesClientParams.getActionsClient.mockResolvedValue(actionsClient);
|
||||
|
||||
alertTypeRegistry.get.mockImplementation(() => ({
|
||||
id: '123',
|
||||
|
@ -92,7 +92,7 @@ export function getBeforeSetup(
|
|||
async executor() {},
|
||||
producer: 'alerts',
|
||||
}));
|
||||
alertsClientParams.getEventLogClient.mockResolvedValue(
|
||||
rulesClientParams.getEventLogClient.mockResolvedValue(
|
||||
eventLogClient ?? eventLogClientMock.create()
|
||||
);
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { AlertsClient, ConstructorOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -30,7 +30,7 @@ const authorization = alertingAuthorizationMock.create();
|
|||
const actionsAuthorization = actionsAuthorizationMock.create();
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -48,11 +48,11 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
});
|
||||
|
||||
describe('listAlertTypes', () => {
|
||||
let alertsClient: AlertsClient;
|
||||
let rulesClient: RulesClient;
|
||||
const alertingAlertType: RegistryAlertType = {
|
||||
actionGroups: [],
|
||||
actionVariables: undefined,
|
||||
|
@ -86,7 +86,7 @@ describe('listAlertTypes', () => {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
alertsClient = new AlertsClient(alertsClientParams);
|
||||
rulesClient = new RulesClient(rulesClientParams);
|
||||
});
|
||||
|
||||
test('should return a list of AlertTypes that exist in the registry', async () => {
|
||||
|
@ -97,7 +97,7 @@ describe('listAlertTypes', () => {
|
|||
{ ...alertingAlertType, authorizedConsumers },
|
||||
])
|
||||
);
|
||||
expect(await alertsClient.listAlertTypes()).toEqual(
|
||||
expect(await rulesClient.listAlertTypes()).toEqual(
|
||||
new Set([
|
||||
{ ...myAppAlertType, authorizedConsumers },
|
||||
{ ...alertingAlertType, authorizedConsumers },
|
||||
|
@ -154,7 +154,7 @@ describe('listAlertTypes', () => {
|
|||
]);
|
||||
authorization.filterByRuleTypeAuthorization.mockResolvedValue(authorizedTypes);
|
||||
|
||||
expect(await alertsClient.listAlertTypes()).toEqual(authorizedTypes);
|
||||
expect(await rulesClient.listAlertTypes()).toEqual(authorizedTypes);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { AlertsClient, ConstructorOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -27,7 +27,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKibanaRequest());
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -45,7 +45,7 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
@ -53,7 +53,7 @@ setGlobalDate();
|
|||
|
||||
describe('muteAll()', () => {
|
||||
test('mutes an alert', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -75,7 +75,7 @@ describe('muteAll()', () => {
|
|||
version: '123',
|
||||
});
|
||||
|
||||
await alertsClient.muteAll({ id: '1' });
|
||||
await rulesClient.muteAll({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.update).toHaveBeenCalledWith(
|
||||
'alert',
|
||||
'1',
|
||||
|
@ -123,8 +123,8 @@ describe('muteAll()', () => {
|
|||
});
|
||||
|
||||
test('ensures user is authorised to muteAll this type of alert under the consumer', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
await alertsClient.muteAll({ id: '1' });
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
await rulesClient.muteAll({ id: '1' });
|
||||
|
||||
expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
|
||||
entity: 'rule',
|
||||
|
@ -136,12 +136,12 @@ describe('muteAll()', () => {
|
|||
});
|
||||
|
||||
test('throws when user is not authorised to muteAll this type of alert', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
authorization.ensureAuthorized.mockRejectedValue(
|
||||
new Error(`Unauthorized to muteAll a "myType" alert for "myApp"`)
|
||||
);
|
||||
|
||||
await expect(alertsClient.muteAll({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
await expect(rulesClient.muteAll({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
`[Error: Unauthorized to muteAll a "myType" alert for "myApp"]`
|
||||
);
|
||||
|
||||
|
@ -156,7 +156,7 @@ describe('muteAll()', () => {
|
|||
|
||||
describe('auditLogger', () => {
|
||||
test('logs audit event when muting a rule', async () => {
|
||||
const alertsClient = new AlertsClient({ ...alertsClientParams, auditLogger });
|
||||
const rulesClient = new RulesClient({ ...rulesClientParams, auditLogger });
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -177,7 +177,7 @@ describe('muteAll()', () => {
|
|||
references: [],
|
||||
version: '123',
|
||||
});
|
||||
await alertsClient.muteAll({ id: '1' });
|
||||
await rulesClient.muteAll({ id: '1' });
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
||||
|
@ -190,7 +190,7 @@ describe('muteAll()', () => {
|
|||
});
|
||||
|
||||
test('logs audit event when not authorised to mute a rule', async () => {
|
||||
const alertsClient = new AlertsClient({ ...alertsClientParams, auditLogger });
|
||||
const rulesClient = new RulesClient({ ...rulesClientParams, auditLogger });
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -213,7 +213,7 @@ describe('muteAll()', () => {
|
|||
});
|
||||
authorization.ensureAuthorized.mockRejectedValue(new Error('Unauthorized'));
|
||||
|
||||
await expect(alertsClient.muteAll({ id: '1' })).rejects.toThrow();
|
||||
await expect(rulesClient.muteAll({ id: '1' })).rejects.toThrow();
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { AlertsClient, ConstructorOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -27,7 +27,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKibanaRequest());
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -45,7 +45,7 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
@ -53,7 +53,7 @@ setGlobalDate();
|
|||
|
||||
describe('muteInstance()', () => {
|
||||
test('mutes an alert instance', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -69,7 +69,7 @@ describe('muteInstance()', () => {
|
|||
references: [],
|
||||
});
|
||||
|
||||
await alertsClient.muteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
await rulesClient.muteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
expect(unsecuredSavedObjectsClient.update).toHaveBeenCalledWith(
|
||||
'alert',
|
||||
'1',
|
||||
|
@ -85,7 +85,7 @@ describe('muteInstance()', () => {
|
|||
});
|
||||
|
||||
test('skips muting when alert instance already muted', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -100,12 +100,12 @@ describe('muteInstance()', () => {
|
|||
references: [],
|
||||
});
|
||||
|
||||
await alertsClient.muteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
await rulesClient.muteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('skips muting when alert is muted', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -121,7 +121,7 @@ describe('muteInstance()', () => {
|
|||
references: [],
|
||||
});
|
||||
|
||||
await alertsClient.muteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
await rulesClient.muteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
@ -155,8 +155,8 @@ describe('muteInstance()', () => {
|
|||
});
|
||||
|
||||
test('ensures user is authorised to muteInstance this type of alert under the consumer', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
await alertsClient.muteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
await rulesClient.muteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
|
||||
expect(actionsAuthorization.ensureAuthorized).toHaveBeenCalledWith('execute');
|
||||
expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
|
||||
|
@ -168,13 +168,13 @@ describe('muteInstance()', () => {
|
|||
});
|
||||
|
||||
test('throws when user is not authorised to muteInstance this type of alert', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
authorization.ensureAuthorized.mockRejectedValue(
|
||||
new Error(`Unauthorized to muteAlert a "myType" alert for "myApp"`)
|
||||
);
|
||||
|
||||
await expect(
|
||||
alertsClient.muteInstance({ alertId: '1', alertInstanceId: '2' })
|
||||
rulesClient.muteInstance({ alertId: '1', alertInstanceId: '2' })
|
||||
).rejects.toMatchInlineSnapshot(
|
||||
`[Error: Unauthorized to muteAlert a "myType" alert for "myApp"]`
|
||||
);
|
||||
|
@ -190,7 +190,7 @@ describe('muteInstance()', () => {
|
|||
|
||||
describe('auditLogger', () => {
|
||||
test('logs audit event when muting an alert', async () => {
|
||||
const alertsClient = new AlertsClient({ ...alertsClientParams, auditLogger });
|
||||
const rulesClient = new RulesClient({ ...rulesClientParams, auditLogger });
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -205,7 +205,7 @@ describe('muteInstance()', () => {
|
|||
version: '123',
|
||||
references: [],
|
||||
});
|
||||
await alertsClient.muteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
await rulesClient.muteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
||||
|
@ -218,7 +218,7 @@ describe('muteInstance()', () => {
|
|||
});
|
||||
|
||||
test('logs audit event when not authorised to mute an alert', async () => {
|
||||
const alertsClient = new AlertsClient({ ...alertsClientParams, auditLogger });
|
||||
const rulesClient = new RulesClient({ ...rulesClientParams, auditLogger });
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -236,7 +236,7 @@ describe('muteInstance()', () => {
|
|||
authorization.ensureAuthorized.mockRejectedValue(new Error('Unauthorized'));
|
||||
|
||||
await expect(
|
||||
alertsClient.muteInstance({ alertId: '1', alertInstanceId: '2' })
|
||||
rulesClient.muteInstance({ alertId: '1', alertInstanceId: '2' })
|
||||
).rejects.toThrow();
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { AlertsClient, ConstructorOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -27,7 +27,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKibanaRequest());
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -45,7 +45,7 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
@ -53,7 +53,7 @@ setGlobalDate();
|
|||
|
||||
describe('unmuteAll()', () => {
|
||||
test('unmutes an alert', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -75,7 +75,7 @@ describe('unmuteAll()', () => {
|
|||
version: '123',
|
||||
});
|
||||
|
||||
await alertsClient.unmuteAll({ id: '1' });
|
||||
await rulesClient.unmuteAll({ id: '1' });
|
||||
expect(unsecuredSavedObjectsClient.update).toHaveBeenCalledWith(
|
||||
'alert',
|
||||
'1',
|
||||
|
@ -123,8 +123,8 @@ describe('unmuteAll()', () => {
|
|||
});
|
||||
|
||||
test('ensures user is authorised to unmuteAll this type of alert under the consumer', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
await alertsClient.unmuteAll({ id: '1' });
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
await rulesClient.unmuteAll({ id: '1' });
|
||||
|
||||
expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
|
||||
entity: 'rule',
|
||||
|
@ -136,12 +136,12 @@ describe('unmuteAll()', () => {
|
|||
});
|
||||
|
||||
test('throws when user is not authorised to unmuteAll this type of alert', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
authorization.ensureAuthorized.mockRejectedValue(
|
||||
new Error(`Unauthorized to unmuteAll a "myType" alert for "myApp"`)
|
||||
);
|
||||
|
||||
await expect(alertsClient.unmuteAll({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
await expect(rulesClient.unmuteAll({ id: '1' })).rejects.toMatchInlineSnapshot(
|
||||
`[Error: Unauthorized to unmuteAll a "myType" alert for "myApp"]`
|
||||
);
|
||||
|
||||
|
@ -156,7 +156,7 @@ describe('unmuteAll()', () => {
|
|||
|
||||
describe('auditLogger', () => {
|
||||
test('logs audit event when unmuting a rule', async () => {
|
||||
const alertsClient = new AlertsClient({ ...alertsClientParams, auditLogger });
|
||||
const rulesClient = new RulesClient({ ...rulesClientParams, auditLogger });
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -177,7 +177,7 @@ describe('unmuteAll()', () => {
|
|||
references: [],
|
||||
version: '123',
|
||||
});
|
||||
await alertsClient.unmuteAll({ id: '1' });
|
||||
await rulesClient.unmuteAll({ id: '1' });
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
||||
|
@ -190,7 +190,7 @@ describe('unmuteAll()', () => {
|
|||
});
|
||||
|
||||
test('logs audit event when not authorised to unmute a rule', async () => {
|
||||
const alertsClient = new AlertsClient({ ...alertsClientParams, auditLogger });
|
||||
const rulesClient = new RulesClient({ ...rulesClientParams, auditLogger });
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -213,7 +213,7 @@ describe('unmuteAll()', () => {
|
|||
});
|
||||
authorization.ensureAuthorized.mockRejectedValue(new Error('Unauthorized'));
|
||||
|
||||
await expect(alertsClient.unmuteAll({ id: '1' })).rejects.toThrow();
|
||||
await expect(rulesClient.unmuteAll({ id: '1' })).rejects.toThrow();
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { AlertsClient, ConstructorOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -27,7 +27,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKibanaRequest());
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -45,7 +45,7 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
@ -53,7 +53,7 @@ setGlobalDate();
|
|||
|
||||
describe('unmuteInstance()', () => {
|
||||
test('unmutes an alert instance', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -69,7 +69,7 @@ describe('unmuteInstance()', () => {
|
|||
references: [],
|
||||
});
|
||||
|
||||
await alertsClient.unmuteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
await rulesClient.unmuteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
expect(unsecuredSavedObjectsClient.update).toHaveBeenCalledWith(
|
||||
'alert',
|
||||
'1',
|
||||
|
@ -83,7 +83,7 @@ describe('unmuteInstance()', () => {
|
|||
});
|
||||
|
||||
test('skips unmuting when alert instance not muted', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -98,12 +98,12 @@ describe('unmuteInstance()', () => {
|
|||
references: [],
|
||||
});
|
||||
|
||||
await alertsClient.unmuteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
await rulesClient.unmuteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('skips unmuting when alert is muted', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -119,7 +119,7 @@ describe('unmuteInstance()', () => {
|
|||
references: [],
|
||||
});
|
||||
|
||||
await alertsClient.unmuteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
await rulesClient.unmuteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
@ -153,8 +153,8 @@ describe('unmuteInstance()', () => {
|
|||
});
|
||||
|
||||
test('ensures user is authorised to unmuteInstance this type of alert under the consumer', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
await alertsClient.unmuteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
await rulesClient.unmuteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
|
||||
expect(actionsAuthorization.ensureAuthorized).toHaveBeenCalledWith('execute');
|
||||
expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
|
||||
|
@ -166,13 +166,13 @@ describe('unmuteInstance()', () => {
|
|||
});
|
||||
|
||||
test('throws when user is not authorised to unmuteInstance this type of alert', async () => {
|
||||
const alertsClient = new AlertsClient(alertsClientParams);
|
||||
const rulesClient = new RulesClient(rulesClientParams);
|
||||
authorization.ensureAuthorized.mockRejectedValue(
|
||||
new Error(`Unauthorized to unmuteAlert a "myType" alert for "myApp"`)
|
||||
);
|
||||
|
||||
await expect(
|
||||
alertsClient.unmuteInstance({ alertId: '1', alertInstanceId: '2' })
|
||||
rulesClient.unmuteInstance({ alertId: '1', alertInstanceId: '2' })
|
||||
).rejects.toMatchInlineSnapshot(
|
||||
`[Error: Unauthorized to unmuteAlert a "myType" alert for "myApp"]`
|
||||
);
|
||||
|
@ -188,7 +188,7 @@ describe('unmuteInstance()', () => {
|
|||
|
||||
describe('auditLogger', () => {
|
||||
test('logs audit event when unmuting an alert', async () => {
|
||||
const alertsClient = new AlertsClient({ ...alertsClientParams, auditLogger });
|
||||
const rulesClient = new RulesClient({ ...rulesClientParams, auditLogger });
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -203,7 +203,7 @@ describe('unmuteInstance()', () => {
|
|||
version: '123',
|
||||
references: [],
|
||||
});
|
||||
await alertsClient.unmuteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
await rulesClient.unmuteInstance({ alertId: '1', alertInstanceId: '2' });
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
event: expect.objectContaining({
|
||||
|
@ -216,7 +216,7 @@ describe('unmuteInstance()', () => {
|
|||
});
|
||||
|
||||
test('logs audit event when not authorised to unmute an alert', async () => {
|
||||
const alertsClient = new AlertsClient({ ...alertsClientParams, auditLogger });
|
||||
const rulesClient = new RulesClient({ ...rulesClientParams, auditLogger });
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValueOnce({
|
||||
id: '1',
|
||||
type: 'alert',
|
||||
|
@ -234,7 +234,7 @@ describe('unmuteInstance()', () => {
|
|||
authorization.ensureAuthorized.mockRejectedValue(new Error('Unauthorized'));
|
||||
|
||||
await expect(
|
||||
alertsClient.unmuteInstance({ alertId: '1', alertInstanceId: '2' })
|
||||
rulesClient.unmuteInstance({ alertId: '1', alertInstanceId: '2' })
|
||||
).rejects.toThrow();
|
||||
expect(auditLogger.log).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import uuid from 'uuid';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { AlertsClient, ConstructorOptions } from '../alerts_client';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
|
@ -39,7 +39,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKibanaRequest());
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
|
@ -58,14 +58,14 @@ const alertsClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(alertsClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
setGlobalDate();
|
||||
|
||||
describe('update()', () => {
|
||||
let alertsClient: AlertsClient;
|
||||
let rulesClient: RulesClient;
|
||||
let actionsClient: jest.Mocked<ActionsClient>;
|
||||
const existingAlert = {
|
||||
id: '1',
|
||||
|
@ -104,8 +104,8 @@ describe('update()', () => {
|
|||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
alertsClient = new AlertsClient(alertsClientParams);
|
||||
actionsClient = (await alertsClientParams.getActionsClient()) as jest.Mocked<ActionsClient>;
|
||||
rulesClient = new RulesClient(rulesClientParams);
|
||||
actionsClient = (await rulesClientParams.getActionsClient()) as jest.Mocked<ActionsClient>;
|
||||
actionsClient.getBulk.mockReset();
|
||||
actionsClient.getBulk.mockResolvedValue([
|
||||
{
|
||||
|
@ -124,7 +124,7 @@ describe('update()', () => {
|
|||
isPreconfigured: false,
|
||||
},
|
||||
]);
|
||||
alertsClientParams.getActionsClient.mockResolvedValue(actionsClient);
|
||||
rulesClientParams.getActionsClient.mockResolvedValue(actionsClient);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValue(existingAlert);
|
||||
encryptedSavedObjects.getDecryptedAsInternalUser.mockResolvedValue(existingDecryptedAlert);
|
||||
alertTypeRegistry.get.mockReturnValue({
|
||||
|
@ -241,7 +241,7 @@ describe('update()', () => {
|
|||
},
|
||||
references: [],
|
||||
});
|
||||
const result = await alertsClient.update({
|
||||
const result = await rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -482,7 +482,7 @@ describe('update()', () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
const result = await alertsClient.update({
|
||||
const result = await rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -574,7 +574,7 @@ describe('update()', () => {
|
|||
});
|
||||
|
||||
it('calls the createApiKey function', async () => {
|
||||
alertsClientParams.createAPIKey.mockResolvedValueOnce({
|
||||
rulesClientParams.createAPIKey.mockResolvedValueOnce({
|
||||
apiKeysEnabled: true,
|
||||
result: { id: '123', name: '123', api_key: 'abc' },
|
||||
});
|
||||
|
@ -630,7 +630,7 @@ describe('update()', () => {
|
|||
},
|
||||
references: [],
|
||||
});
|
||||
const result = await alertsClient.update({
|
||||
const result = await rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -786,7 +786,7 @@ describe('update()', () => {
|
|||
},
|
||||
references: [],
|
||||
});
|
||||
const result = await alertsClient.update({
|
||||
const result = await rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -808,7 +808,7 @@ describe('update()', () => {
|
|||
],
|
||||
},
|
||||
});
|
||||
expect(alertsClientParams.createAPIKey).not.toHaveBeenCalled();
|
||||
expect(rulesClientParams.createAPIKey).not.toHaveBeenCalled();
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"actions": Array [
|
||||
|
@ -893,12 +893,12 @@ describe('update()', () => {
|
|||
});
|
||||
|
||||
it('throws an error if API key creation throws', async () => {
|
||||
alertsClientParams.createAPIKey.mockImplementation(() => {
|
||||
rulesClientParams.createAPIKey.mockImplementation(() => {
|
||||
throw new Error('no');
|
||||
});
|
||||
expect(
|
||||
async () =>
|
||||
await alertsClient.update({
|
||||
await rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -957,7 +957,7 @@ describe('update()', () => {
|
|||
producer: 'alerts',
|
||||
});
|
||||
await expect(
|
||||
alertsClient.update({
|
||||
rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -1018,7 +1018,7 @@ describe('update()', () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
await alertsClient.update({
|
||||
await rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
...existingAlert.attributes,
|
||||
|
@ -1026,7 +1026,7 @@ describe('update()', () => {
|
|||
},
|
||||
});
|
||||
|
||||
expect(alertsClientParams.createAPIKey).toHaveBeenCalledWith('Alerting: myType/my alert name');
|
||||
expect(rulesClientParams.createAPIKey).toHaveBeenCalledWith('Alerting: myType/my alert name');
|
||||
});
|
||||
|
||||
it('swallows error when invalidate API key throws', async () => {
|
||||
|
@ -1060,7 +1060,7 @@ describe('update()', () => {
|
|||
],
|
||||
});
|
||||
unsecuredSavedObjectsClient.create.mockRejectedValueOnce(new Error('Fail')); // add ApiKey to invalidate
|
||||
await alertsClient.update({
|
||||
await rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -1082,7 +1082,7 @@ describe('update()', () => {
|
|||
],
|
||||
},
|
||||
});
|
||||
expect(alertsClientParams.logger.error).toHaveBeenCalledWith(
|
||||
expect(rulesClientParams.logger.error).toHaveBeenCalledWith(
|
||||
'Failed to mark for API key [id="MTIzOmFiYw=="] for invalidation: Fail'
|
||||
);
|
||||
});
|
||||
|
@ -1179,7 +1179,7 @@ describe('update()', () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
await alertsClient.update({
|
||||
await rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -1216,19 +1216,19 @@ describe('update()', () => {
|
|||
},
|
||||
});
|
||||
expect(unsecuredSavedObjectsClient.get).toHaveBeenCalledWith('alert', '1');
|
||||
expect(alertsClientParams.logger.error).toHaveBeenCalledWith(
|
||||
expect(rulesClientParams.logger.error).toHaveBeenCalledWith(
|
||||
'update(): Failed to load API key to invalidate on alert 1: Fail'
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when unsecuredSavedObjectsClient update fails and invalidates newly created API key', async () => {
|
||||
alertsClientParams.createAPIKey.mockResolvedValueOnce({
|
||||
rulesClientParams.createAPIKey.mockResolvedValueOnce({
|
||||
apiKeysEnabled: true,
|
||||
result: { id: '234', name: '234', api_key: 'abc' },
|
||||
});
|
||||
unsecuredSavedObjectsClient.create.mockRejectedValue(new Error('Fail'));
|
||||
await expect(
|
||||
alertsClient.update({
|
||||
rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -1338,7 +1338,7 @@ describe('update()', () => {
|
|||
|
||||
mockApiCalls(alertId, taskId, { interval: '60m' }, { interval: '10s' });
|
||||
|
||||
await alertsClient.update({
|
||||
await rulesClient.update({
|
||||
id: alertId,
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -1370,7 +1370,7 @@ describe('update()', () => {
|
|||
|
||||
mockApiCalls(alertId, taskId, { interval: '10s' }, { interval: '10s' });
|
||||
|
||||
await alertsClient.update({
|
||||
await rulesClient.update({
|
||||
id: alertId,
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -1407,7 +1407,7 @@ describe('update()', () => {
|
|||
taskManager.runNow.mockReset();
|
||||
taskManager.runNow.mockReturnValue(resolveAfterAlertUpdatedCompletes);
|
||||
|
||||
await alertsClient.update({
|
||||
await rulesClient.update({
|
||||
id: alertId,
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -1443,7 +1443,7 @@ describe('update()', () => {
|
|||
taskManager.runNow.mockReset();
|
||||
taskManager.runNow.mockRejectedValue(new Error('Failed to run alert'));
|
||||
|
||||
await alertsClient.update({
|
||||
await rulesClient.update({
|
||||
id: alertId,
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -1468,7 +1468,7 @@ describe('update()', () => {
|
|||
|
||||
expect(taskManager.runNow).toHaveBeenCalled();
|
||||
|
||||
expect(alertsClientParams.logger.error).toHaveBeenCalledWith(
|
||||
expect(rulesClientParams.logger.error).toHaveBeenCalledWith(
|
||||
`Alert update failed to run its underlying task. TaskManager runNow failed with Error: Failed to run alert`
|
||||
);
|
||||
});
|
||||
|
@ -1511,7 +1511,7 @@ describe('update()', () => {
|
|||
]);
|
||||
|
||||
await expect(
|
||||
alertsClient.update({
|
||||
rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -1575,7 +1575,7 @@ describe('update()', () => {
|
|||
});
|
||||
|
||||
test('ensures user is authorised to update this type of alert under the consumer', async () => {
|
||||
await alertsClient.update({
|
||||
await rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -1604,7 +1604,7 @@ describe('update()', () => {
|
|||
);
|
||||
|
||||
await expect(
|
||||
alertsClient.update({
|
||||
rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -1652,7 +1652,7 @@ describe('update()', () => {
|
|||
});
|
||||
|
||||
test('logs audit event when updating a rule', async () => {
|
||||
await alertsClient.update({
|
||||
await rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
||||
|
@ -1682,7 +1682,7 @@ describe('update()', () => {
|
|||
authorization.ensureAuthorized.mockRejectedValue(new Error('Unauthorized'));
|
||||
|
||||
await expect(
|
||||
alertsClient.update({
|
||||
rulesClient.update({
|
||||
id: '1',
|
||||
data: {
|
||||
schedule: { interval: '10s' },
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue