[AAE-9094] - Fix app breaking when configured with BASIC auth (#7672)

This commit is contained in:
Ardit Domi 2022-06-12 22:32:40 +01:00 committed by GitHub
parent 1b20e17ed7
commit 81e58ecfb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -92,6 +92,7 @@ describe('UserAccessService', () => {
beforeEach(() => {
spyOn(jwtHelperService, 'getValueFromLocalToken').and.returnValue(undefined);
getAccessFromApiSpy = spyOn(oauth2Service, 'get').and.returnValue(of(userAccessMock));
appConfigService.config.authType = 'OAUTH';
});
it('should return true when the user has one of the global roles', async () => {
@ -137,5 +138,12 @@ describe('UserAccessService', () => {
expect(getAccessFromApiSpy).toHaveBeenCalledWith({ url: `${ fakeIdentityHost }/v1/identity/roles` });
});
it('should not fetch the access from the API if is not configured with OAUTH', async () => {
appConfigService.config.authType = 'BASIC';
await userAccessService.fetchUserAccess();
expect(getAccessFromApiSpy).not.toHaveBeenCalled();
});
});
});

View File

@ -36,7 +36,11 @@ export class UserAccessService {
async fetchUserAccess() {
if (!this.hasFetchedAccess()) {
this.hasRolesInJwt() ? this.fetchAccessFromJwt() : await this.fetchAccessFromApi();
if (this.hasRolesInJwt()) {
this.fetchAccessFromJwt();
} else if (this.isOauth()) {
await this.fetchAccessFromApi();
}
}
}
@ -67,6 +71,10 @@ export class UserAccessService {
return `${this.appConfigService.get('identityHost')}`;
}
private isOauth(): boolean {
return this.appConfigService.get('authType') === 'OAUTH';
}
/**
* Checks for global roles access.
*