Skip to content

Commit

Permalink
[ACS-6748] BasicAlfrescoAuthService.requireAlfTicket should not be in…
Browse files Browse the repository at this point in the history
… adf/core - fix after CR
  • Loading branch information
dominikiwanekhyland committed Mar 1, 2024
1 parent 2770884 commit a3e2086
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ import { ContentAuthLoaderService } from './content-auth-loader.service';
* @param authLoaderService service dependency
* @returns factory function
*/
export function contentAuthLoaderFactory(authLoaderService: ContentAuthLoaderService) {
export function contentAuthLoaderFactory(authLoaderService: ContentAuthLoaderService): () => void {
return () => authLoaderService.init();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*!
* @license
* Copyright © 2005-2023 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 { fakeAsync, TestBed, tick } from '@angular/core/testing';
import { AuthenticationService, BasicAlfrescoAuthService } from '@alfresco/adf-core';
import { ContentAuthLoaderService } from './content-auth-loader.service';
import { Subject } from 'rxjs';

describe('ContentAuthLoaderService', () => {
let service: ContentAuthLoaderService;
let authService: AuthenticationService;
let basicAlfrescoAuthService: BasicAlfrescoAuthService;
let onLoginSubject: Subject<void>;

beforeEach(() => {
onLoginSubject = new Subject<void>();
TestBed.configureTestingModule({
providers: [
ContentAuthLoaderService,
{
provide: AuthenticationService,
useValue: {
onLogin: onLoginSubject.asObservable(),
isOauth: () => false,
isALLProvider: () => false,
isECMProvider: () => false
}
},
{
provide: BasicAlfrescoAuthService,
useValue: {
requireAlfTicket: jasmine.createSpy()
}
}
]
});

service = TestBed.inject(ContentAuthLoaderService);
authService = TestBed.inject(AuthenticationService);
basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService);
});


it('should require Alf ticket on login if OAuth and provider is ALL or ECM', fakeAsync(() => {
spyOn(authService, 'isOauth').and.returnValue(true);
spyOn(authService, 'isALLProvider').and.returnValue(true);

service.init();
onLoginSubject.next();
tick();

expect(basicAlfrescoAuthService.requireAlfTicket).toHaveBeenCalled();
}));

it('should not require Alf ticket on login if not OAuth', fakeAsync(() => {
spyOn(authService, 'isOauth').and.returnValue(false);

service.init();
onLoginSubject.next();
tick();

expect(basicAlfrescoAuthService.requireAlfTicket).toHaveBeenCalled();
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class ContentAuthLoaderService {
private readonly authService: AuthenticationService,

Check failure on line 26 in lib/content-services/src/lib/auth-loader/content-auth-loader.service.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected trailing comma
) {
}

init(): void {
this.authService.onLogin.subscribe(async () => {
if (this.authService.isOauth() && (this.authService.isALLProvider() || this.authService.isECMProvider())) {
Expand Down
2 changes: 1 addition & 1 deletion lib/content-services/src/lib/content.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class ContentModule {
deps: [ContentAuthLoaderService],
multi: true
}
]
]
};
}

Expand Down

0 comments on commit a3e2086

Please sign in to comment.