[eslint] no_restricted_paths config cleanup (#63741)

Major cleanup of the no_restricted_paths rule for imports of core.

For relative imports, we use eslint-module-utils/resolve which resolves
to the full filesystem path. So, to support relative and absolute
imports from the src alias we need to define both the directory and the
index including file extension.

This rule was handling both core imports, as well as imports from other
plugins. Imports from other plugins are being used much more liberally
allowed through the exceptions in tests. I choose to break these up,
removing this exception for tests for core imports.

Fixes:
Absolute imports of src/core/server/mocks were not allowed in src. This
was not an issue in x-pack due to the target excluding
!x-pack/**/*.test.* and !x-pack/test/**/*.

Non-top-level public and server imports were allowed from X-Pack tests
to the previously mentioned exclusion.

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
This commit is contained in:
Tyler Smalley 2020-04-23 15:59:01 -07:00 committed by GitHub
parent 9e11bcb592
commit feed406c77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 171 additions and 137 deletions

View file

@ -185,31 +185,40 @@ module.exports = {
zones: [
{
target: [
'src/legacy/**/*',
'x-pack/**/*',
'!x-pack/**/*.test.*',
'!x-pack/test/**/*',
'(src|x-pack)/legacy/**/*',
'(src|x-pack)/plugins/**/(public|server)/**/*',
'src/core/(public|server)/**/*',
'examples/**/*',
],
from: [
'src/core/public/**/*',
'!src/core/public/index.ts',
'!src/core/public/mocks.ts',
'!src/core/public/*.test.mocks.ts',
'!src/core/public/index.ts', // relative import
'!src/core/public/mocks{,.ts}',
'!src/core/server/types{,.ts}',
'!src/core/public/utils/**/*',
'!src/core/public/*.test.mocks{,.ts}',
'src/core/server/**/*',
'!src/core/server/index.ts',
'!src/core/server/mocks.ts',
'!src/core/server/types.ts',
'!src/core/server/test_utils.ts',
'!src/core/server/index.ts', // relative import
'!src/core/server/mocks{,.ts}',
'!src/core/server/types{,.ts}',
'!src/core/server/test_utils',
// for absolute imports until fixed in
// https://github.com/elastic/kibana/issues/36096
'!src/core/server/types',
'!src/core/server/*.test.mocks.ts',
'!src/core/server/*.test.mocks{,.ts}',
],
allowSameFolder: true,
errorMessage:
'Plugins may only import from top-level public and server modules in core.',
},
{
target: [
'(src|x-pack)/legacy/**/*',
'(src|x-pack)/plugins/**/(public|server)/**/*',
'examples/**/*',
'!(src|x-pack)/**/*.test.*',
'!(x-pack/)?test/**/*',
],
from: [
'(src|x-pack)/plugins/**/(public|server)/**/*',
'!(src|x-pack)/plugins/**/(public|server)/(index|mocks).{js,ts,tsx}',
],

View file

@ -18,4 +18,5 @@
*/
export { HttpService } from './http_service';
export { HttpFetchError } from './http_fetch_error';
export * from './types';

View file

@ -143,6 +143,7 @@ export {
export {
HttpHeadersInit,
HttpRequestInit,
HttpFetchError,
HttpFetchOptions,
HttpFetchOptionsWithPath,
HttpFetchQuery,

View file

@ -593,6 +593,23 @@ export type HandlerFunction<T extends object> = (context: T, ...args: any[]) =>
// @public
export type HandlerParameters<T extends HandlerFunction<any>> = T extends (context: any, ...args: infer U) => any ? U : never;
// @internal (undocumented)
export class HttpFetchError extends Error implements IHttpFetchError {
constructor(message: string, name: string, request: Request, response?: Response | undefined, body?: any);
// (undocumented)
readonly body?: any;
// (undocumented)
readonly name: string;
// (undocumented)
readonly req: Request;
// (undocumented)
readonly request: Request;
// (undocumented)
readonly res?: Response;
// (undocumented)
readonly response?: Response | undefined;
}
// @public
export interface HttpFetchOptions extends HttpRequestInit {
asResponse?: boolean;

View file

@ -45,6 +45,7 @@ export { elasticsearchServiceMock } from './elasticsearch/elasticsearch_service.
export { httpServiceMock } from './http/http_service.mock';
export { loggingServiceMock } from './logging/logging_service.mock';
export { savedObjectsRepositoryMock } from './saved_objects/service/lib/repository.mock';
export { savedObjectsServiceMock } from './saved_objects/saved_objects_service.mock';
export { typeRegistryMock as savedObjectsTypeRegistryMock } from './saved_objects/saved_objects_type_registry.mock';
export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
export { metricsServiceMock } from './metrics/metrics_service.mock';

View file

@ -7,8 +7,7 @@
import React from 'react';
import { EmptyStateComponent } from '../empty_state';
import { StatesIndexStatus } from '../../../../../common/runtime_types';
import { IHttpFetchError } from '../../../../../../../../../target/types/core/public/http';
import { HttpFetchError } from '../../../../../../../../../src/core/public/http/http_fetch_error';
import { HttpFetchError, IHttpFetchError } from 'src/core/public';
import { mountWithRouter, shallowWithRouter } from '../../../../lib';
describe('EmptyState component', () => {

View file

@ -6,7 +6,7 @@
import { fetchSnapshotCount } from '../snapshot';
import { apiService } from '../utils';
import { HttpFetchError } from '../../../../../../../../src/core/public/http/http_fetch_error';
import { HttpFetchError } from 'src/core/public';
describe('snapshot API', () => {
let fetchMock: jest.SpyInstance<Partial<unknown>>;

View file

@ -7,7 +7,7 @@
import { call, put } from 'redux-saga/effects';
import { fetchEffectFactory } from '../fetch_effect';
import { indexStatusAction } from '../../actions';
import { HttpFetchError } from '../../../../../../../../src/core/public/http/http_fetch_error';
import { HttpFetchError } from 'src/core/public';
import { StatesIndexStatus } from '../../../../common/runtime_types';
import { fetchIndexStatus } from '../../api';

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { createActionRoute } from './create';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { licenseStateMock } from '../lib/license_state.mock';
import { verifyApiAccess, ActionTypeDisabledError } from '../lib';
import { mockHandlerArguments } from './_mock_handler_arguments';
@ -20,7 +20,7 @@ beforeEach(() => {
describe('createActionRoute', () => {
it('creates an action with proper parameters', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
createActionRoute(router, licenseState);
@ -83,7 +83,7 @@ describe('createActionRoute', () => {
it('ensures the license allows creating actions', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
createActionRoute(router, licenseState);
@ -107,7 +107,7 @@ describe('createActionRoute', () => {
it('ensures the license check prevents creating actions', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
(verifyApiAccess as jest.Mock).mockImplementation(() => {
throw new Error('OMG');
@ -135,7 +135,7 @@ describe('createActionRoute', () => {
it('ensures the action type gets validated for the license', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
createActionRoute(router, licenseState);

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { deleteActionRoute } from './delete';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { licenseStateMock } from '../lib/license_state.mock';
import { verifyApiAccess } from '../lib';
import { mockHandlerArguments } from './_mock_handler_arguments';
@ -20,7 +20,7 @@ beforeEach(() => {
describe('deleteActionRoute', () => {
it('deletes an action with proper parameters', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
deleteActionRoute(router, licenseState);
@ -65,7 +65,7 @@ describe('deleteActionRoute', () => {
it('ensures the license allows deleting actions', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
deleteActionRoute(router, licenseState);
@ -86,7 +86,7 @@ describe('deleteActionRoute', () => {
it('ensures the license check prevents deleting actions', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
(verifyApiAccess as jest.Mock).mockImplementation(() => {
throw new Error('OMG');

View file

@ -5,7 +5,7 @@
*/
import { executeActionRoute } from './execute';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { licenseStateMock } from '../lib/license_state.mock';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { ActionExecutorContract, verifyApiAccess, ActionTypeDisabledError } from '../lib';
@ -21,7 +21,7 @@ beforeEach(() => {
describe('executeActionRoute', () => {
it('executes an action with proper parameters', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
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 = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
const [context, req, res] = mockHandlerArguments(
{},
@ -115,7 +115,7 @@ describe('executeActionRoute', () => {
it('ensures the license allows action execution', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
const [context, req, res] = mockHandlerArguments(
{},
@ -147,7 +147,7 @@ describe('executeActionRoute', () => {
it('ensures the license check prevents action execution', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
(verifyApiAccess as jest.Mock).mockImplementation(() => {
throw new Error('OMG');
@ -183,7 +183,7 @@ describe('executeActionRoute', () => {
it('ensures the action type gets validated for the license', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
const [context, req, res] = mockHandlerArguments(
{},

View file

@ -5,7 +5,7 @@
*/
import { getActionRoute } from './get';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { licenseStateMock } from '../lib/license_state.mock';
import { verifyApiAccess } from '../lib';
import { mockHandlerArguments } from './_mock_handler_arguments';
@ -21,7 +21,7 @@ beforeEach(() => {
describe('getActionRoute', () => {
it('gets an action with proper parameters', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
getActionRoute(router, licenseState);
@ -75,7 +75,7 @@ describe('getActionRoute', () => {
it('ensures the license allows getting actions', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
getActionRoute(router, licenseState);
@ -105,7 +105,7 @@ describe('getActionRoute', () => {
it('ensures the license check prevents getting actions', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
(verifyApiAccess as jest.Mock).mockImplementation(() => {
throw new Error('OMG');

View file

@ -5,7 +5,7 @@
*/
import { getAllActionRoute } from './get_all';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { licenseStateMock } from '../lib/license_state.mock';
import { verifyApiAccess } from '../lib';
import { mockHandlerArguments } from './_mock_handler_arguments';
@ -21,7 +21,7 @@ beforeEach(() => {
describe('getAllActionRoute', () => {
it('get all actions with proper parameters', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
getAllActionRoute(router, licenseState);
@ -57,7 +57,7 @@ describe('getAllActionRoute', () => {
it('ensures the license allows getting all actions', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
getAllActionRoute(router, licenseState);
@ -85,7 +85,7 @@ describe('getAllActionRoute', () => {
it('ensures the license check prevents getting all actions', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
(verifyApiAccess as jest.Mock).mockImplementation(() => {
throw new Error('OMG');

View file

@ -5,7 +5,7 @@
*/
import { listActionTypesRoute } from './list_action_types';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { licenseStateMock } from '../lib/license_state.mock';
import { verifyApiAccess } from '../lib';
import { mockHandlerArguments } from './_mock_handler_arguments';
@ -21,7 +21,7 @@ beforeEach(() => {
describe('listActionTypesRoute', () => {
it('lists action types with proper parameters', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
listActionTypesRoute(router, licenseState);
@ -67,7 +67,7 @@ describe('listActionTypesRoute', () => {
it('ensures the license allows listing action types', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
listActionTypesRoute(router, licenseState);
@ -105,7 +105,7 @@ describe('listActionTypesRoute', () => {
it('ensures the license check prevents listing action types', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
(verifyApiAccess as jest.Mock).mockImplementation(() => {
throw new Error('OMG');

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { updateActionRoute } from './update';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { licenseStateMock } from '../lib/license_state.mock';
import { verifyApiAccess, ActionTypeDisabledError } from '../lib';
import { mockHandlerArguments } from './_mock_handler_arguments';
@ -20,7 +20,7 @@ beforeEach(() => {
describe('updateActionRoute', () => {
it('updates an action with proper parameters', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
updateActionRoute(router, licenseState);
@ -86,7 +86,7 @@ describe('updateActionRoute', () => {
it('ensures the license allows deleting actions', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
updateActionRoute(router, licenseState);
@ -125,7 +125,7 @@ describe('updateActionRoute', () => {
it('ensures the license check prevents deleting actions', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
(verifyApiAccess as jest.Mock).mockImplementation(() => {
throw new Error('OMG');
@ -168,7 +168,7 @@ describe('updateActionRoute', () => {
it('ensures the action type gets validated for the license', async () => {
const licenseState = licenseStateMock.create();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
updateActionRoute(router, licenseState);

View file

@ -5,7 +5,7 @@
*/
import { createAlertRoute } from './create';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockLicenseState } from '../lib/license_state.mock';
import { verifyApiAccess } from '../lib/license_api_access';
import { mockHandlerArguments } from './_mock_handler_arguments';
@ -68,7 +68,7 @@ describe('createAlertRoute', () => {
it('creates an alert with proper parameters', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
createAlertRoute(router, licenseState);
@ -134,7 +134,7 @@ describe('createAlertRoute', () => {
it('ensures the license allows creating alerts', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
createAlertRoute(router, licenseState);
@ -151,7 +151,7 @@ describe('createAlertRoute', () => {
it('ensures the license check prevents creating alerts', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
(verifyApiAccess as jest.Mock).mockImplementation(() => {
throw new Error('OMG');

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { deleteAlertRoute } from './delete';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockLicenseState } from '../lib/license_state.mock';
import { verifyApiAccess } from '../lib/license_api_access';
import { mockHandlerArguments } from './_mock_handler_arguments';
@ -23,7 +23,7 @@ beforeEach(() => {
describe('deleteAlertRoute', () => {
it('deletes an alert with proper parameters', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
deleteAlertRoute(router, licenseState);
@ -66,7 +66,7 @@ describe('deleteAlertRoute', () => {
it('ensures the license allows deleting alerts', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
deleteAlertRoute(router, licenseState);
@ -85,7 +85,7 @@ describe('deleteAlertRoute', () => {
it('ensures the license check prevents deleting alerts', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
(verifyApiAccess as jest.Mock).mockImplementation(() => {
throw new Error('OMG');

View file

@ -5,7 +5,7 @@
*/
import { disableAlertRoute } from './disable';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockLicenseState } from '../lib/license_state.mock';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { alertsClientMock } from '../alerts_client.mock';
@ -23,7 +23,7 @@ beforeEach(() => {
describe('disableAlertRoute', () => {
it('disables an alert', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
disableAlertRoute(router, licenseState);

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { enableAlertRoute } from './enable';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockLicenseState } from '../lib/license_state.mock';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { alertsClientMock } from '../alerts_client.mock';
@ -22,7 +22,7 @@ beforeEach(() => {
describe('enableAlertRoute', () => {
it('enables an alert', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
enableAlertRoute(router, licenseState);

View file

@ -5,7 +5,7 @@
*/
import { findAlertRoute } from './find';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockLicenseState } from '../lib/license_state.mock';
import { verifyApiAccess } from '../lib/license_api_access';
import { mockHandlerArguments } from './_mock_handler_arguments';
@ -24,7 +24,7 @@ beforeEach(() => {
describe('findAlertRoute', () => {
it('finds alerts with proper parameters', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
findAlertRoute(router, licenseState);
@ -95,7 +95,7 @@ describe('findAlertRoute', () => {
it('ensures the license allows finding alerts', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
findAlertRoute(router, licenseState);
@ -123,7 +123,7 @@ describe('findAlertRoute', () => {
it('ensures the license check prevents finding alerts', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
(verifyApiAccess as jest.Mock).mockImplementation(() => {
throw new Error('OMG');

View file

@ -5,7 +5,7 @@
*/
import { getAlertRoute } from './get';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockLicenseState } from '../lib/license_state.mock';
import { verifyApiAccess } from '../lib/license_api_access';
import { mockHandlerArguments } from './_mock_handler_arguments';
@ -55,7 +55,7 @@ describe('getAlertRoute', () => {
it('gets an alert with proper parameters', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
getAlertRoute(router, licenseState);
const [config, handler] = router.get.mock.calls[0];
@ -90,7 +90,7 @@ describe('getAlertRoute', () => {
it('ensures the license allows getting alerts', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
getAlertRoute(router, licenseState);
@ -113,7 +113,7 @@ describe('getAlertRoute', () => {
it('ensures the license check prevents getting alerts', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
(verifyApiAccess as jest.Mock).mockImplementation(() => {
throw new Error('OMG');

View file

@ -5,10 +5,10 @@
*/
import { getAlertStateRoute } from './get_alert_state';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockLicenseState } from '../lib/license_state.mock';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { SavedObjectsErrorHelpers } from 'src/core/server/saved_objects';
import { SavedObjectsErrorHelpers } from 'src/core/server';
import { alertsClientMock } from '../alerts_client.mock';
const alertsClient = alertsClientMock.create();
@ -41,7 +41,7 @@ describe('getAlertStateRoute', () => {
it('gets alert state', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
getAlertStateRoute(router, licenseState);
@ -84,7 +84,7 @@ describe('getAlertStateRoute', () => {
it('returns NO-CONTENT when alert exists but has no task state yet', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
getAlertStateRoute(router, licenseState);
@ -127,7 +127,7 @@ describe('getAlertStateRoute', () => {
it('returns NOT-FOUND when alert is not found', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
getAlertStateRoute(router, licenseState);

View file

@ -5,7 +5,7 @@
*/
import { healthRoute } from './health';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { elasticsearchServiceMock } from '../../../../../src/core/server/mocks';
import { verifyApiAccess } from '../lib/license_api_access';
@ -22,7 +22,7 @@ beforeEach(() => {
describe('healthRoute', () => {
it('registers the route', async () => {
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
const licenseState = mockLicenseState();
const encryptedSavedObjects = encryptedSavedObjectsMock.createSetup();
@ -35,7 +35,7 @@ describe('healthRoute', () => {
});
it('queries the usage api', async () => {
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
const licenseState = mockLicenseState();
const encryptedSavedObjects = encryptedSavedObjectsMock.createSetup();
@ -64,7 +64,7 @@ describe('healthRoute', () => {
});
it('evaluates whether Encrypted Saved Objects is using an ephemeral encryption key', async () => {
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
const licenseState = mockLicenseState();
const encryptedSavedObjects = encryptedSavedObjectsMock.createSetup();
@ -88,7 +88,7 @@ describe('healthRoute', () => {
});
it('evaluates missing security info from the usage api to mean that the security plugin is disbled', async () => {
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
const licenseState = mockLicenseState();
const encryptedSavedObjects = encryptedSavedObjectsMock.createSetup();
@ -112,7 +112,7 @@ describe('healthRoute', () => {
});
it('evaluates missing security http info from the usage api to mean that the security plugin is disbled', async () => {
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
const licenseState = mockLicenseState();
const encryptedSavedObjects = encryptedSavedObjectsMock.createSetup();
@ -136,7 +136,7 @@ describe('healthRoute', () => {
});
it('evaluates security enabled, and missing ssl info from the usage api to mean that the user cannot generate keys', async () => {
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
const licenseState = mockLicenseState();
const encryptedSavedObjects = encryptedSavedObjectsMock.createSetup();
@ -162,7 +162,7 @@ describe('healthRoute', () => {
});
it('evaluates security enabled, SSL info present but missing http info from the usage api to mean that the user cannot generate keys', async () => {
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
const licenseState = mockLicenseState();
const encryptedSavedObjects = encryptedSavedObjectsMock.createSetup();
@ -188,7 +188,7 @@ describe('healthRoute', () => {
});
it('evaluates security and tls enabled to mean that the user can generate keys', async () => {
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
const licenseState = mockLicenseState();
const encryptedSavedObjects = encryptedSavedObjectsMock.createSetup();

View file

@ -5,7 +5,7 @@
*/
import { listAlertTypesRoute } from './list_alert_types';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockLicenseState } from '../lib/license_state.mock';
import { verifyApiAccess } from '../lib/license_api_access';
import { mockHandlerArguments } from './_mock_handler_arguments';
@ -21,7 +21,7 @@ beforeEach(() => {
describe('listAlertTypesRoute', () => {
it('lists alert types with proper parameters', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
listAlertTypesRoute(router, licenseState);
@ -79,7 +79,7 @@ describe('listAlertTypesRoute', () => {
it('ensures the license allows listing alert types', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
listAlertTypesRoute(router, licenseState);
@ -117,7 +117,7 @@ describe('listAlertTypesRoute', () => {
it('ensures the license check prevents listing alert types', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
(verifyApiAccess as jest.Mock).mockImplementation(() => {
throw new Error('OMG');

View file

@ -5,7 +5,7 @@
*/
import { muteAllAlertRoute } from './mute_all';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockLicenseState } from '../lib/license_state.mock';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { alertsClientMock } from '../alerts_client.mock';
@ -22,7 +22,7 @@ beforeEach(() => {
describe('muteAllAlertRoute', () => {
it('mute an alert', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
muteAllAlertRoute(router, licenseState);

View file

@ -5,7 +5,7 @@
*/
import { muteAlertInstanceRoute } from './mute_instance';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockLicenseState } from '../lib/license_state.mock';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { alertsClientMock } from '../alerts_client.mock';
@ -22,7 +22,7 @@ beforeEach(() => {
describe('muteAlertInstanceRoute', () => {
it('mutes an alert instance', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
muteAlertInstanceRoute(router, licenseState);

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { unmuteAllAlertRoute } from './unmute_all';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockLicenseState } from '../lib/license_state.mock';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { alertsClientMock } from '../alerts_client.mock';
@ -21,7 +21,7 @@ beforeEach(() => {
describe('unmuteAllAlertRoute', () => {
it('unmutes an alert', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
unmuteAllAlertRoute(router, licenseState);

View file

@ -5,7 +5,7 @@
*/
import { unmuteAlertInstanceRoute } from './unmute_instance';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockLicenseState } from '../lib/license_state.mock';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { alertsClientMock } from '../alerts_client.mock';
@ -22,7 +22,7 @@ beforeEach(() => {
describe('unmuteAlertInstanceRoute', () => {
it('unmutes an alert instance', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
unmuteAlertInstanceRoute(router, licenseState);

View file

@ -5,7 +5,7 @@
*/
import { updateAlertRoute } from './update';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockLicenseState } from '../lib/license_state.mock';
import { verifyApiAccess } from '../lib/license_api_access';
import { mockHandlerArguments } from './_mock_handler_arguments';
@ -45,7 +45,7 @@ describe('updateAlertRoute', () => {
it('updates an alert with proper parameters', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
updateAlertRoute(router, licenseState);
@ -128,7 +128,7 @@ describe('updateAlertRoute', () => {
it('ensures the license allows updating alerts', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
updateAlertRoute(router, licenseState);
@ -171,7 +171,7 @@ describe('updateAlertRoute', () => {
it('ensures the license check prevents updating alerts', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
(verifyApiAccess as jest.Mock).mockImplementation(() => {
throw new Error('OMG');

View file

@ -5,7 +5,7 @@
*/
import { updateApiKeyRoute } from './update_api_key';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockLicenseState } from '../lib/license_state.mock';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { alertsClientMock } from '../alerts_client.mock';
@ -22,7 +22,7 @@ beforeEach(() => {
describe('updateApiKeyRoute', () => {
it('updates api key for an alert', async () => {
const licenseState = mockLicenseState();
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
updateApiKeyRoute(router, licenseState);

View file

@ -7,7 +7,7 @@
import { IEventLogConfig } from './types';
import { EventLogService } from './event_log_service';
import { contextMock } from './es/context.mock';
import { loggingServiceMock } from '../../../../src/core/server/logging/logging_service.mock';
import { loggingServiceMock } from 'src/core/server/mocks';
const loggingService = loggingServiceMock.create();
const systemLogger = loggingService.get();

View file

@ -7,8 +7,7 @@
import { EventLogClientService } from './event_log_start_service';
import { contextMock } from './es/context.mock';
import { KibanaRequest } from 'kibana/server';
import { savedObjectsServiceMock } from 'src/core/server/saved_objects/saved_objects_service.mock';
import { savedObjectsClientMock } from 'src/core/server/mocks';
import { savedObjectsClientMock, savedObjectsServiceMock } from 'src/core/server/mocks';
jest.mock('./event_log_client');

View file

@ -9,20 +9,20 @@ import { ECS_VERSION } from './types';
import { EventLogService } from './event_log_service';
import { EsContext } from './es/context';
import { contextMock } from './es/context.mock';
import { loggerMock, MockedLogger } from '../../../../src/core/server/logging/logger.mock';
import { loggingServiceMock } from 'src/core/server/mocks';
import { delay } from './lib/delay';
import { EVENT_LOGGED_PREFIX } from './event_logger';
const KIBANA_SERVER_UUID = '424-24-2424';
describe('EventLogger', () => {
let systemLogger: MockedLogger;
let systemLogger: ReturnType<typeof loggingServiceMock.createLogger>;
let esContext: EsContext;
let service: IEventLogService;
let eventLogger: IEventLogger;
beforeEach(() => {
systemLogger = loggerMock.create();
systemLogger = loggingServiceMock.createLogger();
esContext = contextMock.create();
service = new EventLogService({
esContext,
@ -153,7 +153,10 @@ describe('EventLogger', () => {
});
// return the next logged event; throw if not an event
async function waitForLogEvent(mockLogger: MockedLogger, waitSeconds: number = 1): Promise<IEvent> {
async function waitForLogEvent(
mockLogger: ReturnType<typeof loggingServiceMock.createLogger>,
waitSeconds: number = 1
): Promise<IEvent> {
const result = await waitForLog(mockLogger, waitSeconds);
if (typeof result === 'string') throw new Error('expecting an event');
return result;
@ -161,7 +164,7 @@ async function waitForLogEvent(mockLogger: MockedLogger, waitSeconds: number = 1
// return the next logged message; throw if it is an event
async function waitForLogMessage(
mockLogger: MockedLogger,
mockLogger: ReturnType<typeof loggingServiceMock.createLogger>,
waitSeconds: number = 1
): Promise<string> {
const result = await waitForLog(mockLogger, waitSeconds);
@ -171,7 +174,7 @@ async function waitForLogMessage(
// return the next logged message, if it's an event log entry, parse it
async function waitForLog(
mockLogger: MockedLogger,
mockLogger: ReturnType<typeof loggingServiceMock.createLogger>,
waitSeconds: number = 1
): Promise<string | IEvent> {
const intervals = 4;

View file

@ -5,7 +5,7 @@
*/
import { createBoundedQueue } from './bounded_queue';
import { loggingServiceMock } from '../../../../../src/core/server/logging/logging_service.mock';
import { loggingServiceMock } from 'src/core/server/mocks';
const loggingService = loggingServiceMock.create();
const logger = loggingService.get();

View file

@ -5,7 +5,7 @@
*/
import { findRoute } from './find';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { httpServiceMock } from 'src/core/server/mocks';
import { mockHandlerArguments, fakeEvent } from './_mock_handler_arguments';
import { eventLogClientMock } from '../event_log_client.mock';
@ -17,7 +17,7 @@ beforeEach(() => {
describe('find', () => {
it('finds events with proper parameters', async () => {
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
findRoute(router);
@ -56,7 +56,7 @@ describe('find', () => {
});
it('supports optional pagination parameters', async () => {
const router: RouterMock = mockRouter.create();
const router = httpServiceMock.createRouter();
findRoute(router);

View file

@ -10,8 +10,7 @@ import {
RequestHandlerContext,
SavedObjectsClientContract,
} from 'kibana/server';
import { savedObjectsClientMock } from '../../../../../../src/core/server/saved_objects/service/saved_objects_client.mock';
import { httpServerMock } from '../../../../../../src/core/server/http/http_server.mocks';
import { savedObjectsClientMock, httpServerMock } from 'src/core/server/mocks';
import { ActionsService } from '../../services/agents';
import { AgentAction } from '../../../common/types/models';
import { postNewAgentActionHandlerBuilder } from './actions_handlers';

View file

@ -5,7 +5,7 @@
*/
import Boom from 'boom';
import { SavedObjectsBulkResponse } from 'kibana/server';
import { savedObjectsClientMock } from '../../../../../../src/core/server/saved_objects/service/saved_objects_client.mock';
import { savedObjectsClientMock } from 'src/core/server/mocks';
import { encryptedSavedObjectsMock } from '../../../../../plugins/encrypted_saved_objects/server/mocks';
import {

View file

@ -7,7 +7,7 @@
import { createAgentAction } from './actions';
import { SavedObject } from 'kibana/server';
import { AgentAction } from '../../../common/types/models';
import { savedObjectsClientMock } from '../../../../../../src/core/server/saved_objects/service/saved_objects_client.mock';
import { savedObjectsClientMock } from 'src/core/server/mocks';
describe('test agent actions services', () => {
it('should create a new action', async () => {

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { savedObjectsClientMock } from '../../../../../../src/core/server/saved_objects/service/saved_objects_client.mock';
import { savedObjectsClientMock } from 'src/core/server/mocks';
import { getAgentStatusById } from './status';
import { AGENT_TYPE_PERMANENT } from '../../../common/constants';
import { AgentSOAttributes } from '../../../common/types/models';

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { httpServerMock } from '../../../../../src/core/server/http/http_server.mocks';
import { httpServerMock } from 'src/core/server/mocks';
import { canRedirectRequest } from './can_redirect_request';

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { loggerMock } from 'src/core/server/logging/logger.mock';
import { loggingServiceMock } from 'src/core/server/mocks';
import { getResult } from '../routes/__mocks__/request_responses';
import { rulesNotificationAlertType } from './rules_notification_alert_type';
import { buildSignalsSearchQuery } from './build_signals_query';
@ -15,12 +15,12 @@ jest.mock('./build_signals_query');
describe('rules_notification_alert_type', () => {
let payload: NotificationExecutorOptions;
let alert: ReturnType<typeof rulesNotificationAlertType>;
let logger: ReturnType<typeof loggerMock.create>;
let logger: ReturnType<typeof loggingServiceMock.createLogger>;
let alertServices: AlertServicesMock;
beforeEach(() => {
alertServices = alertsMock.createAlertServices();
logger = loggerMock.create();
logger = loggingServiceMock.createLogger();
payload = {
alertId: '1111',

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { loggerMock } from 'src/core/server/logging/logger.mock';
import { loggingServiceMock } from 'src/core/server/mocks';
import { getNotificationResult, getResult } from '../routes/__mocks__/request_responses';
import { isAlertTypes, isNotificationAlertExecutor } from './types';
import { rulesNotificationAlertType } from './rules_notification_alert_type';
@ -20,7 +20,9 @@ describe('types', () => {
it('isNotificationAlertExecutor should return true it passed object is NotificationAlertTypeDefinition type', () => {
expect(
isNotificationAlertExecutor(rulesNotificationAlertType({ logger: loggerMock.create() }))
isNotificationAlertExecutor(
rulesNotificationAlertType({ logger: loggingServiceMock.createLogger() })
)
).toEqual(true);
});
});

View file

@ -5,7 +5,7 @@
*/
import moment from 'moment';
import { loggerMock } from 'src/core/server/logging/logger.mock';
import { loggingServiceMock } from 'src/core/server/mocks';
import { getResult, getMlResult } from '../routes/__mocks__/request_responses';
import { signalRulesAlertType } from './signal_rule_alert_type';
import { alertsMock, AlertServicesMock } from '../../../../../alerting/server/mocks';
@ -70,13 +70,13 @@ describe('rules_notification_alert_type', () => {
};
let payload: jest.Mocked<RuleExecutorOptions>;
let alert: ReturnType<typeof signalRulesAlertType>;
let logger: ReturnType<typeof loggerMock.create>;
let logger: ReturnType<typeof loggingServiceMock.createLogger>;
let alertServices: AlertServicesMock;
let ruleStatusService: Record<string, jest.Mock>;
beforeEach(() => {
alertServices = alertsMock.createAlertServices();
logger = loggerMock.create();
logger = loggingServiceMock.createLogger();
ruleStatusService = {
success: jest.fn(),
find: jest.fn(),

View file

@ -6,7 +6,7 @@
import { buildRouteValidation } from './route_validation';
import * as rt from 'io-ts';
import { RouteValidationResultFactory } from '../../../../../../src/core/server/http';
import { RouteValidationResultFactory } from 'src/core/server';
describe('buildRouteValidation', () => {
const schema = rt.exact(

View file

@ -17,9 +17,12 @@ import {
TaskLifecycleResult,
} from './task';
import { StoreOpts, OwnershipClaimingOpts, TaskStore, SearchOpts } from './task_store';
import { savedObjectsRepositoryMock } from '../../../../src/core/server/mocks';
import { SavedObjectsSerializer, SavedObjectTypeRegistry } from '../../../../src/core/server';
import { SavedObjectsErrorHelpers } from '../../../../src/core/server/saved_objects/service/lib/errors';
import { savedObjectsRepositoryMock } from 'src/core/server/mocks';
import {
SavedObjectsSerializer,
SavedObjectTypeRegistry,
SavedObjectsErrorHelpers,
} from 'src/core/server';
import { asTaskClaimEvent, TaskEvent } from './task_events';
import { asOk, asErr } from './lib/result_type';

View file

@ -6,7 +6,7 @@
import { ReindexStatus, ReindexStep } from '../../../../../../../common/types';
import { ReindexPollingService } from './polling_service';
import { httpServiceMock } from 'src/core/public/http/http_service.mock';
import { httpServiceMock } from 'src/core/public/mocks';
const mockClient = httpServiceMock.createSetupContract();

View file

@ -5,7 +5,7 @@
*/
import { kibanaResponseFactory } from 'src/core/server';
import { savedObjectsServiceMock } from 'src/core/server/saved_objects/saved_objects_service.mock';
import { savedObjectsServiceMock } from 'src/core/server/mocks';
import { createMockRouter, MockRouter, routeHandlerContextMock } from './__mocks__/routes.mock';
import { createRequestMock } from './__mocks__/request.mock';

View file

@ -6,7 +6,7 @@
import { elasticsearchServiceMock } from '../../../../../../../src/core/server/mocks';
import { getMonitorStatus } from '../get_monitor_status';
import { ScopedClusterClient } from 'src/core/server/elasticsearch';
import { ScopedClusterClient } from 'src/core/server';
import { defaultDynamicSettings } from '../../../../../../legacy/plugins/uptime/common/runtime_types';
interface BucketItemCriteria {