Skip to content

Commit

Permalink
(will be reverted) explicitly await for license to be ready in the au…
Browse files Browse the repository at this point in the history
…th hook
  • Loading branch information
pgayvallet committed Jan 29, 2021
1 parent d3a24d0 commit fdf73fe
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/security/common/licensing/index.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SecurityLicense, SecurityLicenseFeatures } from '.';

export const licenseMock = {
create: (features?: Partial<SecurityLicenseFeatures>): jest.Mocked<SecurityLicense> => ({
license$: {} as any,
isLicenseAvailable: jest.fn().mockReturnValue(true),
isEnabled: jest.fn().mockReturnValue(true),
getType: jest.fn().mockReturnValue('basic'),
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/security/common/licensing/license_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface SecurityLicense {
isEnabled(): boolean;
getType(): LicenseType | undefined;
getFeatures(): SecurityLicenseFeatures;
license$: Observable<ILicense>;
features$: Observable<SecurityLicenseFeatures>;
}

Expand All @@ -28,11 +29,15 @@ export class SecurityLicenseService {
let rawLicense: Readonly<ILicense> | undefined;

this.licenseSubscription = license$.subscribe((nextRawLicense) => {
// eslint-disable-next-line no-console
console.log('***** NEXT RAW LICENSE');
rawLicense = nextRawLicense;
});

return {
license: Object.freeze({
license$,

isLicenseAvailable: () => rawLicense?.isAvailable ?? false,

isEnabled: () => this.isSecurityEnabledFromRawLicense(rawLicense),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { take } from 'rxjs/operators';
import type { PublicMethodsOf } from '@kbn/utility-types';
import type {
LoggerFactory,
Expand Down Expand Up @@ -66,6 +67,10 @@ export class AuthenticationService {
this.license = license;

http.registerAuth(async (request, response, t) => {
await license.license$.pipe(take(1)).toPromise();
// eslint-disable-next-line no-console
console.log('***** AWAIT REGISTER AUTH COMPLETE');

if (!license.isLicenseAvailable()) {
this.logger.error('License is not available, authentication is not possible.');
return response.customError({
Expand Down

0 comments on commit fdf73fe

Please sign in to comment.