mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Search] remove appSearch & workplaceSearch endpoints (#206107)
## Summary Removing the registration of App Search & Workplace Search routes from `enterprise_search`
This commit is contained in:
parent
44c2504240
commit
b6176b232b
67 changed files with 0 additions and 9485 deletions
|
@ -71,7 +71,6 @@ import {
|
|||
IEnterpriseSearchRequestHandler,
|
||||
} from './lib/enterprise_search_request_handler';
|
||||
|
||||
import { registerAppSearchRoutes } from './routes/app_search';
|
||||
import { registerEnterpriseSearchRoutes } from './routes/enterprise_search';
|
||||
import { registerAnalyticsRoutes } from './routes/enterprise_search/analytics';
|
||||
import { registerApiKeysRoutes } from './routes/enterprise_search/api_keys';
|
||||
|
@ -80,7 +79,6 @@ import { registerConnectorRoutes } from './routes/enterprise_search/connectors';
|
|||
import { registerCrawlerRoutes } from './routes/enterprise_search/crawler/crawler';
|
||||
import { registerStatsRoutes } from './routes/enterprise_search/stats';
|
||||
import { registerTelemetryRoute } from './routes/enterprise_search/telemetry';
|
||||
import { registerWorkplaceSearchRoutes } from './routes/workplace_search';
|
||||
|
||||
import { appSearchTelemetryType } from './saved_objects/app_search/telemetry';
|
||||
import { enterpriseSearchTelemetryType } from './saved_objects/enterprise_search/telemetry';
|
||||
|
@ -291,9 +289,7 @@ export class EnterpriseSearchPlugin implements Plugin<void, void, PluginsSetup,
|
|||
};
|
||||
|
||||
registerConfigDataRoute(dependencies);
|
||||
registerAppSearchRoutes(dependencies);
|
||||
registerEnterpriseSearchRoutes(dependencies);
|
||||
registerWorkplaceSearchRoutes(dependencies);
|
||||
// Enterprise Search Routes
|
||||
if (config.hasConnectors) registerConnectorRoutes(dependencies);
|
||||
if (config.hasWebCrawler) registerCrawlerRoutes(dependencies);
|
||||
|
|
|
@ -1,143 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerSearchRelevanceSuggestionsRoutes } from './adaptive_relevance';
|
||||
|
||||
describe('search relevance insights routes', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/engines/{name}/adaptive_relevance/suggestions', () => {
|
||||
const mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{engineName}/adaptive_relevance/suggestions',
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
registerSearchRelevanceSuggestionsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', async () => {
|
||||
await mockRouter.callRoute({
|
||||
params: { engineName: 'some-engine' },
|
||||
});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v0/engines/:engineName/adaptive_relevance/suggestions',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/app_search/engines/{name}/adaptive_relevance/suggestions', () => {
|
||||
const mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/app_search/engines/{engineName}/adaptive_relevance/suggestions',
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
registerSearchRelevanceSuggestionsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', async () => {
|
||||
await mockRouter.callRoute({
|
||||
params: { engineName: 'some-engine' },
|
||||
body: {
|
||||
query: 'some query',
|
||||
type: 'curation',
|
||||
status: 'applied',
|
||||
},
|
||||
});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v0/engines/:engineName/adaptive_relevance/suggestions',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{name}/adaptive_relevance/settings', () => {
|
||||
const mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/adaptive_relevance/settings',
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
registerSearchRelevanceSuggestionsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', async () => {
|
||||
await mockRouter.callRoute({
|
||||
params: { engineName: 'some-engine' },
|
||||
});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v0/engines/:engineName/adaptive_relevance/settings',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/app_search/engines/{name}/adaptive_relevance/settings', () => {
|
||||
const mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/app_search/engines/{engineName}/adaptive_relevance/settings',
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
registerSearchRelevanceSuggestionsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', async () => {
|
||||
await mockRouter.callRoute({
|
||||
params: { engineName: 'some-engine' },
|
||||
body: { curation: { enabled: true } },
|
||||
});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v0/engines/:engineName/adaptive_relevance/settings',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{engineName}/adaptive_relevance/suggestions/{query}', () => {
|
||||
const mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/adaptive_relevance/suggestions/{query}',
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
registerSearchRelevanceSuggestionsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', async () => {
|
||||
await mockRouter.callRoute({
|
||||
params: { engineName: 'some-engine', query: 'foo' },
|
||||
query: { type: 'curation' },
|
||||
});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/adaptive_relevance/suggestions/:query',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,101 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { skipBodyValidation } from '../../lib/route_config_helpers';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerSearchRelevanceSuggestionsRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/adaptive_relevance/suggestions',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
page: schema.object({
|
||||
current: schema.number(),
|
||||
size: schema.number(),
|
||||
}),
|
||||
filters: schema.object({
|
||||
status: schema.arrayOf(schema.string()),
|
||||
type: schema.string(),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v0/engines/:engineName/adaptive_relevance/suggestions',
|
||||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
skipBodyValidation({
|
||||
path: '/internal/app_search/engines/{engineName}/adaptive_relevance/suggestions',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v0/engines/:engineName/adaptive_relevance/suggestions',
|
||||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/adaptive_relevance/settings',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v0/engines/:engineName/adaptive_relevance/settings',
|
||||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
skipBodyValidation({
|
||||
path: '/internal/app_search/engines/{engineName}/adaptive_relevance/settings',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v0/engines/:engineName/adaptive_relevance/settings',
|
||||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/adaptive_relevance/suggestions/{query}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
query: schema.string(),
|
||||
}),
|
||||
query: schema.object({
|
||||
type: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/adaptive_relevance/suggestions/:query',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerAnalyticsRoutes } from './analytics';
|
||||
|
||||
describe('analytics routes', () => {
|
||||
describe('GET /internal/app_search/engines/{engineName}/analytics/queries', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/analytics/queries',
|
||||
});
|
||||
|
||||
registerAnalyticsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/analytics/queries',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly without optional query params', () => {
|
||||
const request = { query: {} };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('correctly with all optional query params', () => {
|
||||
const request = {
|
||||
query: {
|
||||
size: 20,
|
||||
start: '1970-01-01',
|
||||
end: '1970-01-02',
|
||||
tag: 'some-tag',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('incorrect types', () => {
|
||||
const request = {
|
||||
query: {
|
||||
start: 100,
|
||||
size: '100',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{engineName}/analytics/queries/{query}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/analytics/queries/{query}',
|
||||
});
|
||||
|
||||
registerAnalyticsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/analytics/query/:query',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly without optional query params', () => {
|
||||
const request = { query: {} };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('correctly with all optional query params', () => {
|
||||
const request = {
|
||||
query: {
|
||||
start: '1970-01-01',
|
||||
end: '1970-01-02',
|
||||
tag: 'some-tag',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('incorrect types', () => {
|
||||
const request = {
|
||||
query: {
|
||||
start: 100,
|
||||
tag: false,
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
const querySchema = {
|
||||
start: schema.maybe(schema.string()), // Date string, expected format 'YYYY-MM-DD'
|
||||
end: schema.maybe(schema.string()), // Date string, expected format 'YYYY-MM-DD'
|
||||
tag: schema.maybe(schema.string()),
|
||||
};
|
||||
const queriesSchema = {
|
||||
...querySchema,
|
||||
size: schema.maybe(schema.number()),
|
||||
};
|
||||
|
||||
export function registerAnalyticsRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/analytics/queries',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
query: schema.object(queriesSchema),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/analytics/queries',
|
||||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/analytics/queries/{query}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
query: schema.string(),
|
||||
}),
|
||||
query: schema.object(querySchema),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/analytics/query/:query',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerApiLogsRoutes } from './api_logs';
|
||||
|
||||
describe('API logs routes', () => {
|
||||
describe('GET /internal/app_search/engines/{engineName}/api_logs', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/api_logs',
|
||||
});
|
||||
|
||||
registerApiLogsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/api_logs/collection',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('with required query params', () => {
|
||||
const request = {
|
||||
query: {
|
||||
'filters[date][from]': '1970-01-01T12:00:00.000Z',
|
||||
'filters[date][to]': '1970-01-02T12:00:00.000Z',
|
||||
'page[current]': 1,
|
||||
sort_direction: 'desc',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('missing params', () => {
|
||||
const request = { query: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerApiLogsRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/api_logs',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
query: schema.object({
|
||||
'filters[date][from]': schema.string(), // Date string, expected format: ISO string
|
||||
'filters[date][to]': schema.string(), // Date string, expected format: ISO string
|
||||
'page[current]': schema.number(),
|
||||
sort_direction: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/api_logs/collection',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerAppSearchGatedFormRoute } from './app_search_gated_form';
|
||||
|
||||
describe('Overview route with kibana_uis_enabled ', () => {
|
||||
describe('POST /internal/app_search/as_gate', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/as_gate',
|
||||
});
|
||||
|
||||
registerAppSearchGatedFormRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/ent/v2/internal/as_gate',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
as_gate_data: {
|
||||
additional_feedback: '',
|
||||
feature: 'Selected feature',
|
||||
features_other: '',
|
||||
participate_in_ux_labs: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('throws error unexpected values in body', () => {
|
||||
const request = {
|
||||
body: {
|
||||
foo: 'bar',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerAppSearchGatedFormRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/as_gate',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
as_gate_data: schema.object({
|
||||
additional_feedback: schema.maybe(schema.string()),
|
||||
feature: schema.string(),
|
||||
features_other: schema.maybe(schema.string()),
|
||||
participate_in_ux_labs: schema.maybe(schema.boolean()),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/ent/v2/internal/as_gate',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,715 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { mockDependencies, mockRequestHandler, MockRouter } from '../../__mocks__';
|
||||
|
||||
import { registerCrawlerRoutes } from './crawler';
|
||||
|
||||
describe('crawler routes', () => {
|
||||
describe('GET /internal/app_search/engines/{name}/crawler', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{name}/crawler',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with name', () => {
|
||||
const request = { params: { name: 'some-engine' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without name', () => {
|
||||
const request = { params: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{name}/crawler/crawl_requests', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{name}/crawler/crawl_requests',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler/crawl_requests',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with name', () => {
|
||||
const request = { params: { name: 'some-engine' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without name', () => {
|
||||
const request = { params: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{name}/crawler/crawl_requests/{id}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{name}/crawler/crawl_requests/{id}',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler/crawl_requests/:id',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with name and id', () => {
|
||||
const request = { params: { name: 'some-engine', id: '12345' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without name', () => {
|
||||
const request = { params: { id: '12345' } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation without id', () => {
|
||||
const request = { params: { name: 'some-engine' } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/engines/{name}/crawler/crawl_requests', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{name}/crawler/crawl_requests',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler/crawl_requests',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with name', () => {
|
||||
const request = { params: { name: 'some-engine' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('validates correctly with domain urls', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
body: { overrides: { domain_allowlist: ['https://www.elastic.co'] } },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('validates correctly with max crawl depth', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
body: { overrides: { max_crawl_depth: 10 } },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('validates correctly with seed urls', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
body: { overrides: { seed_urls: ['https://www.elastic.co/guide'] } },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('validates correctly with sitemap urls', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
body: { overrides: { sitemap_urls: ['https://www.elastic.co/sitemap1.xml'] } },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('validates correctly when we set sitemap discovery', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
body: { overrides: { sitemap_discovery_disabled: true } },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('validates correctly with empty overrides', () => {
|
||||
const request = { params: { name: 'some-engine' }, body: { overrides: {} } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without name', () => {
|
||||
const request = { params: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{name}/crawler/domains', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{name}/crawler/domains',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler/domains',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
query: {
|
||||
'page[current]': 5,
|
||||
'page[size]': 10,
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without required params', () => {
|
||||
const request = { params: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/engines/{name}/crawler/crawl_requests/cancel', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{name}/crawler/crawl_requests/cancel',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler/crawl_requests/active/cancel',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with name', () => {
|
||||
const request = { params: { name: 'some-engine' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without name', () => {
|
||||
const request = { params: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/engines/{name}/crawler/domains', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{name}/crawler/domains',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler/domains',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with params and body', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
body: { name: 'https://elastic.co/guide', entry_points: [{ value: '/guide' }] },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('accepts a query param', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
body: { name: 'https://elastic.co/guide', entry_points: [{ value: '/guide' }] },
|
||||
query: { respond_with: 'crawler_details' },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without a name param', () => {
|
||||
const request = {
|
||||
params: {},
|
||||
body: { name: 'https://elastic.co/guide', entry_points: [{ value: '/guide' }] },
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation without a body', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
body: {},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/app_search/engines/{name}/crawler/domains/{id}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/app_search/engines/{name}/crawler/domains/{id}',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler/domains/:id',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with name and id', () => {
|
||||
const request = { params: { name: 'some-engine', id: '1234' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without name', () => {
|
||||
const request = { params: { id: '1234' } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation without id', () => {
|
||||
const request = { params: { name: 'test-engine' } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('accepts a query param', () => {
|
||||
const request = {
|
||||
params: { name: 'test-engine', id: '1234' },
|
||||
query: { respond_with: 'crawler_details' },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/app_search/engines/{name}/crawler/domains/{id}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/app_search/engines/{name}/crawler/domains/{id}',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler/domains/:id',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with crawl rules', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine', id: '1234' },
|
||||
body: {
|
||||
crawl_rules: [
|
||||
{
|
||||
order: 1,
|
||||
id: '5678',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('validates correctly with deduplication enabled', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine', id: '1234' },
|
||||
body: {
|
||||
deduplication_enabled: true,
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('validates correctly with deduplication fields', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine', id: '1234' },
|
||||
body: {
|
||||
deduplication_fields: ['title', 'description'],
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{name}/crawler/domains/{id}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{name}/crawler/domains/{id}',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler/domains/:id',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with name and id', () => {
|
||||
const request = { params: { name: 'some-engine', id: '1234' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without name', () => {
|
||||
const request = { params: { id: '1234' } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation without id', () => {
|
||||
const request = { params: { name: 'test-engine' } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/crawler/validate_url', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/crawler/validate_url',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/crawler/validate_url',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with body', () => {
|
||||
const request = {
|
||||
body: { url: 'elastic.co', checks: ['tcp', 'url_request'] },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without a body', () => {
|
||||
const request = {
|
||||
body: {},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/engines/{name}/crawler/process_crawls', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{name}/crawler/process_crawls',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler/process_crawls',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
body: { domains: ['https://elastic.co', 'https://swiftype.com'] },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('validates correctly without body', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
body: {},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without a name param', () => {
|
||||
const request = {
|
||||
params: {},
|
||||
body: { domains: ['https://elastic.co', 'https://swiftype.com'] },
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{name}/crawler/crawl_schedule', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{name}/crawler/crawl_schedule',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler/crawl_schedule',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without a name param', () => {
|
||||
const request = {
|
||||
params: {},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/app_search/engines/{name}/crawler/crawl_schedule', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/app_search/engines/{name}/crawler/crawl_schedule',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler/crawl_schedule',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
body: { unit: 'day', frequency: 7 },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without a name param', () => {
|
||||
const request = {
|
||||
params: {},
|
||||
body: { unit: 'day', frequency: 7 },
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation without a unit property in body', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
body: { frequency: 7 },
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation without a frequency property in body', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
body: { unit: 'day' },
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/app_search/engines/{name}/crawler/crawl_schedule', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/app_search/engines/{name}/crawler/crawl_schedule',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler/crawl_schedule',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly', () => {
|
||||
const request = {
|
||||
params: { name: 'some-engine' },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without a name param', () => {
|
||||
const request = {
|
||||
params: {},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{name}/crawler/domain_configs', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{name}/crawler/domain_configs',
|
||||
});
|
||||
|
||||
registerCrawlerRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:name/crawler/domain_configs',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with name', () => {
|
||||
const request = { params: { name: 'some-engine' }, query: { 'page[current]': 4 } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('validates correctly with page[current]', () => {
|
||||
const request = { params: { name: 'some-engine' }, query: { 'page[size]': 100 } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without page[size]', () => {
|
||||
const request = { params: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,296 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerCrawlerRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler',
|
||||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler/crawl_requests',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler/crawl_requests',
|
||||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler/crawl_requests/{id}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
id: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler/crawl_requests/:id',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler/crawl_requests',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
overrides: schema.maybe(
|
||||
schema.object({
|
||||
domain_allowlist: schema.maybe(schema.arrayOf(schema.string())),
|
||||
max_crawl_depth: schema.maybe(schema.number()),
|
||||
seed_urls: schema.maybe(schema.arrayOf(schema.string())),
|
||||
sitemap_urls: schema.maybe(schema.arrayOf(schema.string())),
|
||||
sitemap_discovery_disabled: schema.maybe(schema.boolean()),
|
||||
})
|
||||
),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler/crawl_requests',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler/crawl_requests/cancel',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler/crawl_requests/active/cancel',
|
||||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler/domains',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
query: schema.object({
|
||||
'page[current]': schema.number(),
|
||||
'page[size]': schema.number(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler/domains',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler/domains',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
name: schema.string(),
|
||||
entry_points: schema.arrayOf(
|
||||
schema.object({
|
||||
value: schema.string(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
query: schema.object({
|
||||
respond_with: schema.maybe(schema.string()),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler/domains',
|
||||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler/domains/{id}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
id: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler/domains/:id',
|
||||
})
|
||||
);
|
||||
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler/domains/{id}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
id: schema.string(),
|
||||
}),
|
||||
query: schema.object({
|
||||
respond_with: schema.maybe(schema.string()),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler/domains/:id',
|
||||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler/domains/{id}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
id: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
crawl_rules: schema.maybe(
|
||||
schema.arrayOf(
|
||||
schema.object({
|
||||
order: schema.number(),
|
||||
id: schema.string(),
|
||||
})
|
||||
)
|
||||
),
|
||||
deduplication_enabled: schema.maybe(schema.boolean()),
|
||||
deduplication_fields: schema.maybe(schema.arrayOf(schema.string())),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler/domains/:id',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/crawler/validate_url',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
url: schema.string(),
|
||||
checks: schema.arrayOf(schema.string()),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/crawler/validate_url',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler/process_crawls',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
domains: schema.maybe(schema.arrayOf(schema.string())),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler/process_crawls',
|
||||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler/crawl_schedule',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler/crawl_schedule',
|
||||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler/crawl_schedule',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
unit: schema.string(),
|
||||
frequency: schema.number(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler/crawl_schedule',
|
||||
})
|
||||
);
|
||||
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler/crawl_schedule',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler/crawl_schedule',
|
||||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/crawler/domain_configs',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
query: schema.object({
|
||||
'page[current]': schema.maybe(schema.number()),
|
||||
'page[size]': schema.maybe(schema.number()),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:name/crawler/domain_configs',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { mockDependencies, mockRequestHandler, MockRouter } from '../../__mocks__';
|
||||
|
||||
import { registerCrawlerCrawlRulesRoutes } from './crawler_crawl_rules';
|
||||
|
||||
describe('crawler crawl rules routes', () => {
|
||||
describe('POST /internal/app_search/engines/{engineName}/crawler/domains/{domainId}/crawl_rules', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/crawl_rules',
|
||||
});
|
||||
|
||||
registerCrawlerCrawlRulesRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/crawl_rules',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with required params', () => {
|
||||
const request = {
|
||||
params: { engineName: 'some-engine', domainId: '1234' },
|
||||
body: {
|
||||
pattern: '*',
|
||||
policy: 'allow',
|
||||
rule: 'begins',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails otherwise', () => {
|
||||
const request = { params: {}, body: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/app_search/engines/{engineName}/crawler/domains/{domainId}/crawl_rules/{crawlRuleId}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/crawl_rules/{crawlRuleId}',
|
||||
});
|
||||
|
||||
registerCrawlerCrawlRulesRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/crawl_rules/:crawlRuleId',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with required params', () => {
|
||||
const request = {
|
||||
params: { engineName: 'some-engine', domainId: '1234', crawlRuleId: '5678' },
|
||||
body: {
|
||||
order: 1,
|
||||
pattern: '*',
|
||||
policy: 'allow',
|
||||
rule: 'begins',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails otherwise', () => {
|
||||
const request = { params: {}, body: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/app_search/engines/{engineName}/crawler/domains/{domainId}/crawl_rules/{crawlRuleId}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/crawl_rules/{crawlRuleId}',
|
||||
});
|
||||
|
||||
registerCrawlerCrawlRulesRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/crawl_rules/:crawlRuleId',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with required params', () => {
|
||||
const request = {
|
||||
params: { engineName: 'some-engine', domainId: '1234', crawlRuleId: '5678' },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails otherwise', () => {
|
||||
const request = { params: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerCrawlerCrawlRulesRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/crawl_rules',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
domainId: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
pattern: schema.string(),
|
||||
policy: schema.string(),
|
||||
rule: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/crawl_rules',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/crawl_rules/{crawlRuleId}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
domainId: schema.string(),
|
||||
crawlRuleId: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
order: schema.number(),
|
||||
pattern: schema.string(),
|
||||
policy: schema.string(),
|
||||
rule: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/crawl_rules/:crawlRuleId',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/crawl_rules/{crawlRuleId}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
domainId: schema.string(),
|
||||
crawlRuleId: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/crawl_rules/:crawlRuleId',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,132 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { mockDependencies, mockRequestHandler, MockRouter } from '../../__mocks__';
|
||||
|
||||
import { registerCrawlerEntryPointRoutes } from './crawler_entry_points';
|
||||
|
||||
describe('crawler entry point routes', () => {
|
||||
describe('POST /internal/app_search/engines/{engineName}/crawler/domains/{domainId}/entry_points', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/entry_points',
|
||||
});
|
||||
|
||||
registerCrawlerEntryPointRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/entry_points',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with required params', () => {
|
||||
const request = {
|
||||
params: { engineName: 'some-engine', domainId: '1234' },
|
||||
body: {
|
||||
value: 'test',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails otherwise', () => {
|
||||
const request = { params: {}, body: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/app_search/engines/{engineName}/crawler/domains/{domainId}/entry_points/{entryPointId}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/entry_points/{entryPointId}',
|
||||
});
|
||||
|
||||
registerCrawlerEntryPointRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/entry_points/:entryPointId',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with required params', () => {
|
||||
const request = {
|
||||
params: { engineName: 'some-engine', domainId: '1234', entryPointId: '5678' },
|
||||
body: {
|
||||
value: 'test',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails otherwise', () => {
|
||||
const request = { params: {}, body: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/app_search/engines/{engineName}/crawler/domains/{domainId}/entry_points/{entryPointId}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/entry_points/{entryPointId}',
|
||||
});
|
||||
|
||||
registerCrawlerEntryPointRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/entry_points/:entryPointId',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with required params', () => {
|
||||
const request = {
|
||||
params: { engineName: 'some-engine', domainId: '1234', entryPointId: '5678' },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails otherwise', () => {
|
||||
const request = { params: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerCrawlerEntryPointRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/entry_points',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
domainId: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
value: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/entry_points',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/entry_points/{entryPointId}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
domainId: schema.string(),
|
||||
entryPointId: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
value: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/entry_points/:entryPointId',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/entry_points/{entryPointId}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
domainId: schema.string(),
|
||||
entryPointId: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/entry_points/:entryPointId',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,132 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { mockDependencies, mockRequestHandler, MockRouter } from '../../__mocks__';
|
||||
|
||||
import { registerCrawlerSitemapRoutes } from './crawler_sitemaps';
|
||||
|
||||
describe('crawler sitemap routes', () => {
|
||||
describe('POST /internal/app_search/engines/{engineName}/crawler/domains/{domainId}/sitemaps', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/sitemaps',
|
||||
});
|
||||
|
||||
registerCrawlerSitemapRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/sitemaps',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with required params', () => {
|
||||
const request = {
|
||||
params: { engineName: 'some-engine', domainId: '1234' },
|
||||
body: {
|
||||
url: 'http://www.example.com/sitemaps.xml',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails otherwise', () => {
|
||||
const request = { params: {}, body: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/app_search/engines/{engineName}/crawler/domains/{domainId}/sitemaps/{sitemapId}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/sitemaps/{sitemapId}',
|
||||
});
|
||||
|
||||
registerCrawlerSitemapRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/sitemaps/:sitemapId',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with required params', () => {
|
||||
const request = {
|
||||
params: { engineName: 'some-engine', domainId: '1234', sitemapId: '5678' },
|
||||
body: {
|
||||
url: 'http://www.example.com/sitemaps.xml',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails otherwise', () => {
|
||||
const request = { params: {}, body: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/app_search/engines/{engineName}/crawler/domains/{domainId}/sitemaps/{sitemapId}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/sitemaps/{sitemapId}',
|
||||
});
|
||||
|
||||
registerCrawlerSitemapRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/sitemaps/:sitemapId',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with required params', () => {
|
||||
const request = {
|
||||
params: { engineName: 'some-engine', domainId: '1234', sitemapId: '5678' },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails otherwise', () => {
|
||||
const request = { params: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerCrawlerSitemapRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/sitemaps',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
domainId: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
url: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/sitemaps',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/sitemaps/{sitemapId}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
domainId: schema.string(),
|
||||
sitemapId: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
url: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/sitemaps/:sitemapId',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/crawler/domains/{domainId}/sitemaps/{sitemapId}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
domainId: schema.string(),
|
||||
sitemapId: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v1/engines/:engineName/crawler/domains/:domainId/sitemaps/:sitemapId',
|
||||
params: {
|
||||
respond_with: 'index',
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,322 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerCredentialsRoutes } from './credentials';
|
||||
|
||||
describe('credentials routes', () => {
|
||||
describe('GET /internal/app_search/credentials', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/credentials',
|
||||
});
|
||||
|
||||
registerCredentialsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/credentials/collection',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
query: {
|
||||
'page[current]': 1,
|
||||
'page[size]': 10,
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('missing page query params', () => {
|
||||
const request = { query: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/credentials', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/credentials',
|
||||
});
|
||||
|
||||
registerCredentialsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/credentials/collection',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
describe('admin keys', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'admin-key',
|
||||
type: 'admin',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('throws on unnecessary properties', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'admin-key',
|
||||
type: 'admin',
|
||||
read: true,
|
||||
access_all_engines: true,
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('private keys', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'private-key',
|
||||
type: 'private',
|
||||
read: true,
|
||||
write: false,
|
||||
access_all_engines: false,
|
||||
engines: ['engine1', 'engine2'],
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('throws on missing keys', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'private-key',
|
||||
type: 'private',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('search keys', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'search-key',
|
||||
type: 'search',
|
||||
access_all_engines: true,
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('throws on missing keys', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'search-key',
|
||||
type: 'search',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('throws on extra keys', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'search-key',
|
||||
type: 'search',
|
||||
read: true,
|
||||
write: false,
|
||||
access_all_engines: false,
|
||||
engines: ['engine1', 'engine2'],
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/credentials/details', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/credentials/details',
|
||||
});
|
||||
|
||||
registerCredentialsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/credentials/details',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/app_search/credentials/{name}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/app_search/credentials/{name}',
|
||||
});
|
||||
|
||||
registerCredentialsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/credentials/:name',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
describe('admin keys', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'admin-key',
|
||||
type: 'admin',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('throws on unnecessary properties', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'admin-key',
|
||||
type: 'admin',
|
||||
read: true,
|
||||
access_all_engines: true,
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('private keys', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'private-key',
|
||||
type: 'private',
|
||||
read: true,
|
||||
write: false,
|
||||
access_all_engines: false,
|
||||
engines: ['engine1', 'engine2'],
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('throws on missing keys', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'private-key',
|
||||
type: 'private',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('search keys', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'search-key',
|
||||
type: 'search',
|
||||
access_all_engines: true,
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('throws on missing keys', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'search-key',
|
||||
type: 'search',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('throws on extra keys', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'search-key',
|
||||
type: 'search',
|
||||
read: true,
|
||||
write: false,
|
||||
access_all_engines: false,
|
||||
engines: ['engine1', 'engine2'],
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/app_search/credentials/{name}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/app_search/credentials/{name}',
|
||||
});
|
||||
|
||||
registerCredentialsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/credentials/:name',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,103 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
const tokenSchema = schema.oneOf([
|
||||
schema.object({
|
||||
name: schema.string(),
|
||||
type: schema.literal('admin'),
|
||||
}),
|
||||
schema.object({
|
||||
name: schema.string(),
|
||||
type: schema.literal('private'),
|
||||
read: schema.boolean(),
|
||||
write: schema.boolean(),
|
||||
access_all_engines: schema.boolean(),
|
||||
engines: schema.maybe(schema.arrayOf(schema.string())),
|
||||
}),
|
||||
schema.object({
|
||||
name: schema.string(),
|
||||
type: schema.literal('search'),
|
||||
access_all_engines: schema.boolean(),
|
||||
engines: schema.maybe(schema.arrayOf(schema.string())),
|
||||
}),
|
||||
]);
|
||||
|
||||
export function registerCredentialsRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
// Credentials API
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/credentials',
|
||||
validate: {
|
||||
query: schema.object({
|
||||
'page[current]': schema.number(),
|
||||
'page[size]': schema.number(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/credentials/collection',
|
||||
})
|
||||
);
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/credentials',
|
||||
validate: {
|
||||
body: tokenSchema,
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/credentials/collection',
|
||||
})
|
||||
);
|
||||
|
||||
// TODO: It would be great to remove this someday
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/credentials/details',
|
||||
validate: false,
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/credentials/details',
|
||||
})
|
||||
);
|
||||
|
||||
// Single credential API
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/app_search/credentials/{name}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
body: tokenSchema,
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/credentials/:name',
|
||||
})
|
||||
);
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/app_search/credentials/{name}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/credentials/:name',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,232 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerCurationsRoutes } from './curations';
|
||||
|
||||
describe('curations routes', () => {
|
||||
describe('GET /internal/app_search/engines/{engineName}/curations', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/curations',
|
||||
});
|
||||
|
||||
registerCurationsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/curations/collection',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('with pagination query params', () => {
|
||||
const request = {
|
||||
query: {
|
||||
'page[current]': 1,
|
||||
'page[size]': 10,
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('missing query params', () => {
|
||||
const request = { query: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/engines/{engineName}/curations', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{engineName}/curations',
|
||||
});
|
||||
|
||||
registerCurationsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/curations/collection',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('with curation queries', () => {
|
||||
const request = {
|
||||
body: {
|
||||
queries: ['a', 'b', 'c'],
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('empty queries array', () => {
|
||||
const request = {
|
||||
body: {
|
||||
queries: [],
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('empty query strings', () => {
|
||||
const request = {
|
||||
body: {
|
||||
queries: ['', '', ''],
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('missing queries', () => {
|
||||
const request = { body: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/app_search/engines/{engineName}/curations/{curationId}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/app_search/engines/{engineName}/curations/{curationId}',
|
||||
});
|
||||
|
||||
registerCurationsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/curations/:curationId',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{engineName}/curations/{curationId}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/curations/{curationId}',
|
||||
});
|
||||
|
||||
registerCurationsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/curations/:curationId',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/app_search/engines/{engineName}/curations/{curationId}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/app_search/engines/{engineName}/curations/{curationId}',
|
||||
});
|
||||
|
||||
registerCurationsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/curations/:curationId',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('required body', () => {
|
||||
const request = {
|
||||
body: {
|
||||
query: 'hello',
|
||||
queries: ['hello', 'world'],
|
||||
promoted: ['some-doc-id'],
|
||||
hidden: ['another-doc-id'],
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('missing body', () => {
|
||||
const request = { body: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/engines/{engineName}/curations/find_or_create', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{engineName}/curations/find_or_create',
|
||||
});
|
||||
|
||||
registerCurationsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/curations/find_or_create',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('required query param', () => {
|
||||
const request = { body: { query: 'some query' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('missing query', () => {
|
||||
const request = { body: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerCurationsRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/curations',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
query: schema.object({
|
||||
'page[current]': schema.number(),
|
||||
'page[size]': schema.number(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/curations/collection',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/curations',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
queries: schema.arrayOf(schema.string({ minLength: 1 }), { minSize: 1 }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/curations/collection',
|
||||
})
|
||||
);
|
||||
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/curations/{curationId}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
curationId: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/curations/:curationId',
|
||||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/curations/{curationId}',
|
||||
validate: {
|
||||
query: schema.object({
|
||||
skip_record_analytics: schema.string(),
|
||||
}),
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
curationId: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/curations/:curationId',
|
||||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/curations/{curationId}',
|
||||
validate: {
|
||||
query: schema.object({
|
||||
skip_record_analytics: schema.string(),
|
||||
}),
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
curationId: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
query: schema.string(),
|
||||
queries: schema.arrayOf(schema.string()),
|
||||
promoted: schema.arrayOf(schema.string()),
|
||||
hidden: schema.arrayOf(schema.string()),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/curations/:curationId',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/curations/find_or_create',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
query: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/curations/find_or_create',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerDocumentsRoutes, registerDocumentRoutes } from './documents';
|
||||
|
||||
describe('documents routes', () => {
|
||||
describe('POST /internal/app_search/engines/{engineName}/documents', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{engineName}/documents',
|
||||
});
|
||||
|
||||
registerDocumentsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/documents/new',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('document routes', () => {
|
||||
describe('GET /internal/app_search/engines/{engineName}/documents/{documentId}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/documents/{documentId}',
|
||||
});
|
||||
|
||||
registerDocumentRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/documents/:documentId',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/app_search/engines/{engineName}/documents/{documentId}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/app_search/engines/{engineName}/documents/{documentId}',
|
||||
});
|
||||
|
||||
registerDocumentRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/documents/:documentId',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { skipBodyValidation } from '../../lib/route_config_helpers';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerDocumentsRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
skipBodyValidation({
|
||||
path: '/internal/app_search/engines/{engineName}/documents',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/documents/new',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerDocumentRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/documents/{documentId}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
documentId: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/documents/:documentId',
|
||||
})
|
||||
);
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/documents/{documentId}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
documentId: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/documents/:documentId',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,324 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerEnginesRoutes } from './engines';
|
||||
|
||||
describe('engine routes', () => {
|
||||
describe('GET /internal/app_search/engines', () => {
|
||||
const mockRequest = {
|
||||
query: {
|
||||
type: 'indexed',
|
||||
'page[current]': 1,
|
||||
'page[size]': 10,
|
||||
},
|
||||
};
|
||||
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines',
|
||||
});
|
||||
|
||||
registerEnginesRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', async () => {
|
||||
await mockRouter.callRoute(mockRequest);
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/collection',
|
||||
hasValidData: expect.any(Function),
|
||||
});
|
||||
});
|
||||
|
||||
describe('hasValidData', () => {
|
||||
it('should correctly validate that the response has data', async () => {
|
||||
mockRequestHandler.createRequest.mockClear();
|
||||
const response = {
|
||||
meta: {
|
||||
page: {
|
||||
total_results: 1,
|
||||
},
|
||||
},
|
||||
results: [],
|
||||
};
|
||||
|
||||
await mockRouter.callRoute(mockRequest);
|
||||
expect(mockRequestHandler.hasValidData(response)).toBe(true);
|
||||
});
|
||||
|
||||
it('should correctly validate that a response does not have data', async () => {
|
||||
mockRequestHandler.createRequest.mockClear();
|
||||
const response = {};
|
||||
|
||||
await mockRouter.callRoute(mockRequest);
|
||||
expect(mockRequestHandler.hasValidData(response)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
query: {
|
||||
type: 'meta',
|
||||
'page[current]': 5,
|
||||
'page[size]': 10,
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('wrong type string', () => {
|
||||
const request = {
|
||||
query: {
|
||||
type: 'invalid',
|
||||
'page[current]': 5,
|
||||
'page[size]': 10,
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('missing query params', () => {
|
||||
const request = { query: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/engines', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines',
|
||||
});
|
||||
|
||||
registerEnginesRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', async () => {
|
||||
await mockRouter.callRoute({ body: { name: 'some-engine', language: 'en' } });
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/collection',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
describe('indexed engines', () => {
|
||||
it('correctly', () => {
|
||||
const request = { body: { name: 'some-engine', language: 'en' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('missing name', () => {
|
||||
const request = { body: { language: 'en' } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('optional language', () => {
|
||||
const request = { body: { name: 'some-engine' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('meta engines', () => {
|
||||
it('all properties', () => {
|
||||
const request = {
|
||||
body: { name: 'some-meta-engine', type: 'any', language: 'en', source_engines: [] },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('missing name', () => {
|
||||
const request = {
|
||||
body: { type: 'any', language: 'en', source_engines: [] },
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('optional language', () => {
|
||||
const request = {
|
||||
body: { name: 'some-meta-engine', type: 'any', source_engines: [] },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('optional source_engines', () => {
|
||||
const request = {
|
||||
body: { name: 'some-meta-engine', type: 'any', language: 'en' },
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('optional type', () => {
|
||||
const request = { body: { name: 'some-engine' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/elasticsearch/engines', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/elasticsearch/engines',
|
||||
});
|
||||
|
||||
registerEnginesRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', async () => {
|
||||
await mockRouter.callRoute({
|
||||
body: {
|
||||
name: 'some-elasticindexed-engine',
|
||||
search_index: { type: 'elasticsearch', index_name: 'search-elastic-index' },
|
||||
},
|
||||
});
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/as/v0/engines',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
describe('indexed engines', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'some-engine',
|
||||
search_index: { type: 'elasticsearch', index_name: 'search-elastic-index' },
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('missing name', () => {
|
||||
const request = {
|
||||
body: {
|
||||
search_index: { type: 'elasticsearch', index_name: 'search-elastic-index' },
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('missing index_name', () => {
|
||||
const request = {
|
||||
name: 'some-engine',
|
||||
body: {
|
||||
search_index: { type: 'elasticsearch' },
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{name}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{name}',
|
||||
});
|
||||
|
||||
registerEnginesRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:name/details',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/app_search/engines/{name}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/app_search/engines/{name}',
|
||||
});
|
||||
|
||||
registerEnginesRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:name',
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with name', () => {
|
||||
const request = { params: { name: 'test-engine' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without name', () => {
|
||||
const request = { params: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation with a non-string name', () => {
|
||||
const request = { params: { name: 1 } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{name}/overview', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{name}/overview',
|
||||
});
|
||||
|
||||
registerEnginesRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:name/overview_metrics',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
interface EnginesResponse {
|
||||
results: object[];
|
||||
meta: { page: { total_results: number } };
|
||||
}
|
||||
|
||||
export function registerEnginesRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines',
|
||||
validate: {
|
||||
query: schema.object({
|
||||
type: schema.oneOf([schema.literal('indexed'), schema.literal('meta')]),
|
||||
'page[current]': schema.number(),
|
||||
'page[size]': schema.number(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
async (context, request, response) => {
|
||||
return enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/collection',
|
||||
hasValidData: (body?: EnginesResponse) =>
|
||||
Array.isArray(body?.results) && typeof body?.meta?.page?.total_results === 'number',
|
||||
})(context, request, response);
|
||||
}
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/engines',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
name: schema.string(),
|
||||
language: schema.maybe(schema.string()),
|
||||
source_engines: schema.maybe(schema.arrayOf(schema.string())),
|
||||
type: schema.maybe(schema.string()),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/collection',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/elasticsearch/engines',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
name: schema.string(),
|
||||
search_index: schema.object({
|
||||
type: schema.string(),
|
||||
index_name: schema.string(),
|
||||
alias_name: schema.maybe(schema.string()),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/as/v0/engines',
|
||||
})
|
||||
);
|
||||
|
||||
// Single engine endpoints
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:name/details',
|
||||
})
|
||||
);
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:name',
|
||||
})
|
||||
);
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/overview',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:name/overview_metrics',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { mockDependencies, MockRouter } from '../../__mocks__';
|
||||
|
||||
import { registerAppSearchRoutes } from '.';
|
||||
|
||||
describe('registerAppSearchRoutes', () => {
|
||||
it('runs without errors', () => {
|
||||
const mockRouter = new MockRouter({} as any);
|
||||
registerAppSearchRoutes({ ...mockDependencies, router: mockRouter.router });
|
||||
});
|
||||
});
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
import { registerCrawlerExtractionRulesRoutes } from '../enterprise_search/crawler/crawler_extraction_rules';
|
||||
|
||||
import { registerSearchRelevanceSuggestionsRoutes } from './adaptive_relevance';
|
||||
import { registerAnalyticsRoutes } from './analytics';
|
||||
import { registerApiLogsRoutes } from './api_logs';
|
||||
import { registerAppSearchGatedFormRoute } from './app_search_gated_form';
|
||||
import { registerCrawlerRoutes } from './crawler';
|
||||
import { registerCrawlerCrawlRulesRoutes } from './crawler_crawl_rules';
|
||||
import { registerCrawlerEntryPointRoutes } from './crawler_entry_points';
|
||||
import { registerCrawlerSitemapRoutes } from './crawler_sitemaps';
|
||||
import { registerCredentialsRoutes } from './credentials';
|
||||
import { registerCurationsRoutes } from './curations';
|
||||
import { registerDocumentsRoutes, registerDocumentRoutes } from './documents';
|
||||
import { registerEnginesRoutes } from './engines';
|
||||
import { registerOnboardingRoutes } from './onboarding';
|
||||
import { registerResultSettingsRoutes } from './result_settings';
|
||||
import { registerRoleMappingsRoutes } from './role_mappings';
|
||||
import { registerSchemaRoutes } from './schema';
|
||||
import { registerSearchRoutes } from './search';
|
||||
import { registerSearchSettingsRoutes } from './search_settings';
|
||||
import { registerSearchUIRoutes } from './search_ui';
|
||||
import { registerSettingsRoutes } from './settings';
|
||||
import { registerSourceEnginesRoutes } from './source_engines';
|
||||
import { registerSynonymsRoutes } from './synonyms';
|
||||
|
||||
export const registerAppSearchRoutes = (dependencies: RouteDependencies) => {
|
||||
registerEnginesRoutes(dependencies);
|
||||
registerCredentialsRoutes(dependencies);
|
||||
registerSettingsRoutes(dependencies);
|
||||
registerAnalyticsRoutes(dependencies);
|
||||
registerDocumentsRoutes(dependencies);
|
||||
registerDocumentRoutes(dependencies);
|
||||
registerSchemaRoutes(dependencies);
|
||||
registerSearchRoutes(dependencies);
|
||||
registerSourceEnginesRoutes(dependencies);
|
||||
registerCurationsRoutes(dependencies);
|
||||
registerSynonymsRoutes(dependencies);
|
||||
registerSearchSettingsRoutes(dependencies);
|
||||
registerRoleMappingsRoutes(dependencies);
|
||||
registerSearchUIRoutes(dependencies);
|
||||
registerResultSettingsRoutes(dependencies);
|
||||
registerApiLogsRoutes(dependencies);
|
||||
registerOnboardingRoutes(dependencies);
|
||||
registerCrawlerRoutes(dependencies);
|
||||
registerCrawlerEntryPointRoutes(dependencies);
|
||||
registerCrawlerCrawlRulesRoutes(dependencies);
|
||||
registerCrawlerExtractionRulesRoutes(dependencies);
|
||||
registerCrawlerSitemapRoutes(dependencies);
|
||||
registerSearchRelevanceSuggestionsRoutes(dependencies);
|
||||
registerAppSearchGatedFormRoute(dependencies);
|
||||
};
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerOnboardingRoutes } from './onboarding';
|
||||
|
||||
describe('engine routes', () => {
|
||||
describe('POST /internal/app_search/onboarding_complete', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/onboarding_complete',
|
||||
});
|
||||
|
||||
registerOnboardingRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', async () => {
|
||||
await mockRouter.callRoute({ body: {} });
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/onboarding/complete',
|
||||
hasJsonResponse: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('validates seed_sample_engine ', () => {
|
||||
const request = { body: { seed_sample_engine: true } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerOnboardingRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/onboarding_complete',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
seed_sample_engine: schema.maybe(schema.boolean()),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/onboarding/complete',
|
||||
hasJsonResponse: false,
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { mockDependencies, mockRequestHandler, MockRouter } from '../../__mocks__';
|
||||
|
||||
import { registerResultSettingsRoutes } from './result_settings';
|
||||
|
||||
const resultFields = {
|
||||
id: {
|
||||
raw: {},
|
||||
},
|
||||
hp: {
|
||||
raw: {},
|
||||
},
|
||||
name: {
|
||||
raw: {},
|
||||
},
|
||||
};
|
||||
|
||||
describe('result settings routes', () => {
|
||||
describe('GET /internal/app_search/engines/{name}/result_settings/details', () => {
|
||||
const mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/result_settings/details',
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
registerResultSettingsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', async () => {
|
||||
await mockRouter.callRoute({
|
||||
params: { engineName: 'some-engine' },
|
||||
});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/result_settings/details',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/app_search/engines/{name}/result_settings', () => {
|
||||
const mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/app_search/engines/{engineName}/result_settings',
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
registerResultSettingsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', async () => {
|
||||
await mockRouter.callRoute({
|
||||
params: { engineName: 'some-engine' },
|
||||
body: {
|
||||
result_settings: resultFields,
|
||||
},
|
||||
});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/result_settings',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { skipBodyValidation } from '../../lib/route_config_helpers';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerResultSettingsRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/result_settings/details',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/result_settings/details',
|
||||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
skipBodyValidation({
|
||||
path: '/internal/app_search/engines/{engineName}/result_settings',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/result_settings',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,211 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import {
|
||||
registerEnableRoleMappingsRoute,
|
||||
registerRoleMappingsRoute,
|
||||
registerRoleMappingRoute,
|
||||
registerUserRoute,
|
||||
} from './role_mappings';
|
||||
|
||||
const roleMappingBaseSchema = {
|
||||
rules: { username: 'user' },
|
||||
roleType: 'owner',
|
||||
engines: ['e1', 'e2'],
|
||||
accessAllEngines: false,
|
||||
};
|
||||
|
||||
describe('role mappings routes', () => {
|
||||
describe('POST /internal/app_search/role_mappings/enable_role_based_access', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/role_mappings/enable_role_based_access',
|
||||
});
|
||||
|
||||
registerEnableRoleMappingsRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/role_mappings/enable_role_based_access',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/role_mappings', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/role_mappings',
|
||||
});
|
||||
|
||||
registerRoleMappingsRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/role_mappings',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/role_mappings', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/role_mappings',
|
||||
});
|
||||
|
||||
registerRoleMappingsRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/role_mappings',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = { body: roleMappingBaseSchema };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('missing required fields', () => {
|
||||
const request = { body: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/app_search/role_mappings/{id}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/app_search/role_mappings/{id}',
|
||||
});
|
||||
|
||||
registerRoleMappingRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/role_mappings/:id',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = { body: roleMappingBaseSchema };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('missing required fields', () => {
|
||||
const request = { body: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/app_search/role_mappings/{id}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/app_search/role_mappings/{id}',
|
||||
});
|
||||
|
||||
registerRoleMappingRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/role_mappings/:id',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/single_user_role_mapping', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/single_user_role_mapping',
|
||||
});
|
||||
|
||||
registerUserRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
roleMapping: {
|
||||
engines: ['foo', 'bar'],
|
||||
roleType: 'admin',
|
||||
accessAllEngines: true,
|
||||
id: '123asf',
|
||||
},
|
||||
elasticsearchUser: {
|
||||
username: 'user2@elastic.co',
|
||||
email: 'user2',
|
||||
},
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('missing required fields', () => {
|
||||
const request = { body: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/role_mappings/upsert_single_user_role_mapping',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,125 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
const roleMappingBaseSchema = {
|
||||
rules: schema.recordOf(schema.string(), schema.string()),
|
||||
roleType: schema.string(),
|
||||
engines: schema.arrayOf(schema.string()),
|
||||
accessAllEngines: schema.boolean(),
|
||||
};
|
||||
|
||||
export function registerEnableRoleMappingsRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/role_mappings/enable_role_based_access',
|
||||
validate: false,
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/role_mappings/enable_role_based_access',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerRoleMappingsRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/role_mappings',
|
||||
validate: false,
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/role_mappings',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/role_mappings',
|
||||
validate: {
|
||||
body: schema.object(roleMappingBaseSchema),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/role_mappings',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerRoleMappingRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/app_search/role_mappings/{id}',
|
||||
validate: {
|
||||
body: schema.object(roleMappingBaseSchema),
|
||||
params: schema.object({
|
||||
id: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/role_mappings/:id',
|
||||
})
|
||||
);
|
||||
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/app_search/role_mappings/{id}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
id: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/role_mappings/:id',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerUserRoute({ router, enterpriseSearchRequestHandler }: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/single_user_role_mapping',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
roleMapping: schema.object({
|
||||
engines: schema.arrayOf(schema.string()),
|
||||
roleType: schema.string(),
|
||||
accessAllEngines: schema.boolean(),
|
||||
id: schema.maybe(schema.string()),
|
||||
}),
|
||||
elasticsearchUser: schema.object({
|
||||
username: schema.string(),
|
||||
email: schema.string(),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/role_mappings/upsert_single_user_role_mapping',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export const registerRoleMappingsRoutes = (dependencies: RouteDependencies) => {
|
||||
registerEnableRoleMappingsRoute(dependencies);
|
||||
registerRoleMappingsRoute(dependencies);
|
||||
registerRoleMappingRoute(dependencies);
|
||||
registerUserRoute(dependencies);
|
||||
};
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerSchemaRoutes } from './schema';
|
||||
|
||||
describe('schema routes', () => {
|
||||
describe('GET /internal/app_search/engines/{engineName}/schema', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/schema',
|
||||
});
|
||||
|
||||
registerSchemaRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/schema',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/engines/{engineName}/schema', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{engineName}/schema',
|
||||
});
|
||||
|
||||
registerSchemaRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/schema',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{engineName}/reindex_job/{reindexJobId}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/reindex_job/{reindexJobId}',
|
||||
});
|
||||
|
||||
registerSchemaRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/reindex_job/:reindexJobId',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { skipBodyValidation } from '../../lib/route_config_helpers';
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerSchemaRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/schema',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/schema',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
skipBodyValidation({
|
||||
path: '/internal/app_search/engines/{engineName}/schema',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/schema',
|
||||
})
|
||||
);
|
||||
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/reindex_job/{reindexJobId}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
reindexJobId: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/reindex_job/:reindexJobId',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerSearchRoutes } from './search';
|
||||
|
||||
describe('search routes', () => {
|
||||
describe('GET /internal/app_search/engines/{engineName}/search', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/schema',
|
||||
});
|
||||
|
||||
registerSearchRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/dashboard_search',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { skipBodyValidation } from '../../lib/route_config_helpers';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerSearchRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
skipBodyValidation({
|
||||
path: '/internal/app_search/engines/{engineName}/search',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
query: schema.object({
|
||||
query: schema.string(),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/dashboard_search',
|
||||
})
|
||||
);
|
||||
|
||||
// Search UI always posts it's requests to {some_configured_base_url}/api/as/v1/engines/{engineName}/search.json
|
||||
// For that reason, we have to create a proxy url with that same suffix below, so that we can proxy Search UI
|
||||
// requests through Kibana's server.
|
||||
router.post(
|
||||
skipBodyValidation({
|
||||
path: '/internal/app_search/search-ui/api/as/v1/engines/{engineName}/search.json',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/dashboard_search',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerSearchSettingsRoutes } from './search_settings';
|
||||
|
||||
describe('search settings routes', () => {
|
||||
const boosts = {
|
||||
types: [
|
||||
{
|
||||
type: 'value',
|
||||
factor: 6.2,
|
||||
value: ['1313'],
|
||||
},
|
||||
],
|
||||
hp: [
|
||||
{
|
||||
function: 'exponential',
|
||||
type: 'functional',
|
||||
factor: 1,
|
||||
operation: 'add',
|
||||
},
|
||||
],
|
||||
};
|
||||
const resultFields = {
|
||||
id: {
|
||||
raw: {},
|
||||
},
|
||||
hp: {
|
||||
raw: {},
|
||||
},
|
||||
name: {
|
||||
raw: {},
|
||||
},
|
||||
};
|
||||
const searchFields = {
|
||||
hp: {
|
||||
weight: 1,
|
||||
},
|
||||
name: {
|
||||
weight: 1,
|
||||
},
|
||||
id: {
|
||||
weight: 1,
|
||||
},
|
||||
};
|
||||
const searchSettings = {
|
||||
boosts,
|
||||
result_fields: resultFields,
|
||||
search_fields: searchFields,
|
||||
precision: 2,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{name}/search_settings/details', () => {
|
||||
const mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/search_settings/details',
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
registerSearchSettingsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', async () => {
|
||||
await mockRouter.callRoute({
|
||||
params: { engineName: 'some-engine' },
|
||||
});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/search_settings/details',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/app_search/engines/{name}/search_settings', () => {
|
||||
const mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/app_search/engines/{engineName}/search_settings',
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
registerSearchSettingsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', async () => {
|
||||
await mockRouter.callRoute({
|
||||
params: { engineName: 'some-engine' },
|
||||
body: searchSettings,
|
||||
});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/search_settings',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/engines/{name}/search_settings/reset', () => {
|
||||
const mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{engineName}/search_settings/reset',
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
registerSearchSettingsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', async () => {
|
||||
await mockRouter.callRoute({
|
||||
params: { engineName: 'some-engine' },
|
||||
});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/search_settings/reset',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { skipBodyValidation } from '../../lib/route_config_helpers';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerSearchSettingsRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/search_settings/details',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/search_settings/details',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/search_settings/reset',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/search_settings/reset',
|
||||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
skipBodyValidation({
|
||||
path: '/internal/app_search/engines/{engineName}/search_settings',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/search_settings',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { mockDependencies, mockRequestHandler, MockRouter } from '../../__mocks__';
|
||||
|
||||
import { registerSearchUIRoutes } from './search_ui';
|
||||
|
||||
describe('reference application routes', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('GET /internal/app_search/engines/{engineName}/search_settings/details', () => {
|
||||
const mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/search_ui/field_config',
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
registerSearchUIRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', async () => {
|
||||
await mockRouter.callRoute({
|
||||
params: { engineName: 'some-engine' },
|
||||
});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/search_experience/field_config',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerSearchUIRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/search_ui/field_config',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/search_experience/field_config',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerSettingsRoutes } from './settings';
|
||||
|
||||
describe('log settings routes', () => {
|
||||
describe('GET /internal/app_search/log_settings', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/log_settings',
|
||||
});
|
||||
|
||||
registerSettingsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/log_settings',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/app_search/log_settings', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/app_search/log_settings',
|
||||
});
|
||||
|
||||
registerSettingsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/log_settings',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('validates good data', () => {
|
||||
mockRouter.shouldValidate({
|
||||
body: {
|
||||
analytics: { enabled: true },
|
||||
},
|
||||
});
|
||||
mockRouter.shouldValidate({
|
||||
body: {
|
||||
api: { enabled: true },
|
||||
},
|
||||
});
|
||||
mockRouter.shouldValidate({
|
||||
body: {
|
||||
crawler: { enabled: true },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects bad data', () => {
|
||||
const request = {
|
||||
body: {
|
||||
foo: 'bar',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerSettingsRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/log_settings',
|
||||
validate: false,
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/log_settings',
|
||||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/app_search/log_settings',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
api: schema.maybe(
|
||||
schema.object({
|
||||
enabled: schema.boolean(),
|
||||
})
|
||||
),
|
||||
analytics: schema.maybe(
|
||||
schema.object({
|
||||
enabled: schema.boolean(),
|
||||
})
|
||||
),
|
||||
audit: schema.maybe(
|
||||
schema.object({
|
||||
enabled: schema.boolean(),
|
||||
})
|
||||
),
|
||||
crawler: schema.maybe(
|
||||
schema.object({
|
||||
enabled: schema.boolean(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/log_settings',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,153 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerSourceEnginesRoutes } from './source_engines';
|
||||
|
||||
describe('source engine routes', () => {
|
||||
describe('GET /internal/app_search/engines/{name}/source_engines', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{name}/source_engines',
|
||||
});
|
||||
|
||||
registerSourceEnginesRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with name', () => {
|
||||
const request = { params: { name: 'test-engine' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without name', () => {
|
||||
const request = { params: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation with a non-string name', () => {
|
||||
const request = { params: { name: 1 } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation with missing query params', () => {
|
||||
const request = { query: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:name/source_engines',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/engines/{name}/source_engines/bulk_create', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{name}/source_engines/bulk_create',
|
||||
});
|
||||
|
||||
registerSourceEnginesRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with name', () => {
|
||||
const request = { params: { name: 'test-engine' }, body: { source_engine_slugs: [] } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without name', () => {
|
||||
const request = { params: {}, body: { source_engine_slugs: [] } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation with a non-string name', () => {
|
||||
const request = { params: { name: 1 }, body: { source_engine_slugs: [] } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation with missing query params', () => {
|
||||
const request = { params: { name: 'test-engine' }, body: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:name/source_engines/bulk_create',
|
||||
hasJsonResponse: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/app_search/engines/{name}/source_engines/{source_engine_name}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/app_search/engines/{name}/source_engines/{source_engine_name}',
|
||||
});
|
||||
|
||||
registerSourceEnginesRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('validates correctly with name and source_engine_name', () => {
|
||||
const request = { params: { name: 'test-engine', source_engine_name: 'source-engine' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('fails validation without name', () => {
|
||||
const request = { params: { source_engine_name: 'source-engine' } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation with a non-string name', () => {
|
||||
const request = { params: { name: 1, source_engine_name: 'source-engine' } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation without source_engine_name', () => {
|
||||
const request = { params: { name: 'test-engine' } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation with a non-string source_engine_name', () => {
|
||||
const request = { params: { name: 'test-engine', source_engine_name: 1 } };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('fails validation with missing query params', () => {
|
||||
const request = { query: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
|
||||
it('creates a request to enterprise search', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:name/source_engines/:source_engine_name',
|
||||
hasJsonResponse: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerSourceEnginesRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/source_engines',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
query: schema.object({
|
||||
'page[current]': schema.number(),
|
||||
'page[size]': schema.number(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:name/source_engines',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/source_engines/bulk_create',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
source_engine_slugs: schema.arrayOf(schema.string()),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:name/source_engines/bulk_create',
|
||||
hasJsonResponse: false,
|
||||
})
|
||||
);
|
||||
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/app_search/engines/{name}/source_engines/{source_engine_name}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
name: schema.string(),
|
||||
source_engine_name: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:name/source_engines/:source_engine_name',
|
||||
hasJsonResponse: false,
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerSynonymsRoutes } from './synonyms';
|
||||
|
||||
describe('synonyms routes', () => {
|
||||
describe('GET /internal/app_search/engines/{engineName}/synonyms', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/app_search/engines/{engineName}/synonyms',
|
||||
});
|
||||
|
||||
registerSynonymsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/synonyms/collection',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('with pagination query params', () => {
|
||||
const request = {
|
||||
query: {
|
||||
'page[current]': 1,
|
||||
'page[size]': 10,
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('missing query params', () => {
|
||||
const request = { query: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/app_search/engines/{engineName}/synonyms', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/app_search/engines/{engineName}/synonyms',
|
||||
});
|
||||
|
||||
registerSynonymsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/synonyms/collection',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/app_search/engines/{engineName}/synonyms/{synonymId}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/app_search/engines/{engineName}/synonyms/{synonymId}',
|
||||
});
|
||||
|
||||
registerSynonymsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/synonyms/:synonymId',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/app_search/engines/{engineName}/synonyms/{synonymId}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/app_search/engines/{engineName}/synonyms/{synonymId}',
|
||||
});
|
||||
|
||||
registerSynonymsRoutes({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/as/engines/:engineName/synonyms/:synonymId',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { skipBodyValidation } from '../../lib/route_config_helpers';
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerSynonymsRoutes({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/synonyms',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
query: schema.object({
|
||||
'page[current]': schema.number(),
|
||||
'page[size]': schema.number(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/synonyms/collection',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
skipBodyValidation({
|
||||
path: '/internal/app_search/engines/{engineName}/synonyms',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/synonyms/collection',
|
||||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
skipBodyValidation({
|
||||
path: '/internal/app_search/engines/{engineName}/synonyms/{synonymId}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
synonymId: schema.string(),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/synonyms/:synonymId',
|
||||
})
|
||||
);
|
||||
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/app_search/engines/{engineName}/synonyms/{synonymId}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
engineName: schema.string(),
|
||||
synonymId: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/as/engines/:engineName/synonyms/:synonymId',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerApiKeysRoute } from './api_keys';
|
||||
|
||||
describe('api keys routes', () => {
|
||||
describe('GET /internal/workplace_search/api_keys', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/workplace_search/api_keys',
|
||||
});
|
||||
|
||||
registerApiKeysRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/api_tokens',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/workplace_search/api_keys', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/workplace_search/api_keys',
|
||||
});
|
||||
|
||||
registerApiKeysRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/api_tokens',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
name: 'my-api-key',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/workplace_search/api_keys/{tokenName}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/workplace_search/api_keys/{tokenName}',
|
||||
});
|
||||
|
||||
registerApiKeysRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/api_tokens/:tokenName',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerApiKeysRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/workplace_search/api_keys',
|
||||
validate: false,
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/api_tokens',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/workplace_search/api_keys',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/api_tokens',
|
||||
})
|
||||
);
|
||||
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/workplace_search/api_keys/{tokenName}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
tokenName: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/api_tokens/:tokenName',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export const registerApiKeysRoutes = (dependencies: RouteDependencies) => {
|
||||
registerApiKeysRoute(dependencies);
|
||||
};
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerGatedFormRoute } from './gated_form';
|
||||
|
||||
describe('Overview route with kibana_uis_enabled ', () => {
|
||||
describe('POST /internal/workplace_search/ws_gate', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/workplace_search/ws_gate',
|
||||
});
|
||||
|
||||
registerGatedFormRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/api/ent/v2/internal/ws_gate',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
ws_gate_data: {
|
||||
additional_feedback: '',
|
||||
feature: 'Selected feature',
|
||||
features_other: '',
|
||||
participate_in_ux_labs: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('throws error unexpected values in body', () => {
|
||||
const request = {
|
||||
body: {
|
||||
foo: 'bar',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerGatedFormRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/workplace_search/ws_gate',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
ws_gate_data: schema.object({
|
||||
additional_feedback: schema.maybe(schema.string()),
|
||||
feature: schema.string(),
|
||||
features_other: schema.maybe(schema.string()),
|
||||
participate_in_ux_labs: schema.maybe(schema.boolean()),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/api/ent/v2/internal/ws_gate',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,303 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import {
|
||||
registerGroupsRoute,
|
||||
registerSearchGroupsRoute,
|
||||
registerGroupRoute,
|
||||
registerGroupUsersRoute,
|
||||
registerShareGroupRoute,
|
||||
registerBoostsGroupRoute,
|
||||
} from './groups';
|
||||
|
||||
describe('groups routes', () => {
|
||||
describe('GET /internal/workplace_search/groups', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/workplace_search/groups',
|
||||
});
|
||||
|
||||
registerGroupsRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/groups',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/workplace_search/groups', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/workplace_search/groups',
|
||||
});
|
||||
|
||||
registerGroupsRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/groups',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
group_name: 'group',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/workplace_search/groups/search', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/workplace_search/groups/search',
|
||||
});
|
||||
|
||||
registerSearchGroupsRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/groups/search',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
page: {
|
||||
current: 1,
|
||||
size: 1,
|
||||
},
|
||||
search: {
|
||||
query: 'foo',
|
||||
content_source_ids: ['123', '234'],
|
||||
},
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('throws on unnecessary properties', () => {
|
||||
const request = {
|
||||
body: {
|
||||
page: null,
|
||||
search: {
|
||||
kites: 'bar',
|
||||
},
|
||||
},
|
||||
};
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/workplace_search/groups/{id}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/workplace_search/groups/{id}',
|
||||
});
|
||||
|
||||
registerGroupRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/groups/:id',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/workplace_search/groups/{id}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/workplace_search/groups/{id}',
|
||||
});
|
||||
|
||||
registerGroupRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/groups/:id',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
group: {
|
||||
name: 'group',
|
||||
},
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/workplace_search/groups/{id}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/workplace_search/groups/{id}',
|
||||
});
|
||||
|
||||
registerGroupRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/groups/:id',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/workplace_search/groups/{id}/group_users', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/workplace_search/groups/{id}/group_users',
|
||||
});
|
||||
|
||||
registerGroupUsersRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/groups/:id/group_users',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/workplace_search/groups/{id}/share', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/workplace_search/groups/{id}/share',
|
||||
});
|
||||
|
||||
registerShareGroupRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/groups/:id/share',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
params: { id: '123' },
|
||||
body: {
|
||||
content_source_ids: ['123', '234'],
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/workplace_search/groups/{id}/boosts', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/workplace_search/groups/{id}/boosts',
|
||||
});
|
||||
|
||||
registerBoostsGroupRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/groups/:id/update_source_boosts',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
content_source_boosts: [['boost'], ['boost2', 'boost3']],
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,185 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerGroupsRoute({ router, enterpriseSearchRequestHandler }: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/workplace_search/groups',
|
||||
validate: false,
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/groups',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/workplace_search/groups',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
group_name: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/groups',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerSearchGroupsRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/workplace_search/groups/search',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
page: schema.object({
|
||||
current: schema.number(),
|
||||
size: schema.number(),
|
||||
}),
|
||||
search: schema.object({
|
||||
query: schema.string(),
|
||||
content_source_ids: schema.arrayOf(schema.string()),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/groups/search',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerGroupRoute({ router, enterpriseSearchRequestHandler }: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/workplace_search/groups/{id}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
id: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/groups/:id',
|
||||
})
|
||||
);
|
||||
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/workplace_search/groups/{id}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
id: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
group: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/groups/:id',
|
||||
})
|
||||
);
|
||||
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/workplace_search/groups/{id}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
id: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/groups/:id',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerGroupUsersRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/workplace_search/groups/{id}/group_users',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
id: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/groups/:id/group_users',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerShareGroupRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/workplace_search/groups/{id}/share',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
id: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
content_source_ids: schema.arrayOf(schema.string()),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/groups/:id/share',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerBoostsGroupRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/workplace_search/groups/{id}/boosts',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
id: schema.string(),
|
||||
}),
|
||||
body: schema.object({
|
||||
content_source_boosts: schema.arrayOf(
|
||||
schema.arrayOf(schema.oneOf([schema.string(), schema.number()]))
|
||||
),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/groups/:id/update_source_boosts',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export const registerGroupsRoutes = (dependencies: RouteDependencies) => {
|
||||
registerGroupsRoute(dependencies);
|
||||
registerSearchGroupsRoute(dependencies);
|
||||
registerGroupRoute(dependencies);
|
||||
registerGroupUsersRoute(dependencies);
|
||||
registerShareGroupRoute(dependencies);
|
||||
registerBoostsGroupRoute(dependencies);
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { mockDependencies, MockRouter } from '../../__mocks__';
|
||||
|
||||
import { registerWorkplaceSearchRoutes } from '.';
|
||||
|
||||
describe('registerWorkplaceSearchRoutes', () => {
|
||||
it('runs without errors', () => {
|
||||
const mockRouter = new MockRouter({} as any);
|
||||
registerWorkplaceSearchRoutes({ ...mockDependencies, router: mockRouter.router });
|
||||
});
|
||||
});
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
import { registerApiKeysRoutes } from './api_keys';
|
||||
import { registerGatedFormRoute } from './gated_form';
|
||||
import { registerGroupsRoutes } from './groups';
|
||||
import { registerOAuthRoutes } from './oauth';
|
||||
import { registerOverviewRoute } from './overview';
|
||||
import { registerRoleMappingsRoutes } from './role_mappings';
|
||||
import { registerSecurityRoutes } from './security';
|
||||
import { registerSettingsRoutes } from './settings';
|
||||
import { registerSourcesRoutes } from './sources';
|
||||
|
||||
export const registerWorkplaceSearchRoutes = (dependencies: RouteDependencies) => {
|
||||
registerApiKeysRoutes(dependencies);
|
||||
registerOverviewRoute(dependencies);
|
||||
registerOAuthRoutes(dependencies);
|
||||
registerGroupsRoutes(dependencies);
|
||||
registerRoleMappingsRoutes(dependencies);
|
||||
registerSourcesRoutes(dependencies);
|
||||
registerSettingsRoutes(dependencies);
|
||||
registerSecurityRoutes(dependencies);
|
||||
registerGatedFormRoute(dependencies);
|
||||
};
|
|
@ -1,143 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import {
|
||||
registerOAuthAuthorizeRoute,
|
||||
registerOAuthAuthorizeAcceptRoute,
|
||||
registerOAuthAuthorizeDenyRoute,
|
||||
} from './oauth';
|
||||
|
||||
describe('oauth routes', () => {
|
||||
describe('GET /internal/workplace_search/oauth/authorize', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/workplace_search/oauth/authorize',
|
||||
});
|
||||
|
||||
registerOAuthAuthorizeRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', async () => {
|
||||
await mockRouter.callRoute({});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/oauth/authorize',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
query: {
|
||||
access_type: 'offline',
|
||||
client_id: 'SomeClientUID',
|
||||
code_challenge: 'SomeRandomString',
|
||||
code_challenge_method: 'plain',
|
||||
response_type: 'code',
|
||||
response_mode: 'query',
|
||||
redirect_uri: 'https://my.domain/callback',
|
||||
scope: 'search',
|
||||
state: 'someRandomString',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/workplace_search/oauth/authorize', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/workplace_search/oauth/authorize',
|
||||
});
|
||||
|
||||
registerOAuthAuthorizeAcceptRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', async () => {
|
||||
await mockRouter.callRoute({});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/oauth/authorize',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
client_id: 'SomeClientUID',
|
||||
response_type: 'code',
|
||||
redirect_uri: 'https://my.domain/callback',
|
||||
scope: 'search',
|
||||
state: 'someRandomString',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/workplace_search/oauth/authorize', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/workplace_search/oauth/authorize',
|
||||
});
|
||||
|
||||
registerOAuthAuthorizeDenyRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', async () => {
|
||||
await mockRouter.callRoute({});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/oauth/authorize',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
client_id: 'SomeClientUID',
|
||||
response_type: 'code',
|
||||
redirect_uri: 'https://my.domain/callback',
|
||||
scope: 'search',
|
||||
state: 'someRandomString',
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerOAuthAuthorizeRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/workplace_search/oauth/authorize',
|
||||
validate: {
|
||||
query: schema.object({
|
||||
access_type: schema.maybe(schema.string()),
|
||||
client_id: schema.string(),
|
||||
code_challenge: schema.maybe(schema.string()),
|
||||
code_challenge_method: schema.maybe(schema.string()),
|
||||
response_type: schema.string(),
|
||||
response_mode: schema.maybe(schema.string()),
|
||||
redirect_uri: schema.maybe(schema.string()),
|
||||
scope: schema.maybe(schema.string()),
|
||||
state: schema.nullable(schema.string()),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/oauth/authorize',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerOAuthAuthorizeAcceptRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/workplace_search/oauth/authorize',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
client_id: schema.string(),
|
||||
response_type: schema.string(),
|
||||
redirect_uri: schema.maybe(schema.string()),
|
||||
scope: schema.maybe(schema.string()),
|
||||
state: schema.nullable(schema.string()),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/oauth/authorize',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerOAuthAuthorizeDenyRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/workplace_search/oauth/authorize',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
client_id: schema.string(),
|
||||
response_type: schema.string(),
|
||||
redirect_uri: schema.maybe(schema.string()),
|
||||
scope: schema.maybe(schema.string()),
|
||||
state: schema.nullable(schema.string()),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/oauth/authorize',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export const registerOAuthRoutes = (dependencies: RouteDependencies) => {
|
||||
registerOAuthAuthorizeRoute(dependencies);
|
||||
registerOAuthAuthorizeAcceptRoute(dependencies);
|
||||
registerOAuthAuthorizeDenyRoute(dependencies);
|
||||
};
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerOverviewRoute } from './overview';
|
||||
|
||||
describe('Overview route', () => {
|
||||
describe('GET /internal/workplace_search/overview', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/workplace_search/overview',
|
||||
});
|
||||
|
||||
registerOverviewRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org',
|
||||
hasValidData: expect.any(Function),
|
||||
});
|
||||
});
|
||||
|
||||
describe('hasValidData', () => {
|
||||
it('should correctly validate that the response has data', () => {
|
||||
const response = {
|
||||
accountsCount: 1,
|
||||
};
|
||||
|
||||
expect(mockRequestHandler.hasValidData(response)).toBe(true);
|
||||
});
|
||||
|
||||
it('should correctly validate that a response does not have data', () => {
|
||||
const response = {
|
||||
foo: 'bar',
|
||||
};
|
||||
|
||||
expect(mockRequestHandler.hasValidData(response)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerOverviewRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/workplace_search/overview',
|
||||
validate: false,
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org',
|
||||
hasValidData: (body: { accountsCount: number }) => typeof body?.accountsCount === 'number',
|
||||
})
|
||||
);
|
||||
}
|
|
@ -1,180 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import {
|
||||
registerOrgEnableRoleMappingsRoute,
|
||||
registerOrgRoleMappingsRoute,
|
||||
registerOrgRoleMappingRoute,
|
||||
registerOrgUserRoute,
|
||||
} from './role_mappings';
|
||||
|
||||
describe('role mappings routes', () => {
|
||||
describe('POST /internal/workplace_search/org/role_mappings/enable_role_based_access', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/workplace_search/org/role_mappings/enable_role_based_access',
|
||||
});
|
||||
|
||||
registerOrgEnableRoleMappingsRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/role_mappings/enable_role_based_access',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/workplace_search/org/role_mappings', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/workplace_search/org/role_mappings',
|
||||
});
|
||||
|
||||
registerOrgRoleMappingsRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/role_mappings/collection',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/workplace_search/org/role_mappings', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/workplace_search/org/role_mappings',
|
||||
});
|
||||
|
||||
registerOrgRoleMappingsRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/role_mappings/collection',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/workplace_search/org/role_mappings/{id}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/workplace_search/org/role_mappings/{id}',
|
||||
});
|
||||
|
||||
registerOrgRoleMappingRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/role_mappings/:id',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /internal/workplace_search/org/role_mappings/{id}', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'delete',
|
||||
path: '/internal/workplace_search/org/role_mappings/{id}',
|
||||
});
|
||||
|
||||
registerOrgRoleMappingRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/role_mappings/:id',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /internal/workplace_search/org/single_user_role_mapping', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'post',
|
||||
path: '/internal/workplace_search/org/single_user_role_mapping',
|
||||
});
|
||||
|
||||
registerOrgUserRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
roleMapping: {
|
||||
groups: ['foo', 'bar'],
|
||||
roleType: 'admin',
|
||||
allGroups: true,
|
||||
id: '123asf',
|
||||
},
|
||||
elasticsearchUser: {
|
||||
username: 'user2@elastic.co',
|
||||
email: 'user2',
|
||||
},
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
|
||||
it('missing required fields', () => {
|
||||
const request = { body: {} };
|
||||
mockRouter.shouldThrow(request);
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/role_mappings/upsert_single_user_role_mapping',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,128 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
const roleMappingBaseSchema = {
|
||||
rules: schema.recordOf(schema.string(), schema.string()),
|
||||
roleType: schema.string(),
|
||||
groups: schema.arrayOf(schema.string()),
|
||||
allGroups: schema.boolean(),
|
||||
};
|
||||
|
||||
export function registerOrgEnableRoleMappingsRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/workplace_search/org/role_mappings/enable_role_based_access',
|
||||
validate: false,
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/role_mappings/enable_role_based_access',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerOrgRoleMappingsRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/workplace_search/org/role_mappings',
|
||||
validate: false,
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/role_mappings/collection',
|
||||
})
|
||||
);
|
||||
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/workplace_search/org/role_mappings',
|
||||
validate: {
|
||||
body: schema.object(roleMappingBaseSchema),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/role_mappings/collection',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerOrgRoleMappingRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/workplace_search/org/role_mappings/{id}',
|
||||
validate: {
|
||||
body: schema.object(roleMappingBaseSchema),
|
||||
params: schema.object({
|
||||
id: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/role_mappings/:id',
|
||||
})
|
||||
);
|
||||
|
||||
router.delete(
|
||||
{
|
||||
path: '/internal/workplace_search/org/role_mappings/{id}',
|
||||
validate: {
|
||||
params: schema.object({
|
||||
id: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/role_mappings/:id',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerOrgUserRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.post(
|
||||
{
|
||||
path: '/internal/workplace_search/org/single_user_role_mapping',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
roleMapping: schema.object({
|
||||
groups: schema.arrayOf(schema.string()),
|
||||
roleType: schema.string(),
|
||||
allGroups: schema.boolean(),
|
||||
id: schema.maybe(schema.string()),
|
||||
}),
|
||||
elasticsearchUser: schema.object({
|
||||
username: schema.string(),
|
||||
email: schema.string(),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/role_mappings/upsert_single_user_role_mapping',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export const registerRoleMappingsRoutes = (dependencies: RouteDependencies) => {
|
||||
registerOrgEnableRoleMappingsRoute(dependencies);
|
||||
registerOrgRoleMappingsRoute(dependencies);
|
||||
registerOrgRoleMappingRoute(dependencies);
|
||||
registerOrgUserRoute(dependencies);
|
||||
};
|
|
@ -1,107 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import { registerSecurityRoute, registerSecuritySourceRestrictionsRoute } from './security';
|
||||
|
||||
describe('security routes', () => {
|
||||
describe('GET /internal/workplace_search/org/security', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/workplace_search/org/security',
|
||||
});
|
||||
|
||||
registerSecurityRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', async () => {
|
||||
await mockRouter.callRoute({});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/security',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /internal/workplace_search/org/security/source_restrictions', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/workplace_search/org/security/source_restrictions',
|
||||
});
|
||||
|
||||
registerSecuritySourceRestrictionsRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', async () => {
|
||||
await mockRouter.callRoute({});
|
||||
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/security/source_restrictions',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PATCH /internal/workplace_search/org/security/source_restrictions', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
mockRouter = new MockRouter({
|
||||
method: 'patch',
|
||||
path: '/internal/workplace_search/org/security/source_restrictions',
|
||||
});
|
||||
|
||||
registerSecuritySourceRestrictionsRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/security/source_restrictions',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
isEnabled: true,
|
||||
remote: {
|
||||
isEnabled: true,
|
||||
contentSources: [{ id: 'gmail', name: 'Gmail', isEnabled: true }],
|
||||
},
|
||||
standard: {
|
||||
isEnabled: false,
|
||||
contentSources: [{ id: 'dropbox', name: 'Dropbox', isEnabled: false }],
|
||||
},
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
export function registerSecurityRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/workplace_search/org/security',
|
||||
validate: false,
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/security',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerSecuritySourceRestrictionsRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/workplace_search/org/security/source_restrictions',
|
||||
validate: false,
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/security/source_restrictions',
|
||||
})
|
||||
);
|
||||
|
||||
router.patch(
|
||||
{
|
||||
path: '/internal/workplace_search/org/security/source_restrictions',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
isEnabled: schema.boolean(),
|
||||
remote: schema.object({
|
||||
isEnabled: schema.boolean(),
|
||||
contentSources: schema.arrayOf(
|
||||
schema.object({
|
||||
isEnabled: schema.boolean(),
|
||||
id: schema.string(),
|
||||
name: schema.string(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
standard: schema.object({
|
||||
isEnabled: schema.boolean(),
|
||||
contentSources: schema.arrayOf(
|
||||
schema.object({
|
||||
isEnabled: schema.boolean(),
|
||||
id: schema.string(),
|
||||
name: schema.string(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/security/source_restrictions',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export const registerSecurityRoutes = (dependencies: RouteDependencies) => {
|
||||
registerSecurityRoute(dependencies);
|
||||
registerSecuritySourceRestrictionsRoute(dependencies);
|
||||
};
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
|
||||
|
||||
import {
|
||||
registerOrgSettingsRoute,
|
||||
registerOrgSettingsCustomizeRoute,
|
||||
registerOrgSettingsUploadImagesRoute,
|
||||
registerOrgSettingsOauthApplicationRoute,
|
||||
} from './settings';
|
||||
|
||||
describe('settings routes', () => {
|
||||
describe('GET /internal/workplace_search/org/settings', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'get',
|
||||
path: '/internal/workplace_search/org/settings',
|
||||
});
|
||||
|
||||
registerOrgSettingsRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/settings',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/workplace_search/org/settings/customize', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/workplace_search/org/settings/customize',
|
||||
});
|
||||
|
||||
registerOrgSettingsCustomizeRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/settings/customize',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = { body: { name: 'foo' } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/workplace_search/org/settings/upload_images', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/workplace_search/org/settings/upload_images',
|
||||
});
|
||||
|
||||
registerOrgSettingsUploadImagesRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/settings/upload_images',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = { body: { logo: 'foo', icon: null } };
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /internal/workplace_search/org/settings/oauth_application', () => {
|
||||
let mockRouter: MockRouter;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockRouter = new MockRouter({
|
||||
method: 'put',
|
||||
path: '/internal/workplace_search/org/settings/oauth_application',
|
||||
});
|
||||
|
||||
registerOrgSettingsOauthApplicationRoute({
|
||||
...mockDependencies,
|
||||
router: mockRouter.router,
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a request handler', () => {
|
||||
expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
|
||||
path: '/ws/org/settings/oauth_application',
|
||||
});
|
||||
});
|
||||
|
||||
describe('validates', () => {
|
||||
it('correctly', () => {
|
||||
const request = {
|
||||
body: {
|
||||
oauth_application: {
|
||||
name: 'foo',
|
||||
confidential: true,
|
||||
redirect_uri: 'http://foo.bar',
|
||||
},
|
||||
},
|
||||
};
|
||||
mockRouter.shouldValidate(request);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,101 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
||||
import { RouteDependencies } from '../../plugin';
|
||||
|
||||
const MAX_IMAGE_BYTES = 2000000;
|
||||
|
||||
export function registerOrgSettingsRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.get(
|
||||
{
|
||||
path: '/internal/workplace_search/org/settings',
|
||||
validate: false,
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/settings',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerOrgSettingsCustomizeRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/workplace_search/org/settings/customize',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
name: schema.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/settings/customize',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerOrgSettingsUploadImagesRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/workplace_search/org/settings/upload_images',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
logo: schema.maybe(schema.nullable(schema.string())),
|
||||
icon: schema.maybe(schema.nullable(schema.string())),
|
||||
}),
|
||||
},
|
||||
options: {
|
||||
body: {
|
||||
maxBytes: MAX_IMAGE_BYTES,
|
||||
},
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/settings/upload_images',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function registerOrgSettingsOauthApplicationRoute({
|
||||
router,
|
||||
enterpriseSearchRequestHandler,
|
||||
}: RouteDependencies) {
|
||||
router.put(
|
||||
{
|
||||
path: '/internal/workplace_search/org/settings/oauth_application',
|
||||
validate: {
|
||||
body: schema.object({
|
||||
oauth_application: schema.object({
|
||||
name: schema.string(),
|
||||
confidential: schema.boolean(),
|
||||
redirect_uri: schema.string(),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
enterpriseSearchRequestHandler.createRequest({
|
||||
path: '/ws/org/settings/oauth_application',
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export const registerSettingsRoutes = (dependencies: RouteDependencies) => {
|
||||
registerOrgSettingsRoute(dependencies);
|
||||
registerOrgSettingsCustomizeRoute(dependencies);
|
||||
registerOrgSettingsUploadImagesRoute(dependencies);
|
||||
registerOrgSettingsOauthApplicationRoute(dependencies);
|
||||
};
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue