diff --git a/lib/core/src/lib/auth/guard/auth-guard-bpm.service.spec.ts b/lib/core/src/lib/auth/guard/auth-guard-bpm.service.spec.ts index 5a6bf24872..14619d26c5 100644 --- a/lib/core/src/lib/auth/guard/auth-guard-bpm.service.spec.ts +++ b/lib/core/src/lib/auth/guard/auth-guard-bpm.service.spec.ts @@ -41,10 +41,21 @@ describe('AuthGuardService BPM', () => { imports: [ TranslateModule.forRoot(), CoreTestingModule + ], + providers: [ + { + provide: OidcAuthenticationService, useValue: { + ssoImplicitLogin: () => { }, + isPublicUrl: () => false, + hasValidIdToken: () => false, + isLoggedIn: () => false + } + } ] }); localStorage.clear(); basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService); + oidcAuthenticationService = TestBed.inject(OidcAuthenticationService); authService = TestBed.inject(AuthenticationService); authGuard = TestBed.inject(AuthGuardBpm); router = TestBed.inject(Router); diff --git a/lib/core/src/lib/auth/guard/auth-guard-ecm.service.spec.ts b/lib/core/src/lib/auth/guard/auth-guard-ecm.service.spec.ts index a766e26785..d4c26591db 100644 --- a/lib/core/src/lib/auth/guard/auth-guard-ecm.service.spec.ts +++ b/lib/core/src/lib/auth/guard/auth-guard-ecm.service.spec.ts @@ -40,6 +40,16 @@ describe('AuthGuardService ECM', () => { imports: [ TranslateModule.forRoot(), CoreTestingModule + ], + providers: [ + { + provide: OidcAuthenticationService, useValue: { + ssoImplicitLogin: () => { }, + isPublicUrl: () => false, + hasValidIdToken: () => false, + isLoggedIn: () => false + } + } ] }); localStorage.clear(); diff --git a/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts b/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts index 685290c847..96ef8d0eb6 100644 --- a/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts +++ b/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts @@ -41,6 +41,15 @@ describe('AuthGuardService', () => { imports: [ TranslateModule.forRoot(), CoreTestingModule + ], + providers: [ + { + provide: OidcAuthenticationService, useValue: { + ssoImplicitLogin: () => { }, + isPublicUrl: () => false, + hasValidIdToken: () => false + } + } ] }); localStorage.clear(); diff --git a/lib/core/src/lib/login/components/login-dialog-panel.component.spec.ts b/lib/core/src/lib/login/components/login-dialog-panel.component.spec.ts index 96540ae49b..8d6d12a338 100644 --- a/lib/core/src/lib/login/components/login-dialog-panel.component.spec.ts +++ b/lib/core/src/lib/login/components/login-dialog-panel.component.spec.ts @@ -21,6 +21,7 @@ import { of } from 'rxjs'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; import { BasicAlfrescoAuthService } from '../../auth/basic-auth/basic-alfresco-auth.service'; +import { OidcAuthenticationService } from '../../auth/services/oidc-authentication.service'; describe('LoginDialogPanelComponent', () => { let component: LoginDialogPanelComponent; @@ -35,9 +36,14 @@ describe('LoginDialogPanelComponent', () => { imports: [ TranslateModule.forRoot(), CoreTestingModule + ], + providers: [ + { provide: OidcAuthenticationService, useValue: {}} ] }); fixture = TestBed.createComponent(LoginDialogPanelComponent); + basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService); + element = fixture.nativeElement; component = fixture.componentInstance; diff --git a/lib/core/src/lib/login/components/login.component.spec.ts b/lib/core/src/lib/login/components/login.component.spec.ts index 2c1229e832..40cdcd4bd1 100644 --- a/lib/core/src/lib/login/components/login.component.spec.ts +++ b/lib/core/src/lib/login/components/login.component.spec.ts @@ -25,11 +25,11 @@ import { AuthenticationService } from '../../auth/services/authentication.servic import { LoginErrorEvent } from '../models/login-error.event'; import { LoginSuccessEvent } from '../models/login-success.event'; import { LoginComponent } from './login.component'; -import { of, throwError } from 'rxjs'; -import { AlfrescoApiService } from '../../services/alfresco-api.service'; +import { EMPTY, of, throwError } from 'rxjs'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { LogService } from '../../common/services/log.service'; import { BasicAlfrescoAuthService } from '../../auth/basic-auth/basic-alfresco-auth.service'; +import { OidcAuthenticationService } from '../../auth/services/oidc-authentication.service'; describe('LoginComponent', () => { let component: LoginComponent; @@ -39,7 +39,6 @@ describe('LoginComponent', () => { let router: Router; let userPreferences: UserPreferencesService; let appConfigService: AppConfigService; - let alfrescoApiService: AlfrescoApiService; let basicAlfrescoAuthService: BasicAlfrescoAuthService; let usernameInput; @@ -62,6 +61,16 @@ describe('LoginComponent', () => { TestBed.configureTestingModule({ imports: [ CoreTestingModule + ], + providers: [ + { + provide: OidcAuthenticationService, useValue: { + ssoImplicitLogin: () => { }, + isPublicUrl: () => false, + hasValidIdToken: () => false, + isLoggedIn: () => false + } + } ] }); fixture = TestBed.createComponent(LoginComponent); @@ -76,7 +85,6 @@ describe('LoginComponent', () => { router = TestBed.inject(Router); userPreferences = TestBed.inject(UserPreferencesService); appConfigService = TestBed.inject(AppConfigService); - alfrescoApiService = TestBed.inject(AlfrescoApiService); const logService = TestBed.inject(LogService); spyOn(logService, 'error'); @@ -178,7 +186,6 @@ describe('LoginComponent', () => { it('should update user preferences upon login', async () => { spyOn(userPreferences, 'setStoragePrefix').and.callThrough(); spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); - spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve()); component.success.subscribe(() => { expect(userPreferences.setStoragePrefix).toHaveBeenCalledWith('fake-username'); @@ -472,7 +479,7 @@ describe('LoginComponent', () => { }); it('should return error with a wrong username', (done) => { - spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject()); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(throwError(new Error())); component.error.subscribe(() => { fixture.detectChanges(); @@ -487,7 +494,7 @@ describe('LoginComponent', () => { }); it('should return error with a wrong password', (done) => { - spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject()); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(throwError(new Error())); component.error.subscribe(() => { fixture.detectChanges(); @@ -503,7 +510,7 @@ describe('LoginComponent', () => { }); it('should return error with a wrong username and password', (done) => { - spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject()); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(throwError(new Error())); component.error.subscribe(() => { fixture.detectChanges(); @@ -671,7 +678,7 @@ describe('LoginComponent', () => { }); it('should emit only the username and not the password as part of the executeSubmit', fakeAsync(() => { - spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve()); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(EMPTY); component.executeSubmit.subscribe((res) => { fixture.detectChanges(); @@ -691,7 +698,6 @@ describe('LoginComponent', () => { beforeEach(() => { appConfigService.config.oauth2 = { implicitFlow: true, silentLogin: false }; appConfigService.load(); - alfrescoApiService.reset(); }); it('should not show login username and password if SSO implicit flow is active', fakeAsync(() => { diff --git a/lib/core/src/lib/login/directives/login-footer.directive.spec.ts b/lib/core/src/lib/login/directives/login-footer.directive.spec.ts index bce4351a80..bde2728e77 100644 --- a/lib/core/src/lib/login/directives/login-footer.directive.spec.ts +++ b/lib/core/src/lib/login/directives/login-footer.directive.spec.ts @@ -20,6 +20,7 @@ import { LoginComponent } from '../components/login.component'; import { LoginFooterDirective } from './login-footer.directive'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; +import { OidcAuthenticationService } from '../../auth/services/oidc-authentication.service'; describe('LoginFooterDirective', () => { let fixture: ComponentFixture; @@ -31,6 +32,11 @@ describe('LoginFooterDirective', () => { imports: [ TranslateModule.forRoot(), CoreTestingModule + ], + providers: [ + { + provide: OidcAuthenticationService, useValue: {} + } ] }); fixture = TestBed.createComponent(LoginComponent); diff --git a/lib/core/src/lib/login/directives/login-header.directive.spec.ts b/lib/core/src/lib/login/directives/login-header.directive.spec.ts index 635eca7c57..c255e4c9ed 100644 --- a/lib/core/src/lib/login/directives/login-header.directive.spec.ts +++ b/lib/core/src/lib/login/directives/login-header.directive.spec.ts @@ -20,6 +20,7 @@ import { LoginComponent } from '../components/login.component'; import { LoginHeaderDirective } from './login-header.directive'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; +import { OidcAuthenticationService } from '../../auth/services/oidc-authentication.service'; describe('LoginHeaderDirective', () => { let fixture: ComponentFixture; @@ -31,6 +32,9 @@ describe('LoginHeaderDirective', () => { imports: [ TranslateModule.forRoot(), CoreTestingModule + ], + providers: [ + { provide: OidcAuthenticationService, useValue: {} } ] }); fixture = TestBed.createComponent(LoginComponent);