From 52c06ca9e477cf0750feffaf6d827782b0bb4675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20C=C3=B4t=C3=A9?= Date: Thu, 5 Mar 2020 11:30:59 -0500 Subject: [PATCH] Make actions config mock and license state mock use factory pattern and jest mocks (#59370) --- .../server/action_type_registry.test.ts | 26 +++++++----- .../actions/server/action_type_registry.ts | 4 +- .../actions/server/actions_client.test.ts | 4 +- .../actions/server/actions_config.mock.ts | 21 ++++++---- .../server/builtin_action_types/email.test.ts | 11 ++--- .../server/builtin_action_types/index.test.ts | 6 +-- .../builtin_action_types/pagerduty.test.ts | 6 +-- .../builtin_action_types/servicenow.test.ts | 6 +-- .../server/builtin_action_types/slack.test.ts | 10 ++--- .../builtin_action_types/webhook.test.ts | 6 +-- .../actions/server/lib/license_api_access.ts | 4 +- .../actions/server/lib/license_state.mock.ts | 41 ++++++------------- .../actions/server/lib/license_state.ts | 2 + x-pack/plugins/actions/server/plugin.ts | 4 +- .../actions/server/routes/create.test.ts | 8 ++-- .../plugins/actions/server/routes/create.ts | 4 +- .../actions/server/routes/delete.test.ts | 8 ++-- .../plugins/actions/server/routes/delete.ts | 4 +- .../actions/server/routes/execute.test.ts | 10 ++--- .../plugins/actions/server/routes/execute.ts | 4 +- .../actions/server/routes/find.test.ts | 8 ++-- x-pack/plugins/actions/server/routes/find.ts | 4 +- .../plugins/actions/server/routes/get.test.ts | 8 ++-- x-pack/plugins/actions/server/routes/get.ts | 4 +- .../server/routes/list_action_types.test.ts | 8 ++-- .../server/routes/list_action_types.ts | 4 +- .../actions/server/routes/update.test.ts | 8 ++-- .../plugins/actions/server/routes/update.ts | 4 +- 28 files changed, 117 insertions(+), 120 deletions(-) diff --git a/x-pack/plugins/actions/server/action_type_registry.test.ts b/x-pack/plugins/actions/server/action_type_registry.test.ts index f0d0a598a816b..45177c5b5044e 100644 --- a/x-pack/plugins/actions/server/action_type_registry.test.ts +++ b/x-pack/plugins/actions/server/action_type_registry.test.ts @@ -5,21 +5,27 @@ */ import { taskManagerMock } from '../../task_manager/server/task_manager.mock'; -import { ActionTypeRegistry } from './action_type_registry'; +import { ActionTypeRegistry, ActionTypeRegistryOpts } from './action_type_registry'; import { ExecutorType } from './types'; import { ActionExecutor, ExecutorError, TaskRunnerFactory } from './lib'; -import { configUtilsMock } from './actions_config.mock'; +import { actionsConfigMock } from './actions_config.mock'; +import { ActionsConfigurationUtilities } from './actions_config'; const mockTaskManager = taskManagerMock.setup(); -const actionTypeRegistryParams = { - taskManager: mockTaskManager, - taskRunnerFactory: new TaskRunnerFactory( - new ActionExecutor({ isESOUsingEphemeralEncryptionKey: false }) - ), - actionsConfigUtils: configUtilsMock, -}; +let mockedActionsConfig: jest.Mocked; +let actionTypeRegistryParams: ActionTypeRegistryOpts; -beforeEach(() => jest.resetAllMocks()); +beforeEach(() => { + jest.resetAllMocks(); + mockedActionsConfig = actionsConfigMock.create(); + actionTypeRegistryParams = { + taskManager: mockTaskManager, + taskRunnerFactory: new TaskRunnerFactory( + new ActionExecutor({ isESOUsingEphemeralEncryptionKey: false }) + ), + actionsConfigUtils: mockedActionsConfig, + }; +}); const executor: ExecutorType = async options => { return { status: 'ok', actionId: options.actionId }; diff --git a/x-pack/plugins/actions/server/action_type_registry.ts b/x-pack/plugins/actions/server/action_type_registry.ts index 42e0ee9f523e1..7d77a6b1358ff 100644 --- a/x-pack/plugins/actions/server/action_type_registry.ts +++ b/x-pack/plugins/actions/server/action_type_registry.ts @@ -12,7 +12,7 @@ import { ActionType } from './types'; import { ActionType as CommonActionType } from '../common'; import { ActionsConfigurationUtilities } from './actions_config'; -interface ConstructorOptions { +export interface ActionTypeRegistryOpts { taskManager: TaskManagerSetupContract; taskRunnerFactory: TaskRunnerFactory; actionsConfigUtils: ActionsConfigurationUtilities; @@ -24,7 +24,7 @@ export class ActionTypeRegistry { private readonly taskRunnerFactory: TaskRunnerFactory; private readonly actionsConfigUtils: ActionsConfigurationUtilities; - constructor(constructorParams: ConstructorOptions) { + constructor(constructorParams: ActionTypeRegistryOpts) { this.taskManager = constructorParams.taskManager; this.taskRunnerFactory = constructorParams.taskRunnerFactory; this.actionsConfigUtils = constructorParams.actionsConfigUtils; diff --git a/x-pack/plugins/actions/server/actions_client.test.ts b/x-pack/plugins/actions/server/actions_client.test.ts index bba9bd6aea0b3..dc212ab146664 100644 --- a/x-pack/plugins/actions/server/actions_client.test.ts +++ b/x-pack/plugins/actions/server/actions_client.test.ts @@ -11,7 +11,7 @@ import { ActionsClient } from './actions_client'; import { ExecutorType } from './types'; import { ActionExecutor, TaskRunnerFactory } from './lib'; import { taskManagerMock } from '../../task_manager/server/task_manager.mock'; -import { configUtilsMock } from './actions_config.mock'; +import { actionsConfigMock } from './actions_config.mock'; import { getActionsConfigurationUtilities } from './actions_config'; import { @@ -30,7 +30,7 @@ const actionTypeRegistryParams = { taskRunnerFactory: new TaskRunnerFactory( new ActionExecutor({ isESOUsingEphemeralEncryptionKey: false }) ), - actionsConfigUtils: configUtilsMock, + actionsConfigUtils: actionsConfigMock.create(), }; let actionsClient: ActionsClient; diff --git a/x-pack/plugins/actions/server/actions_config.mock.ts b/x-pack/plugins/actions/server/actions_config.mock.ts index b4e0324f9fead..addd35ae4f5f3 100644 --- a/x-pack/plugins/actions/server/actions_config.mock.ts +++ b/x-pack/plugins/actions/server/actions_config.mock.ts @@ -6,11 +6,18 @@ import { ActionsConfigurationUtilities } from './actions_config'; -export const configUtilsMock: ActionsConfigurationUtilities = { - isWhitelistedHostname: _ => true, - isWhitelistedUri: _ => true, - isActionTypeEnabled: _ => true, - ensureWhitelistedHostname: _ => {}, - ensureWhitelistedUri: _ => {}, - ensureActionTypeEnabled: _ => {}, +const createActionsConfigMock = () => { + const mocked: jest.Mocked = { + isWhitelistedHostname: jest.fn().mockReturnValue(true), + isWhitelistedUri: jest.fn().mockReturnValue(true), + isActionTypeEnabled: jest.fn().mockReturnValue(true), + ensureWhitelistedHostname: jest.fn().mockReturnValue({}), + ensureWhitelistedUri: jest.fn().mockReturnValue({}), + ensureActionTypeEnabled: jest.fn().mockReturnValue({}), + }; + return mocked; +}; + +export const actionsConfigMock = { + create: createActionsConfigMock, }; diff --git a/x-pack/plugins/actions/server/builtin_action_types/email.test.ts b/x-pack/plugins/actions/server/builtin_action_types/email.test.ts index 4ad4fe96f3447..0bd3992de30e6 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/email.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/email.test.ts @@ -12,7 +12,7 @@ import { Logger } from '../../../../../src/core/server'; import { savedObjectsClientMock } from '../../../../../src/core/server/mocks'; import { ActionType, ActionTypeExecutorOptions } from '../types'; -import { configUtilsMock } from '../actions_config.mock'; +import { actionsConfigMock } from '../actions_config.mock'; import { validateConfig, validateSecrets, validateParams } from '../lib'; import { createActionTypeRegistry } from './index.test'; import { sendEmail } from './lib/send_email'; @@ -37,13 +37,10 @@ const services = { let actionType: ActionType; let mockedLogger: jest.Mocked; -beforeAll(() => { - const { actionTypeRegistry } = createActionTypeRegistry(); - actionType = actionTypeRegistry.get(ACTION_TYPE_ID); -}); - beforeEach(() => { jest.resetAllMocks(); + const { actionTypeRegistry } = createActionTypeRegistry(); + actionType = actionTypeRegistry.get(ACTION_TYPE_ID); }); describe('actionTypeRegistry.get() works', () => { @@ -128,7 +125,7 @@ describe('config validation', () => { actionType = getActionType({ logger: mockedLogger, configurationUtilities: { - ...configUtilsMock, + ...actionsConfigMock.create(), isWhitelistedHostname: hostname => hostname === NODEMAILER_AOL_SERVICE_HOST, }, }); diff --git a/x-pack/plugins/actions/server/builtin_action_types/index.test.ts b/x-pack/plugins/actions/server/builtin_action_types/index.test.ts index db6375fe18193..5040d7242d1b2 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/index.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/index.test.ts @@ -10,7 +10,7 @@ import { taskManagerMock } from '../../../task_manager/server/task_manager.mock' import { registerBuiltInActionTypes } from './index'; import { Logger } from '../../../../../src/core/server'; import { loggingServiceMock } from '../../../../../src/core/server/mocks'; -import { configUtilsMock } from '../actions_config.mock'; +import { actionsConfigMock } from '../actions_config.mock'; const ACTION_TYPE_IDS = ['.index', '.email', '.pagerduty', '.server-log', '.slack', '.webhook']; @@ -24,12 +24,12 @@ export function createActionTypeRegistry(): { taskRunnerFactory: new TaskRunnerFactory( new ActionExecutor({ isESOUsingEphemeralEncryptionKey: false }) ), - actionsConfigUtils: configUtilsMock, + actionsConfigUtils: actionsConfigMock.create(), }); registerBuiltInActionTypes({ logger, actionTypeRegistry, - actionsConfigUtils: configUtilsMock, + actionsConfigUtils: actionsConfigMock.create(), }); return { logger, actionTypeRegistry }; } diff --git a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts index ab860e4c3bbba..643eb252a4bfc 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts @@ -15,7 +15,7 @@ import { savedObjectsClientMock } from '../../../../../src/core/server/mocks'; import { postPagerduty } from './lib/post_pagerduty'; import { createActionTypeRegistry } from './index.test'; import { Logger } from '../../../../../src/core/server'; -import { configUtilsMock } from '../actions_config.mock'; +import { actionsConfigMock } from '../actions_config.mock'; const postPagerdutyMock = postPagerduty as jest.Mock; @@ -60,7 +60,7 @@ describe('validateConfig()', () => { actionType = getActionType({ logger: mockedLogger, configurationUtilities: { - ...configUtilsMock, + ...actionsConfigMock.create(), ensureWhitelistedUri: url => { expect(url).toEqual('https://events.pagerduty.com/v2/enqueue'); }, @@ -76,7 +76,7 @@ describe('validateConfig()', () => { actionType = getActionType({ logger: mockedLogger, configurationUtilities: { - ...configUtilsMock, + ...actionsConfigMock.create(), ensureWhitelistedUri: _ => { throw new Error(`target url is not whitelisted`); }, diff --git a/x-pack/plugins/actions/server/builtin_action_types/servicenow.test.ts b/x-pack/plugins/actions/server/builtin_action_types/servicenow.test.ts index 9ae96cb23a5c3..f56158f27c580 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/servicenow.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/servicenow.test.ts @@ -14,7 +14,7 @@ import { validateConfig, validateSecrets, validateParams } from '../lib'; import { savedObjectsClientMock } from '../../../../../src/core/server/mocks'; import { postServiceNow } from './lib/post_servicenow'; import { createActionTypeRegistry } from './index.test'; -import { configUtilsMock } from '../actions_config.mock'; +import { actionsConfigMock } from '../actions_config.mock'; const postServiceNowMock = postServiceNow as jest.Mock; @@ -70,7 +70,7 @@ describe('validateConfig()', () => { test('should validate and pass when the servicenow url is whitelisted', () => { actionType = getActionType({ configurationUtilities: { - ...configUtilsMock, + ...actionsConfigMock.create(), ensureWhitelistedUri: url => { expect(url).toEqual('https://events.servicenow.com/v2/enqueue'); }, @@ -85,7 +85,7 @@ describe('validateConfig()', () => { test('config validation returns an error if the specified URL isnt whitelisted', () => { actionType = getActionType({ configurationUtilities: { - ...configUtilsMock, + ...actionsConfigMock.create(), ensureWhitelistedUri: _ => { throw new Error(`target url is not whitelisted`); }, diff --git a/x-pack/plugins/actions/server/builtin_action_types/slack.test.ts b/x-pack/plugins/actions/server/builtin_action_types/slack.test.ts index 919f0800c291c..49b0b84e9dbb5 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/slack.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/slack.test.ts @@ -8,7 +8,7 @@ import { ActionType, Services, ActionTypeExecutorOptions } from '../types'; import { savedObjectsClientMock } from '../../../../../src/core/server/mocks'; import { validateParams, validateSecrets } from '../lib'; import { getActionType } from './slack'; -import { configUtilsMock } from '../actions_config.mock'; +import { actionsConfigMock } from '../actions_config.mock'; const ACTION_TYPE_ID = '.slack'; @@ -22,7 +22,7 @@ let actionType: ActionType; beforeAll(() => { actionType = getActionType({ async executor(options: ActionTypeExecutorOptions): Promise {}, - configurationUtilities: configUtilsMock, + configurationUtilities: actionsConfigMock.create(), }); }); @@ -85,7 +85,7 @@ describe('validateActionTypeSecrets()', () => { test('should validate and pass when the slack webhookUrl is whitelisted', () => { actionType = getActionType({ configurationUtilities: { - ...configUtilsMock, + ...actionsConfigMock.create(), ensureWhitelistedUri: url => { expect(url).toEqual('https://api.slack.com/'); }, @@ -100,7 +100,7 @@ describe('validateActionTypeSecrets()', () => { test('config validation returns an error if the specified URL isnt whitelisted', () => { actionType = getActionType({ configurationUtilities: { - ...configUtilsMock, + ...actionsConfigMock.create(), ensureWhitelistedHostname: url => { throw new Error(`target hostname is not whitelisted`); }, @@ -135,7 +135,7 @@ describe('execute()', () => { actionType = getActionType({ executor: mockSlackExecutor, - configurationUtilities: configUtilsMock, + configurationUtilities: actionsConfigMock.create(), }); }); diff --git a/x-pack/plugins/actions/server/builtin_action_types/webhook.test.ts b/x-pack/plugins/actions/server/builtin_action_types/webhook.test.ts index e553e5c83712a..24656ef29a639 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/webhook.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/webhook.test.ts @@ -12,7 +12,7 @@ import { getActionType } from './webhook'; import { ActionType, Services } from '../types'; import { validateConfig, validateSecrets, validateParams } from '../lib'; import { savedObjectsClientMock } from '../../../../../src/core/server/mocks'; -import { configUtilsMock } from '../actions_config.mock'; +import { actionsConfigMock } from '../actions_config.mock'; import { createActionTypeRegistry } from './index.test'; import { Logger } from '../../../../../src/core/server'; import axios from 'axios'; @@ -164,7 +164,7 @@ describe('config validation', () => { actionType = getActionType({ logger: mockedLogger, configurationUtilities: { - ...configUtilsMock, + ...actionsConfigMock.create(), ensureWhitelistedUri: _ => { throw new Error(`target url is not whitelisted`); }, @@ -207,7 +207,7 @@ describe('execute()', () => { axiosRequestMock.mockReset(); actionType = getActionType({ logger: mockedLogger, - configurationUtilities: configUtilsMock, + configurationUtilities: actionsConfigMock.create(), }); }); diff --git a/x-pack/plugins/actions/server/lib/license_api_access.ts b/x-pack/plugins/actions/server/lib/license_api_access.ts index 2e650ebf5eb17..2055c66865c4e 100644 --- a/x-pack/plugins/actions/server/lib/license_api_access.ts +++ b/x-pack/plugins/actions/server/lib/license_api_access.ts @@ -5,9 +5,9 @@ */ import Boom from 'boom'; -import { LicenseState } from './license_state'; +import { ILicenseState } from './license_state'; -export function verifyApiAccess(licenseState: LicenseState) { +export function verifyApiAccess(licenseState: ILicenseState) { const licenseCheckResults = licenseState.getLicenseInformation(); if (licenseCheckResults.showAppLink && licenseCheckResults.enableAppLink) { diff --git a/x-pack/plugins/actions/server/lib/license_state.mock.ts b/x-pack/plugins/actions/server/lib/license_state.mock.ts index f36f3a9eaeade..835cb14432b3e 100644 --- a/x-pack/plugins/actions/server/lib/license_state.mock.ts +++ b/x-pack/plugins/actions/server/lib/license_state.mock.ts @@ -4,35 +4,20 @@ * you may not use this file except in compliance with the Elastic License. */ -import { of } from 'rxjs'; -import { LicenseState } from './license_state'; -import { LICENSE_CHECK_STATE, ILicense } from '../../../licensing/server'; +import { ILicenseState } from './license_state'; +import { LICENSE_CHECK_STATE } from '../../../licensing/server'; -export const mockLicenseState = () => { - const license: ILicense = { - uid: '123', - status: 'active', - isActive: true, - signature: 'sig', - isAvailable: true, - toJSON: () => ({ - signature: 'sig', +export const createLicenseStateMock = () => { + const licenseState: jest.Mocked = { + clean: jest.fn(), + getLicenseInformation: jest.fn(), + checkLicense: jest.fn().mockResolvedValue({ + state: LICENSE_CHECK_STATE.Valid, }), - getUnavailableReason: () => undefined, - hasAtLeast() { - return true; - }, - check() { - return { - state: LICENSE_CHECK_STATE.Valid, - }; - }, - getFeature() { - return { - isAvailable: true, - isEnabled: true, - }; - }, }; - return new LicenseState(of(license)); + return licenseState; +}; + +export const licenseStateMock = { + create: createLicenseStateMock, }; diff --git a/x-pack/plugins/actions/server/lib/license_state.ts b/x-pack/plugins/actions/server/lib/license_state.ts index 7b25e55ac0ba1..ba11803f018ce 100644 --- a/x-pack/plugins/actions/server/lib/license_state.ts +++ b/x-pack/plugins/actions/server/lib/license_state.ts @@ -10,6 +10,8 @@ import { assertNever } from '../../../../../src/core/utils'; import { ILicense, LICENSE_CHECK_STATE } from '../../../licensing/common/types'; import { PLUGIN } from '../constants/plugin'; +export type ILicenseState = PublicMethodsOf; + export interface ActionsLicenseInformation { showAppLink: boolean; enableAppLink: boolean; diff --git a/x-pack/plugins/actions/server/plugin.ts b/x-pack/plugins/actions/server/plugin.ts index 89d89baf721fc..057693be6d58f 100644 --- a/x-pack/plugins/actions/server/plugin.ts +++ b/x-pack/plugins/actions/server/plugin.ts @@ -48,7 +48,7 @@ import { listActionTypesRoute, executeActionRoute, } from './routes'; -import { LicenseState } from './lib/license_state'; +import { LicenseState, ILicenseState } from './lib/license_state'; import { IEventLogger, IEventLogService } from '../../event_log/server'; const EVENT_LOG_PROVIDER = 'actions'; @@ -88,7 +88,7 @@ export class ActionsPlugin implements Plugin, Plugi private taskRunnerFactory?: TaskRunnerFactory; private actionTypeRegistry?: ActionTypeRegistry; private actionExecutor?: ActionExecutor; - private licenseState: LicenseState | null = null; + private licenseState: ILicenseState | null = null; private spaces?: SpacesServiceSetup; private eventLogger?: IEventLogger; private isESOUsingEphemeralEncryptionKey?: boolean; diff --git a/x-pack/plugins/actions/server/routes/create.test.ts b/x-pack/plugins/actions/server/routes/create.test.ts index 6f7ebf2735edd..3eca815acda7f 100644 --- a/x-pack/plugins/actions/server/routes/create.test.ts +++ b/x-pack/plugins/actions/server/routes/create.test.ts @@ -5,7 +5,7 @@ */ import { createActionRoute } from './create'; import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock'; -import { mockLicenseState } from '../lib/license_state.mock'; +import { licenseStateMock } from '../lib/license_state.mock'; import { verifyApiAccess } from '../lib/license_api_access'; import { mockHandlerArguments } from './_mock_handler_arguments'; @@ -19,7 +19,7 @@ beforeEach(() => { describe('createActionRoute', () => { it('creates an action with proper parameters', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); createActionRoute(router, licenseState); @@ -82,7 +82,7 @@ describe('createActionRoute', () => { }); it('ensures the license allows creating actions', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); createActionRoute(router, licenseState); @@ -106,7 +106,7 @@ describe('createActionRoute', () => { }); it('ensures the license check prevents creating actions', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); (verifyApiAccess as jest.Mock).mockImplementation(() => { diff --git a/x-pack/plugins/actions/server/routes/create.ts b/x-pack/plugins/actions/server/routes/create.ts index f8f9aff9323a0..42e2ed2407100 100644 --- a/x-pack/plugins/actions/server/routes/create.ts +++ b/x-pack/plugins/actions/server/routes/create.ts @@ -13,7 +13,7 @@ import { KibanaResponseFactory, } from 'kibana/server'; import { ActionResult } from '../types'; -import { LicenseState } from '../lib/license_state'; +import { ILicenseState } from '../lib/license_state'; import { verifyApiAccess } from '../lib/license_api_access'; export const bodySchema = schema.object({ @@ -23,7 +23,7 @@ export const bodySchema = schema.object({ secrets: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }), }); -export const createActionRoute = (router: IRouter, licenseState: LicenseState) => { +export const createActionRoute = (router: IRouter, licenseState: ILicenseState) => { router.post( { path: `/api/action`, diff --git a/x-pack/plugins/actions/server/routes/delete.test.ts b/x-pack/plugins/actions/server/routes/delete.test.ts index e44f325413428..3931e3e7aa038 100644 --- a/x-pack/plugins/actions/server/routes/delete.test.ts +++ b/x-pack/plugins/actions/server/routes/delete.test.ts @@ -5,7 +5,7 @@ */ import { deleteActionRoute } from './delete'; import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock'; -import { mockLicenseState } from '../lib/license_state.mock'; +import { licenseStateMock } from '../lib/license_state.mock'; import { verifyApiAccess } from '../lib/license_api_access'; import { mockHandlerArguments } from './_mock_handler_arguments'; @@ -19,7 +19,7 @@ beforeEach(() => { describe('deleteActionRoute', () => { it('deletes an action with proper parameters', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); deleteActionRoute(router, licenseState); @@ -64,7 +64,7 @@ describe('deleteActionRoute', () => { }); it('ensures the license allows deleting actions', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); deleteActionRoute(router, licenseState); @@ -85,7 +85,7 @@ describe('deleteActionRoute', () => { }); it('ensures the license check prevents deleting actions', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); (verifyApiAccess as jest.Mock).mockImplementation(() => { diff --git a/x-pack/plugins/actions/server/routes/delete.ts b/x-pack/plugins/actions/server/routes/delete.ts index d96523997ad34..bd81194d1ab05 100644 --- a/x-pack/plugins/actions/server/routes/delete.ts +++ b/x-pack/plugins/actions/server/routes/delete.ts @@ -17,14 +17,14 @@ import { IKibanaResponse, KibanaResponseFactory, } from 'kibana/server'; -import { LicenseState } from '../lib/license_state'; +import { ILicenseState } from '../lib/license_state'; import { verifyApiAccess } from '../lib/license_api_access'; const paramSchema = schema.object({ id: schema.string(), }); -export const deleteActionRoute = (router: IRouter, licenseState: LicenseState) => { +export const deleteActionRoute = (router: IRouter, licenseState: ILicenseState) => { router.delete( { path: `/api/action/{id}`, diff --git a/x-pack/plugins/actions/server/routes/execute.test.ts b/x-pack/plugins/actions/server/routes/execute.test.ts index d8b57b2fb849a..111120abe1457 100644 --- a/x-pack/plugins/actions/server/routes/execute.test.ts +++ b/x-pack/plugins/actions/server/routes/execute.test.ts @@ -6,7 +6,7 @@ import { executeActionRoute } from './execute'; import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock'; -import { mockLicenseState } from '../lib/license_state.mock'; +import { licenseStateMock } from '../lib/license_state.mock'; import { verifyApiAccess } from '../lib/license_api_access'; import { mockHandlerArguments } from './_mock_handler_arguments'; import { ActionExecutorContract } from '../lib'; @@ -21,7 +21,7 @@ beforeEach(() => { describe('executeActionRoute', () => { it('executes an action with proper parameters', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); const [context, req, res] = mockHandlerArguments( @@ -77,7 +77,7 @@ describe('executeActionRoute', () => { }); it('returns a "204 NO CONTENT" when the executor returns a nullish value', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); const [context, req, res] = mockHandlerArguments( @@ -115,7 +115,7 @@ describe('executeActionRoute', () => { }); it('ensures the license allows action execution', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); const [context, req, res] = mockHandlerArguments( @@ -147,7 +147,7 @@ describe('executeActionRoute', () => { }); it('ensures the license check prevents action execution', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); (verifyApiAccess as jest.Mock).mockImplementation(() => { diff --git a/x-pack/plugins/actions/server/routes/execute.ts b/x-pack/plugins/actions/server/routes/execute.ts index afccee3b5e70e..252b27b7c270d 100644 --- a/x-pack/plugins/actions/server/routes/execute.ts +++ b/x-pack/plugins/actions/server/routes/execute.ts @@ -11,7 +11,7 @@ import { IKibanaResponse, KibanaResponseFactory, } from 'kibana/server'; -import { LicenseState } from '../lib/license_state'; +import { ILicenseState } from '../lib/license_state'; import { verifyApiAccess } from '../lib/license_api_access'; import { ActionExecutorContract } from '../lib'; @@ -27,7 +27,7 @@ const bodySchema = schema.object({ export const executeActionRoute = ( router: IRouter, - licenseState: LicenseState, + licenseState: ILicenseState, actionExecutor: ActionExecutorContract ) => { router.post( diff --git a/x-pack/plugins/actions/server/routes/find.test.ts b/x-pack/plugins/actions/server/routes/find.test.ts index 862e26132fdc3..cb24bf5fdecc4 100644 --- a/x-pack/plugins/actions/server/routes/find.test.ts +++ b/x-pack/plugins/actions/server/routes/find.test.ts @@ -6,7 +6,7 @@ import { findActionRoute } from './find'; import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock'; -import { mockLicenseState } from '../lib/license_state.mock'; +import { licenseStateMock } from '../lib/license_state.mock'; import { verifyApiAccess } from '../lib/license_api_access'; import { mockHandlerArguments } from './_mock_handler_arguments'; @@ -20,7 +20,7 @@ beforeEach(() => { describe('findActionRoute', () => { it('finds actions with proper parameters', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); findActionRoute(router, licenseState); @@ -92,7 +92,7 @@ describe('findActionRoute', () => { }); it('ensures the license allows finding actions', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); findActionRoute(router, licenseState); @@ -122,7 +122,7 @@ describe('findActionRoute', () => { }); it('ensures the license check prevents finding actions', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); (verifyApiAccess as jest.Mock).mockImplementation(() => { diff --git a/x-pack/plugins/actions/server/routes/find.ts b/x-pack/plugins/actions/server/routes/find.ts index e791aff4fb598..9244b2f7b6cd4 100644 --- a/x-pack/plugins/actions/server/routes/find.ts +++ b/x-pack/plugins/actions/server/routes/find.ts @@ -13,7 +13,7 @@ import { KibanaResponseFactory, } from 'kibana/server'; import { FindOptions } from '../../../alerting/server'; -import { LicenseState } from '../lib/license_state'; +import { ILicenseState } from '../lib/license_state'; import { verifyApiAccess } from '../lib/license_api_access'; // config definition @@ -40,7 +40,7 @@ const querySchema = schema.object({ filter: schema.maybe(schema.string()), }); -export const findActionRoute = (router: IRouter, licenseState: LicenseState) => { +export const findActionRoute = (router: IRouter, licenseState: ILicenseState) => { router.get( { path: `/api/action/_find`, diff --git a/x-pack/plugins/actions/server/routes/get.test.ts b/x-pack/plugins/actions/server/routes/get.test.ts index 8762a68b192f2..91da74858fad3 100644 --- a/x-pack/plugins/actions/server/routes/get.test.ts +++ b/x-pack/plugins/actions/server/routes/get.test.ts @@ -6,7 +6,7 @@ import { getActionRoute } from './get'; import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock'; -import { mockLicenseState } from '../lib/license_state.mock'; +import { licenseStateMock } from '../lib/license_state.mock'; import { verifyApiAccess } from '../lib/license_api_access'; import { mockHandlerArguments } from './_mock_handler_arguments'; @@ -20,7 +20,7 @@ beforeEach(() => { describe('getActionRoute', () => { it('gets an action with proper parameters', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); getActionRoute(router, licenseState); @@ -74,7 +74,7 @@ describe('getActionRoute', () => { }); it('ensures the license allows getting actions', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); getActionRoute(router, licenseState); @@ -104,7 +104,7 @@ describe('getActionRoute', () => { }); it('ensures the license check prevents getting actions', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); (verifyApiAccess as jest.Mock).mockImplementation(() => { diff --git a/x-pack/plugins/actions/server/routes/get.ts b/x-pack/plugins/actions/server/routes/get.ts index 26aa74da5d36b..1048635c44a49 100644 --- a/x-pack/plugins/actions/server/routes/get.ts +++ b/x-pack/plugins/actions/server/routes/get.ts @@ -12,14 +12,14 @@ import { IKibanaResponse, KibanaResponseFactory, } from 'kibana/server'; -import { LicenseState } from '../lib/license_state'; +import { ILicenseState } from '../lib/license_state'; import { verifyApiAccess } from '../lib/license_api_access'; const paramSchema = schema.object({ id: schema.string(), }); -export const getActionRoute = (router: IRouter, licenseState: LicenseState) => { +export const getActionRoute = (router: IRouter, licenseState: ILicenseState) => { router.get( { path: `/api/action/{id}`, diff --git a/x-pack/plugins/actions/server/routes/list_action_types.test.ts b/x-pack/plugins/actions/server/routes/list_action_types.test.ts index 87cc4dfee5336..7249d3c005a6c 100644 --- a/x-pack/plugins/actions/server/routes/list_action_types.test.ts +++ b/x-pack/plugins/actions/server/routes/list_action_types.test.ts @@ -6,7 +6,7 @@ import { listActionTypesRoute } from './list_action_types'; import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock'; -import { mockLicenseState } from '../lib/license_state.mock'; +import { licenseStateMock } from '../lib/license_state.mock'; import { verifyApiAccess } from '../lib/license_api_access'; import { mockHandlerArguments } from './_mock_handler_arguments'; @@ -20,7 +20,7 @@ beforeEach(() => { describe('listActionTypesRoute', () => { it('lists action types with proper parameters', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); listActionTypesRoute(router, licenseState); @@ -66,7 +66,7 @@ describe('listActionTypesRoute', () => { }); it('ensures the license allows listing action types', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); listActionTypesRoute(router, licenseState); @@ -104,7 +104,7 @@ describe('listActionTypesRoute', () => { }); it('ensures the license check prevents listing action types', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); (verifyApiAccess as jest.Mock).mockImplementation(() => { diff --git a/x-pack/plugins/actions/server/routes/list_action_types.ts b/x-pack/plugins/actions/server/routes/list_action_types.ts index 0b9791eedb39c..62c43da83f6d0 100644 --- a/x-pack/plugins/actions/server/routes/list_action_types.ts +++ b/x-pack/plugins/actions/server/routes/list_action_types.ts @@ -11,10 +11,10 @@ import { IKibanaResponse, KibanaResponseFactory, } from 'kibana/server'; -import { LicenseState } from '../lib/license_state'; +import { ILicenseState } from '../lib/license_state'; import { verifyApiAccess } from '../lib/license_api_access'; -export const listActionTypesRoute = (router: IRouter, licenseState: LicenseState) => { +export const listActionTypesRoute = (router: IRouter, licenseState: ILicenseState) => { router.get( { path: `/api/action/types`, diff --git a/x-pack/plugins/actions/server/routes/update.test.ts b/x-pack/plugins/actions/server/routes/update.test.ts index 1090193761395..b50e885a2fbc8 100644 --- a/x-pack/plugins/actions/server/routes/update.test.ts +++ b/x-pack/plugins/actions/server/routes/update.test.ts @@ -5,7 +5,7 @@ */ import { updateActionRoute } from './update'; import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock'; -import { mockLicenseState } from '../lib/license_state.mock'; +import { licenseStateMock } from '../lib/license_state.mock'; import { verifyApiAccess } from '../lib/license_api_access'; import { mockHandlerArguments } from './_mock_handler_arguments'; @@ -19,7 +19,7 @@ beforeEach(() => { describe('updateActionRoute', () => { it('updates an action with proper parameters', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); updateActionRoute(router, licenseState); @@ -85,7 +85,7 @@ describe('updateActionRoute', () => { }); it('ensures the license allows deleting actions', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); updateActionRoute(router, licenseState); @@ -124,7 +124,7 @@ describe('updateActionRoute', () => { }); it('ensures the license check prevents deleting actions', async () => { - const licenseState = mockLicenseState(); + const licenseState = licenseStateMock.create(); const router: RouterMock = mockRouter.create(); (verifyApiAccess as jest.Mock).mockImplementation(() => { diff --git a/x-pack/plugins/actions/server/routes/update.ts b/x-pack/plugins/actions/server/routes/update.ts index 9c5f32e8b9119..27395289b4804 100644 --- a/x-pack/plugins/actions/server/routes/update.ts +++ b/x-pack/plugins/actions/server/routes/update.ts @@ -12,7 +12,7 @@ import { IKibanaResponse, KibanaResponseFactory, } from 'kibana/server'; -import { LicenseState } from '../lib/license_state'; +import { ILicenseState } from '../lib/license_state'; import { verifyApiAccess } from '../lib/license_api_access'; const paramSchema = schema.object({ @@ -25,7 +25,7 @@ const bodySchema = schema.object({ secrets: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }), }); -export const updateActionRoute = (router: IRouter, licenseState: LicenseState) => { +export const updateActionRoute = (router: IRouter, licenseState: ILicenseState) => { router.put( { path: `/api/action/{id}`,