[AAE-18459] Fix invalidateSession is called when auth is not initilized by js-api (#9152)

* [AAE-18459] Replace all placeholders if the configuration key is an object

* [AAE-18459] don't invalidate session if authentication is not handled by js-api
This commit is contained in:
Amedeo Lepore
2023-12-14 19:51:10 +01:00
committed by GitHub
parent 1f5af31ad0
commit 0932a3ed10
3 changed files with 20 additions and 4 deletions

View File

@@ -198,4 +198,20 @@ describe('AppConfigService', () => {
expect(fakeCallBack).toHaveBeenCalled();
});
it('should replace all the configuration placeholders if the provided key is an object', () => {
appConfigService.config.objectKey = {
firstUrl: '{protocol}//{hostname}{:port}',
secondUrl: '{protocol}//{hostname}{:port}',
thirdUrl: '{protocol}//{hostname}{:port}'
};
spyOn(appConfigService, 'getLocationHostname').and.returnValue('localhost');
spyOn(appConfigService, 'getLocationPort').and.returnValue(':8080');
spyOn(appConfigService, 'getLocationProtocol').and.returnValue('http:');
expect(appConfigService.get<any>('objectKey').firstUrl).toEqual('http://localhost:8080');
expect(appConfigService.get<any>('objectKey').secondUrl).toEqual('http://localhost:8080');
expect(appConfigService.get<any>('objectKey').thirdUrl).toEqual('http://localhost:8080');
});
});

View File

@@ -123,9 +123,9 @@ export class AppConfigService {
}
if (typeof result === 'object') {
result = JSON.parse(JSON.stringify(result).replace('{hostname}', this.getLocationHostname()));
result = JSON.parse(JSON.stringify(result).replace('{:port}', this.getLocationPort(':')));
result = JSON.parse(JSON.stringify(result).replace('{protocol}', this.getLocationProtocol()));
result = JSON.parse(JSON.stringify(result).replace(/{hostname}/g, this.getLocationHostname()));
result = JSON.parse(JSON.stringify(result).replace(/{:port}/g, this.getLocationPort(':')));
result = JSON.parse(JSON.stringify(result).replace(/{protocol}/g, this.getLocationProtocol()));
}
if (result === undefined) {

View File

@@ -207,7 +207,7 @@ export class AlfrescoApi implements Emitter, AlfrescoApiType {
/**@private? */
errorHandler(error: { status?: number }) {
if (error.status === 401) {
if (this.config.oauthInit && error.status === 401) {
this.invalidateSession();
}