From 3282719c4154f0abb0b74852ed4d29f83f9ed596 Mon Sep 17 00:00:00 2001 From: Justin Kambic Date: Thu, 21 Nov 2019 15:47:03 -0500 Subject: [PATCH] Rename domain check. --- .../plugins/uptime/server/lib/compose/kibana.ts | 4 ++-- .../__tests__/__snapshots__/auth.test.ts.snap | 7 ------- .../__tests__/__snapshots__/license.test.ts.snap | 7 +++++++ .../__tests__/{auth.test.ts => license.test.ts} | 12 ++++++------ .../plugins/uptime/server/lib/domains/index.ts | 2 +- .../server/lib/domains/{auth.ts => license.ts} | 2 +- x-pack/legacy/plugins/uptime/server/lib/lib.ts | 2 +- .../uptime/server/rest_api/create_route_with_auth.ts | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) delete mode 100644 x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/__snapshots__/auth.test.ts.snap create mode 100644 x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/__snapshots__/license.test.ts.snap rename x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/{auth.test.ts => license.test.ts} (73%) rename x-pack/legacy/plugins/uptime/server/lib/domains/{auth.ts => license.ts} (90%) diff --git a/x-pack/legacy/plugins/uptime/server/lib/compose/kibana.ts b/x-pack/legacy/plugins/uptime/server/lib/compose/kibana.ts index 7027a30bfce179f..a7c370e03490b1b 100644 --- a/x-pack/legacy/plugins/uptime/server/lib/compose/kibana.ts +++ b/x-pack/legacy/plugins/uptime/server/lib/compose/kibana.ts @@ -8,7 +8,7 @@ import { UMKibanaDatabaseAdapter } from '../adapters/database/kibana_database_ad import { UMKibanaBackendFrameworkAdapter } from '../adapters/framework'; import { ElasticsearchMonitorsAdapter } from '../adapters/monitors'; import { ElasticsearchPingsAdapter } from '../adapters/pings'; -import { authDomain } from '../domains'; +import { licenseCheck } from '../domains'; import { UMDomainLibs, UMServerLibs } from '../lib'; import { ElasticsearchMonitorStatesAdapter } from '../adapters/monitor_states'; import { UMKibanaSavedObjectsAdapter } from '../adapters/saved_objects/kibana_saved_objects_adapter'; @@ -20,7 +20,7 @@ export function compose(server: UptimeCoreSetup, plugins: UptimeCorePlugins): UM const database = new UMKibanaDatabaseAdapter(elasticsearch); const domainLibs: UMDomainLibs = { - auth: authDomain, + license: licenseCheck, monitors: new ElasticsearchMonitorsAdapter(database), monitorStates: new ElasticsearchMonitorStatesAdapter(database), pings: new ElasticsearchPingsAdapter(database), diff --git a/x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/__snapshots__/auth.test.ts.snap b/x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/__snapshots__/auth.test.ts.snap deleted file mode 100644 index d7454d0d9066c18..000000000000000 --- a/x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/__snapshots__/auth.test.ts.snap +++ /dev/null @@ -1,7 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`authDomain throws for inactive license 1`] = `"License not active"`; - -exports[`authDomain throws for null license 1`] = `"Missing license information"`; - -exports[`authDomain throws for unsupported license type 1`] = `"License not supported"`; diff --git a/x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/__snapshots__/license.test.ts.snap b/x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/__snapshots__/license.test.ts.snap new file mode 100644 index 000000000000000..07d437112e888d2 --- /dev/null +++ b/x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/__snapshots__/license.test.ts.snap @@ -0,0 +1,7 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`license check throws for inactive license 1`] = `"License not active"`; + +exports[`license check throws for null license 1`] = `"Missing license information"`; + +exports[`license check throws for unsupported license type 1`] = `"License not supported"`; diff --git a/x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/auth.test.ts b/x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/license.test.ts similarity index 73% rename from x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/auth.test.ts rename to x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/license.test.ts index 4b6b31300918817..73e70cb78626dad 100644 --- a/x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/auth.test.ts +++ b/x-pack/legacy/plugins/uptime/server/lib/domains/__tests__/license.test.ts @@ -4,24 +4,24 @@ * you may not use this file except in compliance with the Elastic License. */ -import { authDomain } from '../auth'; +import { licenseCheck } from '../license'; import { RequestHandlerContext } from 'kibana/server'; -describe('authDomain', () => { +describe('license check', () => { let mockContext: RequestHandlerContext; const isOneOf = jest.fn(); it('throws for null license', () => { // @ts-ignore there's a null check in this function mockContext = { licensing: { license: null } }; - expect(() => authDomain(mockContext)).toThrowErrorMatchingSnapshot(); + expect(() => licenseCheck(mockContext)).toThrowErrorMatchingSnapshot(); }); it('throws for unsupported license type', () => { isOneOf.mockReturnValue(false); expect(() => // @ts-ignore it needs to throw if the license is not supported - authDomain({ licensing: { license: { isOneOf } } }) + licenseCheck({ licensing: { license: { isOneOf } } }) ).toThrowErrorMatchingSnapshot(); }); @@ -29,13 +29,13 @@ describe('authDomain', () => { isOneOf.mockReturnValue(true); expect(() => // @ts-ignore it needs to throw if !isActive - authDomain({ licensing: { license: { isActive: false, isOneOf } } }) + licenseCheck({ licensing: { license: { isActive: false, isOneOf } } }) ).toThrowErrorMatchingSnapshot(); }); it('returns true for a valid license', () => { isOneOf.mockReturnValue(true); // @ts-ignore license type needs to be non-null - expect(authDomain({ licensing: { license: { isActive: true, isOneOf } } })).toBe(true); + expect(licenseCheck({ licensing: { license: { isActive: true, isOneOf } } })).toBe(true); }); }); diff --git a/x-pack/legacy/plugins/uptime/server/lib/domains/index.ts b/x-pack/legacy/plugins/uptime/server/lib/domains/index.ts index b2d7503a6a192c5..6a35b9b41020bbf 100644 --- a/x-pack/legacy/plugins/uptime/server/lib/domains/index.ts +++ b/x-pack/legacy/plugins/uptime/server/lib/domains/index.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export { authDomain, UMLicenseCheck } from './auth'; +export { licenseCheck, UMLicenseCheck } from './license'; diff --git a/x-pack/legacy/plugins/uptime/server/lib/domains/auth.ts b/x-pack/legacy/plugins/uptime/server/lib/domains/license.ts similarity index 90% rename from x-pack/legacy/plugins/uptime/server/lib/domains/auth.ts rename to x-pack/legacy/plugins/uptime/server/lib/domains/license.ts index e7edc6913ab0729..22bb30d42387d15 100644 --- a/x-pack/legacy/plugins/uptime/server/lib/domains/auth.ts +++ b/x-pack/legacy/plugins/uptime/server/lib/domains/license.ts @@ -9,7 +9,7 @@ import { RequestHandlerContext } from 'kibana/server'; export type UMLicenseCheck = (context: RequestHandlerContext) => boolean; -export const authDomain: UMLicenseCheck = ({ licensing: { license } }) => { +export const licenseCheck: UMLicenseCheck = ({ licensing: { license } }) => { if (license === null) { throw Boom.badRequest('Missing license information'); } diff --git a/x-pack/legacy/plugins/uptime/server/lib/lib.ts b/x-pack/legacy/plugins/uptime/server/lib/lib.ts index 9a6a8217d127891..e68a6dd18ef5f22 100644 --- a/x-pack/legacy/plugins/uptime/server/lib/lib.ts +++ b/x-pack/legacy/plugins/uptime/server/lib/lib.ts @@ -15,7 +15,7 @@ import { import { UMLicenseCheck } from './domains'; export interface UMDomainLibs { - auth: UMLicenseCheck; + license: UMLicenseCheck; monitors: UMMonitorsAdapter; monitorStates: UMMonitorStatesAdapter; pings: UMPingsAdapter; diff --git a/x-pack/legacy/plugins/uptime/server/rest_api/create_route_with_auth.ts b/x-pack/legacy/plugins/uptime/server/rest_api/create_route_with_auth.ts index 26ae3b454cfb89b..7fbae1d2091feee 100644 --- a/x-pack/legacy/plugins/uptime/server/rest_api/create_route_with_auth.ts +++ b/x-pack/legacy/plugins/uptime/server/rest_api/create_route_with_auth.ts @@ -20,7 +20,7 @@ export const createRouteWithAuth = ( request, response ) => { - if (libs.auth(context)) { + if (libs.license(context)) { return await handler(context, request, response); } return response.badRequest();