mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[MNT-24614] Fixed APS basic auth login issue with ADF (#10364)
* [MNT-24614] Fixed APS basic auth login issue with ADF * [MNT-24614] Addressed code review findings - Using includes api, and removed unneeded functions. Added missing return type to functions * [MNT-24614] Added unit tests * [MNT-24614] Added unit tests * [MNT-24614] Fixed casing of unit test titles
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { BasicAlfrescoAuthService } from './basic-alfresco-auth.service';
|
||||
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
|
||||
import { ProcessAuth } from './process-auth';
|
||||
import { ContentAuth } from './content-auth';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
|
||||
describe('BasicAlfrescoAuthService', () => {
|
||||
let basicAlfrescoAuthService: BasicAlfrescoAuthService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule],
|
||||
providers: [BasicAlfrescoAuthService]
|
||||
});
|
||||
basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService);
|
||||
spyOn(TestBed.inject(ProcessAuth), 'getToken').and.returnValue('Mock Process Auth ticket');
|
||||
spyOn(TestBed.inject(ContentAuth), 'getToken').and.returnValue('Mock Content Auth ticket');
|
||||
const appConfigSpy = spyOn(TestBed.inject(AppConfigService), 'get');
|
||||
appConfigSpy.withArgs(AppConfigValues.CONTEXTROOTBPM).and.returnValue('activiti-app');
|
||||
appConfigSpy.withArgs(AppConfigValues.CONTEXTROOTECM).and.returnValue('alfresco');
|
||||
});
|
||||
|
||||
it('should return content services ticket when requestUrl contains ECM context root', () => {
|
||||
const ticket = basicAlfrescoAuthService.getTicketEcmBase64('http://www.exmple.com/alfresco/mock-api-url');
|
||||
const base64Segment = ticket.split('Basic ')[1];
|
||||
expect(atob(base64Segment)).toEqual('Mock Content Auth ticket');
|
||||
});
|
||||
|
||||
it('should return process services ticket when requestUrl contains ECM context root', () => {
|
||||
const ticket = basicAlfrescoAuthService.getTicketEcmBase64('http://www.example.com/activiti-app/mock-api-url');
|
||||
expect(ticket).toEqual('Basic Mock Process Auth ticket');
|
||||
});
|
||||
|
||||
it('should return content services ticket when requestUrl contains both ECM and BPM context root, but ECM context root comes before', () => {
|
||||
const ticket = basicAlfrescoAuthService.getTicketEcmBase64('http://www.exmple.com/alfresco/activiti-app/mock-api-url');
|
||||
const base64Segment = ticket.split('Basic ')[1];
|
||||
expect(atob(base64Segment)).toEqual('Mock Content Auth ticket');
|
||||
});
|
||||
|
||||
it('should return process services ticket when requestUrl contains both ECM and BPM context root, but BPM context root comes before', () => {
|
||||
const ticket = basicAlfrescoAuthService.getTicketEcmBase64('http://www.example.com/activiti-app/alfresco/mock-api-url');
|
||||
expect(ticket).toEqual('Basic Mock Process Auth ticket');
|
||||
});
|
||||
});
|
@@ -373,15 +373,24 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService {
|
||||
getTicketEcmBase64(requestUrl: string): string | null {
|
||||
let ticket = null;
|
||||
|
||||
const contextRootBpm = this.appConfig.get<string>(AppConfigValues.CONTEXTROOTBPM) || 'activiti-app';
|
||||
const contextRoot = this.appConfig.get<string>(AppConfigValues.CONTEXTROOTECM) || 'alfresco';
|
||||
const bpmRoot = `/${this.appConfig.get<string>(AppConfigValues.CONTEXTROOTBPM) || 'activiti-app'}/`;
|
||||
const ecmRoot = `/${this.appConfig.get<string>(AppConfigValues.CONTEXTROOTECM) || 'alfresco'}/`;
|
||||
|
||||
if (contextRoot && requestUrl.indexOf(contextRoot) !== -1) {
|
||||
ticket = 'Basic ' + btoa(this.contentAuth.getToken());
|
||||
} else if (contextRootBpm && requestUrl.indexOf(contextRootBpm) !== -1) {
|
||||
ticket = 'Basic ' + this.processAuth.getToken();
|
||||
if (requestUrl?.includes(ecmRoot) && !requestUrl.includes(bpmRoot)) {
|
||||
ticket = this.getContentServicesTicket();
|
||||
} else if (requestUrl?.includes(bpmRoot) && !requestUrl.includes(ecmRoot)) {
|
||||
ticket = this.getProcessServicesTicket();
|
||||
} else if (requestUrl?.includes(ecmRoot) && requestUrl.includes(bpmRoot)) {
|
||||
ticket = requestUrl.indexOf(ecmRoot) < requestUrl.indexOf(bpmRoot) ? this.getContentServicesTicket() : this.getProcessServicesTicket();
|
||||
}
|
||||
|
||||
return ticket;
|
||||
}
|
||||
|
||||
private getProcessServicesTicket(): string {
|
||||
return this.processAuth.getToken()?.startsWith('Basic ') ? this.processAuth.getToken() : 'Basic ' + this.processAuth.getToken();
|
||||
}
|
||||
|
||||
private getContentServicesTicket(): string {
|
||||
return 'Basic ' + btoa(this.contentAuth.getToken());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user