From 621cc360a9c72362a5705312a2a69159b63b2a45 Mon Sep 17 00:00:00 2001 From: "Christiane (Tina) Heiligers" Date: Thu, 7 Nov 2024 11:53:42 -0700 Subject: [PATCH] Asserts deprecation config passes to router args --- .../src/routes/index.ts | 8 ---- .../allow_api_access/bulk_create.test.ts | 10 +---- .../allow_api_access/bulk_delete.test.ts | 10 +---- .../routes/allow_api_access/bulk_get.test.ts | 10 +---- .../allow_api_access/bulk_resolve.test.ts | 10 +---- .../allow_api_access/bulk_update.test.ts | 10 +---- .../routes/allow_api_access/create.test.ts | 10 +---- .../routes/allow_api_access/delete.test.ts | 10 +---- .../routes/allow_api_access/find.test.ts | 10 +---- .../routes/allow_api_access/get.test.ts | 10 +---- .../routes/allow_api_access/resolve.test.ts | 10 +---- .../routes/allow_api_access/update.test.ts | 10 +---- .../saved_objects/routes/bulk_create.test.ts | 32 ++++++++++---- .../saved_objects/routes/bulk_delete.test.ts | 29 +++++++++---- .../saved_objects/routes/bulk_get.test.ts | 28 ++++++++---- .../saved_objects/routes/bulk_resolve.test.ts | 27 ++++++++---- .../saved_objects/routes/bulk_update.test.ts | 43 +++++++++++++++---- .../saved_objects/routes/create.test.ts | 27 ++++++++---- .../saved_objects/routes/delete.test.ts | 21 +++++---- .../saved_objects/routes/find.test.ts | 22 ++++++---- .../saved_objects/routes/get.test.ts | 22 ++++++---- .../legacy_import_export/export.test.ts | 11 ++--- .../legacy_import_export/import.test.ts | 11 ++--- .../saved_objects/routes/resolve.test.ts | 23 ++++++---- .../saved_objects/routes/routes_test_utils.ts | 16 +++++++ .../saved_objects/routes/update.test.ts | 22 ++++++---- 26 files changed, 251 insertions(+), 201 deletions(-) diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/index.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/index.ts index 31a7e6f526491..a9a83d55a0daa 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/index.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/index.ts @@ -36,14 +36,6 @@ import { registerLegacyExportRoute } from './legacy_import_export/export'; import { registerBulkResolveRoute } from './bulk_resolve'; import { registerDeleteUnknownTypesRoute } from './deprecations'; -// export interface RouteDeprecationInfo { -// documentationUrl: string; -// severity: 'warning'; -// reason: { -// type: 'deprecate' | 'remove'; -// }; -// } - export function registerRoutes({ http, coreUsageData, diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_create.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_create.test.ts index 9d80ca8b78fb8..e824e5124f6c6 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_create.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_create.test.ts @@ -21,7 +21,7 @@ import { } from '@kbn/core-saved-objects-server-internal'; import { createHiddenTypeVariants, setupServer } from '@kbn/core-test-helpers-test-utils'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -56,13 +56,7 @@ describe('POST /api/saved_objects/_bulk_create with allowApiAccess true', () => const logger = loggerMock.create(); const config = setupConfig(true); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerBulkCreateRoute(router, { config, coreUsageData, diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_delete.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_delete.test.ts index cf9d331197022..114b682fa51b4 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_delete.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_delete.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -60,13 +60,7 @@ describe('POST /api/saved_objects/_bulk_delete with allowApiAccess as true', () const config = setupConfig(true); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerBulkDeleteRoute(router, { config, coreUsageData, diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_get.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_get.test.ts index e4694c260b4eb..bd6caca6233c8 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_get.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_get.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -58,13 +58,7 @@ describe('POST /api/saved_objects/_bulk_get with allowApiAccess true', () => { const config = setupConfig(true); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerBulkGetRoute(router, { config, coreUsageData, diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_resolve.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_resolve.test.ts index e64858cf24a71..f297f1b6a8cb4 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_resolve.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_resolve.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -59,13 +59,7 @@ describe('POST /api/saved_objects/_bulk_resolve with allowApiAccess true', () => const config = setupConfig(true); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerBulkResolveRoute(router, { config, coreUsageData, diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_update.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_update.test.ts index 84cdbdc269167..7625334bbe638 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_update.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/bulk_update.test.ts @@ -19,7 +19,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; const testTypes = [ @@ -52,13 +52,7 @@ describe('PUT /api/saved_objects/_bulk_update with allowApiAccess true', () => { const config = setupConfig(true); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerBulkUpdateRoute(router, { config, coreUsageData, diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/create.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/create.test.ts index f0a64ba2ca7d4..632b41fe886b2 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/create.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/create.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -58,13 +58,7 @@ describe('POST /api/saved_objects/{type} with allowApiAccess true', () => { const logger = loggerMock.create(); const config = setupConfig(true); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerCreateRoute(router, { config, coreUsageData, diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/delete.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/delete.test.ts index 3c21268c3baf3..a1f3ff0bc60ec 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/delete.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/delete.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -55,13 +55,7 @@ describe('DELETE /api/saved_objects/{type}/{id} with allowApiAccess true', () => const logger = loggerMock.create(); const config = setupConfig(true); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerDeleteRoute(router, { config, coreUsageData, diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/find.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/find.test.ts index ada7a31aecca0..c87546ea4887a 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/find.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/find.test.ts @@ -21,7 +21,7 @@ import { registerFindRoute, type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -71,13 +71,7 @@ describe('GET /api/saved_objects/_find with allowApiAccess true', () => { const config = setupConfig(true); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerFindRoute(router, { config, coreUsageData, diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/get.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/get.test.ts index 8d0da5990bfbb..6220de6540685 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/get.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/get.test.ts @@ -25,7 +25,7 @@ import { } from '@kbn/core-saved-objects-server-internal'; import { createHiddenTypeVariants } from '@kbn/core-test-helpers-test-utils'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; const coreId = Symbol('core'); const testTypes = [ @@ -80,13 +80,7 @@ describe('GET /api/saved_objects/{type}/{id} with allowApiAccess true', () => { const config = setupConfig(true); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerGetRoute(router, { config, coreUsageData, diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/resolve.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/resolve.test.ts index 25b3c551e293a..f1f7fd1d6153e 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/resolve.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/resolve.test.ts @@ -25,7 +25,7 @@ import { } from '@kbn/core-saved-objects-server-internal'; import { createHiddenTypeVariants } from '@kbn/core-test-helpers-test-utils'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; const coreId = Symbol('core'); @@ -80,13 +80,7 @@ describe('GET /api/saved_objects/resolve/{type}/{id} with allowApiAccess true', const config = setupConfig(true); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerResolveRoute(router, { config, coreUsageData, diff --git a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/update.test.ts b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/update.test.ts index e4fceb5a0c5c5..2a086f29d75d1 100644 --- a/src/core/server/integration_tests/saved_objects/routes/allow_api_access/update.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/allow_api_access/update.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from '../routes_test_utils'; +import { deprecationMock, setupConfig } from '../routes_test_utils'; type SetupServerReturn = Awaited>; @@ -56,13 +56,7 @@ describe('PUT /api/saved_objects/{type}/{id?} with allowApiAccess true', () => { const config = setupConfig(true); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerUpdateRoute(router, { config, coreUsageData, diff --git a/src/core/server/integration_tests/saved_objects/routes/bulk_create.test.ts b/src/core/server/integration_tests/saved_objects/routes/bulk_create.test.ts index f464738679944..033a5570c588a 100644 --- a/src/core/server/integration_tests/saved_objects/routes/bulk_create.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/bulk_create.test.ts @@ -21,7 +21,7 @@ import { } from '@kbn/core-saved-objects-server-internal'; import { createHiddenTypeVariants, setupServer } from '@kbn/core-test-helpers-test-utils'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -37,6 +37,7 @@ describe('POST /api/saved_objects/_bulk_create', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { ({ server, httpSetup, handlerContext } = await setupServer()); @@ -57,16 +58,11 @@ describe('POST /api/saved_objects/_bulk_create', () => { const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'post'); const config = setupConfig(); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerBulkCreateRoute(router, { config, coreUsageData, @@ -206,4 +202,24 @@ describe('POST /api/saved_objects/_bulk_create', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation config to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .post('/api/saved_objects/_bulk_create') + .set('x-elastic-internal-origin', 'kibana') + .send([ + { + id: 'abc1234', + type: 'index-pattern', + attributes: { + title: 'foo', + }, + references: [], + }, + ]) + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/bulk_delete.test.ts b/src/core/server/integration_tests/saved_objects/routes/bulk_delete.test.ts index f754078650394..9421d5207b211 100644 --- a/src/core/server/integration_tests/saved_objects/routes/bulk_delete.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/bulk_delete.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -36,6 +36,7 @@ describe('POST /api/saved_objects/_bulk_delete', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { ({ server, httpSetup, handlerContext } = await setupServer()); @@ -59,16 +60,11 @@ describe('POST /api/saved_objects/_bulk_delete', () => { const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'post'); const config = setupConfig(); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerBulkDeleteRoute(router, { config, coreUsageData, @@ -175,4 +171,21 @@ describe('POST /api/saved_objects/_bulk_delete', () => { .expect(400); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .post('/api/saved_objects/_bulk_delete') + .set('x-elastic-internal-origin', 'kibana') + .send([ + { + id: 'hiddenID', + type: 'hidden-from-http', + }, + ]) + .expect(400); + + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/bulk_get.test.ts b/src/core/server/integration_tests/saved_objects/routes/bulk_get.test.ts index cfd06d3f8da5f..8d16ca5787350 100644 --- a/src/core/server/integration_tests/saved_objects/routes/bulk_get.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/bulk_get.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -36,6 +36,7 @@ describe('POST /api/saved_objects/_bulk_get', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { ({ server, httpSetup, handlerContext } = await setupServer()); @@ -57,16 +58,11 @@ describe('POST /api/saved_objects/_bulk_get', () => { const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'post'); const config = setupConfig(); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerBulkGetRoute(router, { config, coreUsageData, @@ -162,4 +158,20 @@ describe('POST /api/saved_objects/_bulk_get', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation config to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .post('/api/saved_objects/_bulk_get') + .set('x-elastic-internal-origin', 'kibana') + .send([ + { + id: 'abc123', + type: 'index-pattern', + }, + ]) + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/bulk_resolve.test.ts b/src/core/server/integration_tests/saved_objects/routes/bulk_resolve.test.ts index 450bd26c85d81..800fccb00324d 100644 --- a/src/core/server/integration_tests/saved_objects/routes/bulk_resolve.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/bulk_resolve.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -36,6 +36,7 @@ describe('POST /api/saved_objects/_bulk_resolve', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { ({ server, httpSetup, handlerContext } = await setupServer()); @@ -58,16 +59,10 @@ describe('POST /api/saved_objects/_bulk_resolve', () => { const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'post'); const config = setupConfig(); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; registerBulkResolveRoute(router, { config, coreUsageData, @@ -166,4 +161,20 @@ describe('POST /api/saved_objects/_bulk_resolve', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .post('/api/saved_objects/_bulk_resolve') + .set('x-elastic-internal-origin', 'kibana') + .send([ + { + id: 'abc123', + type: 'index-pattern', + }, + ]) + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/bulk_update.test.ts b/src/core/server/integration_tests/saved_objects/routes/bulk_update.test.ts index 57ffa089c5404..d746d1d5b9ca8 100644 --- a/src/core/server/integration_tests/saved_objects/routes/bulk_update.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/bulk_update.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; const testTypes = [ @@ -37,6 +37,7 @@ describe('PUT /api/saved_objects/_bulk_update', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { ({ server, httpSetup, handlerContext } = await setupServer()); @@ -56,16 +57,11 @@ describe('PUT /api/saved_objects/_bulk_update', () => { const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'put'); const config = setupConfig(); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerBulkUpdateRoute(router, { config, coreUsageData, @@ -192,6 +188,7 @@ describe('PUT /api/saved_objects/_bulk_update', () => { }, ]) .expect(400); + expect(result.body.message).toContain('Unsupported saved object type(s):'); }); @@ -217,5 +214,35 @@ describe('PUT /api/saved_objects/_bulk_update', () => { ]) .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .put('/api/saved_objects/_bulk_update') + .set('x-elastic-internal-origin', 'kibana') + .send([ + { + type: 'visualization', + id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab', + attributes: { + title: 'An existing visualization', + }, + }, + { + type: 'dashboard', + id: 'be3733a0-9efe-11e7-acb3-3dab96693fab', + attributes: { + title: 'An existing dashboard', + }, + }, + ]) + .expect(200); + + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/create.test.ts b/src/core/server/integration_tests/saved_objects/routes/create.test.ts index 613c84285b44f..f2471e14fc128 100644 --- a/src/core/server/integration_tests/saved_objects/routes/create.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/create.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -36,6 +36,7 @@ describe('POST /api/saved_objects/{type}', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; const clientResponse = { id: 'logstash-*', @@ -58,15 +59,10 @@ describe('POST /api/saved_objects/{type}', () => { const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'post'); + const config = setupConfig(); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; registerCreateRoute(router, { config, @@ -191,4 +187,19 @@ describe('POST /api/saved_objects/{type}', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .post('/api/saved_objects/index-pattern') + .set('x-elastic-internal-origin', 'kibana') + .send({ + attributes: { + title: 'Logging test', + }, + }) + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/delete.test.ts b/src/core/server/integration_tests/saved_objects/routes/delete.test.ts index 46f1f24ffd345..70d811cd97521 100644 --- a/src/core/server/integration_tests/saved_objects/routes/delete.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/delete.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -37,6 +37,7 @@ describe('DELETE /api/saved_objects/{type}/{id}', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { ({ server, httpSetup, handlerContext } = await setupServer()); @@ -55,15 +56,10 @@ describe('DELETE /api/saved_objects/{type}/{id}', () => { const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'delete'); + const config = setupConfig(); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; registerDeleteRoute(router, { config, coreUsageData, @@ -133,4 +129,13 @@ describe('DELETE /api/saved_objects/{type}/{id}', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .delete('/api/saved_objects/index-pattern/logstash-*') + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/find.test.ts b/src/core/server/integration_tests/saved_objects/routes/find.test.ts index 02ae2cec1beb4..d2048ba13b634 100644 --- a/src/core/server/integration_tests/saved_objects/routes/find.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/find.test.ts @@ -22,7 +22,7 @@ import { registerFindRoute, type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -42,6 +42,7 @@ describe('GET /api/saved_objects/_find', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; const clientResponse = { total: 0, @@ -71,18 +72,11 @@ describe('GET /api/saved_objects/_find', () => { const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'get'); const config = setupConfig(); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; - registerFindRoute(router, { config, coreUsageData, @@ -485,4 +479,14 @@ describe('GET /api/saved_objects/_find', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .get('/api/saved_objects/_find?type=foo&type=bar') + .set('x-elastic-internal-origin', 'kibana') + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/get.test.ts b/src/core/server/integration_tests/saved_objects/routes/get.test.ts index 1919c27cab520..bb748ca478e8a 100644 --- a/src/core/server/integration_tests/saved_objects/routes/get.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/get.test.ts @@ -25,7 +25,7 @@ import { } from '@kbn/core-saved-objects-server-internal'; import { createHiddenTypeVariants } from '@kbn/core-test-helpers-test-utils'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; const coreId = Symbol('core'); const testTypes = [ @@ -41,6 +41,7 @@ describe('GET /api/saved_objects/{type}/{id}', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { const coreContext = createCoreContext({ coreId }); @@ -80,15 +81,10 @@ describe('GET /api/saved_objects/{type}/{id}', () => { const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'get'); + const config = setupConfig(); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; registerGetRoute(router, { config, @@ -157,4 +153,14 @@ describe('GET /api/saved_objects/{type}/{id}', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .get('/api/saved_objects/index-pattern/logstash-*') + .set('x-elastic-internal-origin', 'kibana') + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/export.test.ts b/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/export.test.ts index 030d41b2dfd6f..73f1ce075272c 100644 --- a/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/export.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/export.test.ts @@ -41,6 +41,7 @@ import { registerLegacyExportRoute, type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; +import { legacyDeprecationMock } from '../routes_test_utils'; type SetupServerReturn = Awaited>; let coreUsageStatsClient: jest.Mocked; @@ -58,19 +59,13 @@ describe('POST /api/dashboards/export', () => { coreUsageStatsClient = coreUsageStatsClientMock.create(); coreUsageStatsClient.incrementLegacyDashboardsExport.mockRejectedValue(new Error('Oh no!')); // intentionally throw this error, which is swallowed, so we can assert that the operation does not fail const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'remove' as const, - }, - }; + registerLegacyExportRoute(router, { kibanaVersion: 'mockversion', coreUsageData, logger: loggerMock.create(), access: 'public', - legacyDeprecationInfo: deprecationMock, + legacyDeprecationInfo: legacyDeprecationMock, }); handlerContext.savedObjects.client.bulkGet diff --git a/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/import.test.ts b/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/import.test.ts index 7489ebcb6c780..c96c0e1d9011a 100644 --- a/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/import.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/legacy_import_export/import.test.ts @@ -41,6 +41,7 @@ import { registerLegacyImportRoute, type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; +import { legacyDeprecationMock } from '../routes_test_utils'; type SetupServerReturn = Awaited>; let coreUsageStatsClient: jest.Mocked; @@ -58,19 +59,13 @@ describe('POST /api/dashboards/import', () => { coreUsageStatsClient = coreUsageStatsClientMock.create(); coreUsageStatsClient.incrementLegacyDashboardsImport.mockRejectedValue(new Error('Oh no!')); // intentionally throw this error, which is swallowed, so we can assert that the operation does not fail const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'remove' as const, - }, - }; + registerLegacyImportRoute(router, { maxImportPayloadBytes: 26214400, coreUsageData, logger: loggerMock.create(), access: 'public', - legacyDeprecationInfo: deprecationMock, + legacyDeprecationInfo: legacyDeprecationMock, }); handlerContext.savedObjects.client.bulkCreate.mockResolvedValueOnce({ diff --git a/src/core/server/integration_tests/saved_objects/routes/resolve.test.ts b/src/core/server/integration_tests/saved_objects/routes/resolve.test.ts index d4119c238c268..7812081e5329c 100644 --- a/src/core/server/integration_tests/saved_objects/routes/resolve.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/resolve.test.ts @@ -25,7 +25,7 @@ import { } from '@kbn/core-saved-objects-server-internal'; import { createHiddenTypeVariants } from '@kbn/core-test-helpers-test-utils'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; const coreId = Symbol('core'); @@ -42,6 +42,7 @@ describe('GET /api/saved_objects/resolve/{type}/{id}', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { const coreContext = createCoreContext({ coreId }); @@ -79,15 +80,11 @@ describe('GET /api/saved_objects/resolve/{type}/{id}', () => { const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'get'); + const config = setupConfig(); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; + registerResolveRoute(router, { config, coreUsageData, @@ -154,4 +151,14 @@ describe('GET /api/saved_objects/resolve/{type}/{id}', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .get('/api/saved_objects/resolve/index-pattern/logstash-*') + .set('x-elastic-internal-origin', 'kibana') + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); }); diff --git a/src/core/server/integration_tests/saved_objects/routes/routes_test_utils.ts b/src/core/server/integration_tests/saved_objects/routes/routes_test_utils.ts index b27b2b72aba97..3c78b4e7f0e3b 100644 --- a/src/core/server/integration_tests/saved_objects/routes/routes_test_utils.ts +++ b/src/core/server/integration_tests/saved_objects/routes/routes_test_utils.ts @@ -15,3 +15,19 @@ export function setupConfig(allowAccess: boolean = false) { } as SavedObjectConfig; return config; } + +export const deprecationMock = { + documentationUrl: 'http://elastic.co', + severity: 'warning' as const, + reason: { + type: 'deprecate' as const, + }, +}; + +export const legacyDeprecationMock = { + documentationUrl: 'http://elastic.co', + severity: 'warning' as const, + reason: { + type: 'remove' as const, + }, +}; diff --git a/src/core/server/integration_tests/saved_objects/routes/update.test.ts b/src/core/server/integration_tests/saved_objects/routes/update.test.ts index 2523e0741f8d2..909121429aefb 100644 --- a/src/core/server/integration_tests/saved_objects/routes/update.test.ts +++ b/src/core/server/integration_tests/saved_objects/routes/update.test.ts @@ -20,7 +20,7 @@ import { type InternalSavedObjectsRequestHandlerContext, } from '@kbn/core-saved-objects-server-internal'; import { loggerMock } from '@kbn/logging-mocks'; -import { setupConfig } from './routes_test_utils'; +import { deprecationMock, setupConfig } from './routes_test_utils'; type SetupServerReturn = Awaited>; @@ -37,6 +37,7 @@ describe('PUT /api/saved_objects/{type}/{id?}', () => { let savedObjectsClient: ReturnType; let coreUsageStatsClient: jest.Mocked; let loggerWarnSpy: jest.SpyInstance; + let registrationSpy: jest.SpyInstance; beforeEach(async () => { const clientResponse = { @@ -66,16 +67,10 @@ describe('PUT /api/saved_objects/{type}/{id?}', () => { const coreUsageData = coreUsageDataServiceMock.createSetupContract(coreUsageStatsClient); const logger = loggerMock.create(); loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation(); + registrationSpy = jest.spyOn(router, 'put'); const config = setupConfig(); const access = 'public'; - const deprecationMock = { - documentationUrl: 'http://elastic.co', - severity: 'warning' as const, - reason: { - type: 'deprecate' as const, - }, - }; registerUpdateRoute(router, { config, coreUsageData, @@ -158,4 +153,15 @@ describe('PUT /api/saved_objects/{type}/{id?}', () => { .expect(200); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); }); + + it('passes deprecation configuration to the router arguments', async () => { + await supertest(httpSetup.server.listener) + .put('/api/saved_objects/index-pattern/logstash-*') + .set('x-elastic-internal-origin', 'kibana') + .send({ attributes: { title: 'Logging test' }, version: 'log' }) + .expect(200); + expect(registrationSpy.mock.calls[0][0]).toMatchObject({ + options: { deprecated: deprecationMock }, + }); + }); });