Skip to content

Commit

Permalink
Rename domain check.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Nov 21, 2019
1 parent 2facdf7 commit 3282719
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/uptime/server/lib/compose/kibana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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),
Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,38 @@
* 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();
});

it('throws for inactive license', () => {
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);
});
});
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/uptime/server/lib/domains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/uptime/server/lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { UMLicenseCheck } from './domains';

export interface UMDomainLibs {
auth: UMLicenseCheck;
license: UMLicenseCheck;
monitors: UMMonitorsAdapter;
monitorStates: UMMonitorStatesAdapter;
pings: UMPingsAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 3282719

Please sign in to comment.