(will be reverted) explicitly await for license to be ready in the auth hook

This commit is contained in:
pgayvallet 2021-01-29 15:54:00 +01:00
parent d3a24d0cc7
commit fdf73feb0a
3 changed files with 11 additions and 0 deletions

View file

@ -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'),

View file

@ -14,6 +14,7 @@ export interface SecurityLicense {
isEnabled(): boolean;
getType(): LicenseType | undefined;
getFeatures(): SecurityLicenseFeatures;
license$: Observable<ILicense>;
features$: Observable<SecurityLicenseFeatures>;
}
@ -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),

View file

@ -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,
@ -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({