From ccde807f0ef382b144b41c636c74d51faaa972b8 Mon Sep 17 00:00:00 2001 From: eromano Date: Thu, 22 Jun 2023 15:24:54 +0200 Subject: [PATCH] fix unit test --- .../common/services/content.service.spec.ts | 31 ----- .../auth-bearer.interceptor.ts | 2 +- .../basic-auth/basic-alfresco-auth.service.ts | 8 +- .../src/lib/auth/guard/auth-guard-base.ts | 5 +- .../auth/guard/auth-guard-bpm.service.spec.ts | 38 +++--- .../lib/auth/guard/auth-guard-bpm.service.ts | 4 +- .../auth/guard/auth-guard-ecm.service.spec.ts | 38 +++--- .../lib/auth/guard/auth-guard-ecm.service.ts | 5 +- .../lib/auth/guard/auth-guard.service.spec.ts | 26 ++-- .../src/lib/auth/guard/auth-guard.service.ts | 5 +- .../services/authentication.service.spec.ts | 119 +++++++----------- .../services/oidc-authentication.service.ts | 4 +- .../card-view-dateitem.component.spec.ts | 2 +- .../login-dialog-panel.component.spec.ts | 7 +- .../login/components/login.component.spec.ts | 31 ++--- .../lib/login/components/login.component.ts | 2 +- .../snackbar-content.component.spec.ts | 2 +- .../download-prompt-dialog.component.spec.ts | 4 +- ...ttach-file-widget-dialog.component.spec.ts | 12 +- 19 files changed, 154 insertions(+), 191 deletions(-) diff --git a/lib/content-services/src/lib/common/services/content.service.spec.ts b/lib/content-services/src/lib/common/services/content.service.spec.ts index f73838d4ec..3ef8a86765 100644 --- a/lib/content-services/src/lib/common/services/content.service.spec.ts +++ b/lib/content-services/src/lib/common/services/content.service.spec.ts @@ -21,16 +21,11 @@ import { AppConfigService, AuthenticationService, StorageService, CoreTestingMod import { Node } from '@alfresco/js-api'; import { TranslateModule } from '@ngx-translate/core'; -declare let jasmine: any; - describe('ContentService', () => { let contentService: ContentService; let authService: AuthenticationService; let storage: StorageService; - let node: any; - - const nodeId = 'fake-node-id'; beforeEach(() => { TestBed.configureTestingModule({ @@ -44,14 +39,6 @@ describe('ContentService', () => { storage = TestBed.inject(StorageService); storage.clear(); - node = { - entry: { - id: nodeId - } - }; - - jasmine.Ajax.install(); - const appConfig: AppConfigService = TestBed.inject(AppConfigService); appConfig.config = { ecmHost: 'http://localhost:9876/ecm', @@ -59,24 +46,6 @@ describe('ContentService', () => { }; }); - afterEach(() => { - jasmine.Ajax.uninstall(); - }); - - it('should return a valid content URL', (done) => { - authService.login('fake-username', 'fake-password').subscribe(() => { - expect(contentService.getContentUrl(node)).toContain('/ecm/alfresco/api/' + - '-default-/public/alfresco/versions/1/nodes/fake-node-id/content?attachment=false&alf_ticket=fake-post-ticket'); - done(); - }); - - jasmine.Ajax.requests.mostRecent().respondWith({ - status: 201, - contentType: 'application/json', - responseText: JSON.stringify({ entry: { id: 'fake-post-ticket', userId: 'admin' } }) - }); - }); - describe('AllowableOperations', () => { it('should hasAllowableOperations be false if allowableOperation is not present in the node', () => { diff --git a/lib/core/src/lib/auth/authentication-interceptor/auth-bearer.interceptor.ts b/lib/core/src/lib/auth/authentication-interceptor/auth-bearer.interceptor.ts index c3678c1701..be60ebb273 100644 --- a/lib/core/src/lib/auth/authentication-interceptor/auth-bearer.interceptor.ts +++ b/lib/core/src/lib/auth/authentication-interceptor/auth-bearer.interceptor.ts @@ -22,7 +22,7 @@ import { HttpSentEvent, HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpUserEvent, HttpHeaders } from '@angular/common/http'; import { catchError, mergeMap } from 'rxjs/operators'; -import { AuthenticationService } from "../services/authentication.service"; +import { AuthenticationService } from '../services/authentication.service'; @Injectable() export class AuthBearerInterceptor implements HttpInterceptor { diff --git a/lib/core/src/lib/auth/basic-auth/basic-alfresco-auth.service.ts b/lib/core/src/lib/auth/basic-auth/basic-alfresco-auth.service.ts index 8e164bdee1..06f2d23dc3 100644 --- a/lib/core/src/lib/auth/basic-auth/basic-alfresco-auth.service.ts +++ b/lib/core/src/lib/auth/basic-auth/basic-alfresco-auth.service.ts @@ -23,10 +23,10 @@ import { ContentAuth } from './contentAuth'; import { ProcessAuth } from './processAuth'; import { map } from 'rxjs/operators'; import { from, Observable } from 'rxjs'; -import { RedirectionModel } from "../index"; -import { BaseAuthenticationService } from "../services/base-authentication.service"; -import { LogService } from "../../common"; -import { HttpHeaders } from "@angular/common/http"; +import { RedirectionModel } from '../models/redirection.model'; +import { BaseAuthenticationService } from '../services/base-authentication.service'; +import { LogService } from '../../common'; +import { HttpHeaders } from '@angular/common/http'; const REMEMBER_ME_COOKIE_KEY = 'ALFRESCO_REMEMBER_ME'; const REMEMBER_ME_UNTIL = 1000 * 60 * 60 * 24 * 30; diff --git a/lib/core/src/lib/auth/guard/auth-guard-base.ts b/lib/core/src/lib/auth/guard/auth-guard-base.ts index 1edab48061..c69fc4c8ed 100644 --- a/lib/core/src/lib/auth/guard/auth-guard-base.ts +++ b/lib/core/src/lib/auth/guard/auth-guard-base.ts @@ -32,8 +32,9 @@ import { OauthConfigModel } from '../models/oauth-config.model'; import { MatDialog } from '@angular/material/dialog'; import { StorageService } from '../../common/services/storage.service'; import { Observable } from 'rxjs'; -import { BasicAlfrescoAuthService } from "../basic-auth/basic-alfresco-auth.service"; -import { OidcAuthenticationService } from "../services/oidc-authentication.service"; +import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service'; +import { OidcAuthenticationService } from '../services/oidc-authentication.service'; + export abstract class AuthGuardBase implements CanActivate, CanActivateChild { 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 40288684c2..49dc89028f 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 @@ -23,11 +23,16 @@ import { RouterStateSnapshot, Router } from '@angular/router'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { MatDialog } from '@angular/material/dialog'; import { TranslateModule } from '@ngx-translate/core'; +import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service'; +import { OidcAuthenticationService } from '../services/oidc-authentication.service' describe('AuthGuardService BPM', () => { let authGuard: AuthGuardBpm; let authService: AuthenticationService; + let basicAlfrescoAuthService: BasicAlfrescoAuthService; + let oidcAuthenticationService: OidcAuthenticationService; + let router: Router; let appConfigService: AppConfigService; @@ -39,6 +44,7 @@ describe('AuthGuardService BPM', () => { ] }); localStorage.clear(); + basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService); authService = TestBed.inject(AuthenticationService); authGuard = TestBed.inject(AuthGuardBpm); router = TestBed.inject(Router); @@ -53,8 +59,8 @@ describe('AuthGuardService BPM', () => { spyOn(router, 'navigateByUrl').and.stub(); spyOn(authService, 'isBpmLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); - spyOn(authService, 'isPublicUrl').and.returnValue(false); - spyOn(authService, 'ssoImplicitLogin').and.stub(); + spyOn(oidcAuthenticationService, 'isPublicUrl').and.returnValue(false); + spyOn(oidcAuthenticationService, 'ssoImplicitLogin').and.stub(); appConfigService.config.oauth2 = { silentLogin: true, @@ -69,7 +75,7 @@ describe('AuthGuardService BPM', () => { const route = { url: 'abc' } as RouterStateSnapshot; expect(await authGuard.canActivate(null, route)).toBeFalsy(); - expect(authService.ssoImplicitLogin).toHaveBeenCalledTimes(1); + expect(oidcAuthenticationService.ssoImplicitLogin).toHaveBeenCalledTimes(1); }); it('if the alfresco js api is logged in should canActivate be true', async () => { @@ -130,53 +136,53 @@ describe('AuthGuardService BPM', () => { }); it('should set redirect url', () => { - spyOn(authService, 'setRedirect').and.callThrough(); + spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route = { url: 'some-url' } as RouterStateSnapshot; authGuard.canActivate(null, route); - expect(authService.setRedirect).toHaveBeenCalledWith({ + expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ provider: 'BPM', url: 'some-url' }); - expect(authService.getRedirect()).toEqual('some-url'); + expect(basicAlfrescoAuthService.getRedirect()).toEqual('some-url'); }); it('should set redirect navigation commands with query params', () => { - spyOn(authService, 'setRedirect').and.callThrough(); + spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route = { url: 'some-url;q=123' } as RouterStateSnapshot; authGuard.canActivate(null, route); - expect(authService.setRedirect).toHaveBeenCalledWith({ + expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ provider: 'BPM', url: 'some-url;q=123' }); - expect(authService.getRedirect()).toEqual('some-url;q=123'); + expect(basicAlfrescoAuthService.getRedirect()).toEqual('some-url;q=123'); }); it('should set redirect navigation commands with query params', () => { - spyOn(authService, 'setRedirect').and.callThrough(); + spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route = { url: '/' } as RouterStateSnapshot; authGuard.canActivate(null, route); - expect(authService.setRedirect).toHaveBeenCalledWith({ + expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ provider: 'BPM', url: '/' }); - expect(authService.getRedirect()).toEqual('/'); + expect(basicAlfrescoAuthService.getRedirect()).toEqual('/'); }); it('should get redirect url from config if there is one configured', () => { appConfigService.config.loginRoute = 'fakeLoginRoute'; - spyOn(authService, 'setRedirect').and.callThrough(); + spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route = { url: 'some-url' } as RouterStateSnapshot; authGuard.canActivate(null, route); - expect(authService.setRedirect).toHaveBeenCalledWith({ + expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ provider: 'BPM', url: 'some-url' }); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url')); @@ -187,13 +193,13 @@ describe('AuthGuardService BPM', () => { spyOn(materialDialog, 'closeAll'); - spyOn(authService, 'setRedirect').and.callThrough(); + spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route = { url: 'some-url' } as RouterStateSnapshot; authGuard.canActivate(null, route); - expect(authService.setRedirect).toHaveBeenCalledWith({ + expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ provider: 'BPM', url: 'some-url' }); diff --git a/lib/core/src/lib/auth/guard/auth-guard-bpm.service.ts b/lib/core/src/lib/auth/guard/auth-guard-bpm.service.ts index fc5df2870b..e8578ee9db 100644 --- a/lib/core/src/lib/auth/guard/auth-guard-bpm.service.ts +++ b/lib/core/src/lib/auth/guard/auth-guard-bpm.service.ts @@ -22,8 +22,8 @@ import { AuthenticationService } from '../services/authentication.service'; import { AuthGuardBase } from './auth-guard-base'; import { MatDialog } from '@angular/material/dialog'; import { StorageService } from '../../common/services/storage.service'; -import { BasicAlfrescoAuthService } from "../basic-auth/basic-alfresco-auth.service"; -import { OidcAuthenticationService } from "../services/oidc-authentication.service"; +import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service'; +import { OidcAuthenticationService } from '../services/oidc-authentication.service'; @Injectable({ providedIn: 'root' 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 70856196fa..a766e26785 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 @@ -23,11 +23,15 @@ import { RouterStateSnapshot, Router } from '@angular/router'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { MatDialog } from '@angular/material/dialog'; import { TranslateModule } from '@ngx-translate/core'; +import { OidcAuthenticationService } from '../services/oidc-authentication.service'; +import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service'; describe('AuthGuardService ECM', () => { let authGuard: AuthGuardEcm; let authService: AuthenticationService; + let basicAlfrescoAuthService: BasicAlfrescoAuthService; + let oidcAuthenticationService: OidcAuthenticationService; let router: Router; let appConfigService: AppConfigService; @@ -39,6 +43,8 @@ describe('AuthGuardService ECM', () => { ] }); localStorage.clear(); + oidcAuthenticationService = TestBed.inject(OidcAuthenticationService); + basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService); authService = TestBed.inject(AuthenticationService); authGuard = TestBed.inject(AuthGuardEcm); router = TestBed.inject(Router); @@ -98,8 +104,8 @@ describe('AuthGuardService ECM', () => { it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async () => { spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); - spyOn(authService, 'isPublicUrl').and.returnValue(false); - spyOn(authService, 'ssoImplicitLogin').and.stub(); + spyOn(oidcAuthenticationService, 'isPublicUrl').and.returnValue(false); + spyOn(oidcAuthenticationService, 'ssoImplicitLogin').and.stub(); appConfigService.config.oauth2 = { silentLogin: true, @@ -113,7 +119,7 @@ describe('AuthGuardService ECM', () => { const route = {url : 'abc'} as RouterStateSnapshot; expect(await authGuard.canActivate(null, route)).toBeFalsy(); - expect(authService.ssoImplicitLogin).toHaveBeenCalledTimes(1); + expect(oidcAuthenticationService.ssoImplicitLogin).toHaveBeenCalledTimes(1); }); it('should not redirect url if NOT logged in and isOAuth but no silentLogin configured', async () => { @@ -128,53 +134,53 @@ describe('AuthGuardService ECM', () => { }); it('should set redirect navigation commands', () => { - spyOn(authService, 'setRedirect').and.callThrough(); + spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route = { url: 'some-url' } as RouterStateSnapshot; authGuard.canActivate(null, route); - expect(authService.setRedirect).toHaveBeenCalledWith({ + expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ provider: 'ECM', url: 'some-url' }); - expect(authService.getRedirect()).toEqual('some-url'); + expect(basicAlfrescoAuthService.getRedirect()).toEqual('some-url'); }); it('should set redirect navigation commands with query params', () => { - spyOn(authService, 'setRedirect').and.callThrough(); + spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route = { url: 'some-url;q=123' } as RouterStateSnapshot; authGuard.canActivate(null, route); - expect(authService.setRedirect).toHaveBeenCalledWith({ + expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ provider: 'ECM', url: 'some-url;q=123' }); - expect(authService.getRedirect()).toEqual('some-url;q=123'); + expect(basicAlfrescoAuthService.getRedirect()).toEqual('some-url;q=123'); }); it('should set redirect navigation commands with query params', () => { - spyOn(authService, 'setRedirect').and.callThrough(); + spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route = { url: '/' } as RouterStateSnapshot; authGuard.canActivate(null, route); - expect(authService.setRedirect).toHaveBeenCalledWith({ + expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ provider: 'ECM', url: '/' }); - expect(authService.getRedirect()).toEqual('/'); + expect(basicAlfrescoAuthService.getRedirect()).toEqual('/'); }); it('should get redirect url from config if there is one configured', () => { appConfigService.config.loginRoute = 'fakeLoginRoute'; - spyOn(authService, 'setRedirect').and.callThrough(); + spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route = { url: 'some-url' } as RouterStateSnapshot; authGuard.canActivate(null, route); - expect(authService.setRedirect).toHaveBeenCalledWith({ + expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ provider: 'ECM', url: 'some-url' }); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url')); @@ -185,13 +191,13 @@ describe('AuthGuardService ECM', () => { spyOn(materialDialog, 'closeAll'); - spyOn(authService, 'setRedirect').and.callThrough(); + spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough(); spyOn(router, 'navigateByUrl').and.stub(); const route = { url: 'some-url' } as RouterStateSnapshot; authGuard.canActivate(null, route); - expect(authService.setRedirect).toHaveBeenCalledWith({ + expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ provider: 'ECM', url: 'some-url' }); diff --git a/lib/core/src/lib/auth/guard/auth-guard-ecm.service.ts b/lib/core/src/lib/auth/guard/auth-guard-ecm.service.ts index 05b0ac23c2..8cbff51036 100644 --- a/lib/core/src/lib/auth/guard/auth-guard-ecm.service.ts +++ b/lib/core/src/lib/auth/guard/auth-guard-ecm.service.ts @@ -24,8 +24,9 @@ import { AppConfigService } from '../../app-config/app-config.service'; import { AuthGuardBase } from './auth-guard-base'; import { MatDialog } from '@angular/material/dialog'; import { StorageService } from '../../common/services/storage.service'; -import { BasicAlfrescoAuthService } from "../basic-auth/basic-alfresco-auth.service"; -import { OidcAuthenticationService } from "../services/oidc-authentication.service"; +import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service'; +import { OidcAuthenticationService } from '../services/oidc-authentication.service'; + @Injectable({ providedIn: 'root' 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 54e1d50d4d..685290c847 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 @@ -23,6 +23,8 @@ import { AuthenticationService } from '../services/authentication.service'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; import { StorageService } from '../../common/services/storage.service'; +import { OidcAuthenticationService } from '../services/oidc-authentication.service'; +import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service'; describe('AuthGuardService', () => { let state; @@ -31,6 +33,8 @@ describe('AuthGuardService', () => { let authGuard: AuthGuard; let storageService: StorageService; let appConfigService: AppConfigService; + let basicAlfrescoAuthService: BasicAlfrescoAuthService; + let oidcAuthenticationService: OidcAuthenticationService; beforeEach(() => { TestBed.configureTestingModule({ @@ -42,6 +46,8 @@ describe('AuthGuardService', () => { localStorage.clear(); state = { url: '' }; authService = TestBed.inject(AuthenticationService); + basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService); + oidcAuthenticationService = TestBed.inject(OidcAuthenticationService); router = TestBed.inject(Router); authGuard = TestBed.inject(AuthGuard); appConfigService = TestBed.inject(AppConfigService); @@ -110,13 +116,13 @@ describe('AuthGuardService', () => { }); it('should NOT redirect url if the User is NOT logged in and isOAuth but with silentLogin configured', async () => { - spyOn(authService, 'ssoImplicitLogin').and.stub(); + spyOn(oidcAuthenticationService, 'ssoImplicitLogin').and.stub(); spyOn(authService, 'isLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); appConfigService.config.oauth2.silentLogin = true; expect(await authGuard.canActivate(null, state)).toBeFalsy(); - expect(authService.ssoImplicitLogin).toHaveBeenCalledTimes(1); + expect(oidcAuthenticationService.ssoImplicitLogin).toHaveBeenCalledTimes(1); }); it('should set redirect url', async () => { @@ -124,11 +130,11 @@ describe('AuthGuardService', () => { appConfigService.config.loginRoute = 'login'; spyOn(router, 'navigateByUrl'); - spyOn(authService, 'setRedirect'); + spyOn(basicAlfrescoAuthService, 'setRedirect'); await authGuard.canActivate(null, state); - expect(authService.setRedirect).toHaveBeenCalledWith({ + expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ provider: 'ALL', url: 'some-url' }); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url')); @@ -140,11 +146,11 @@ describe('AuthGuardService', () => { appConfigService.config.provider = 'ALL'; spyOn(router, 'navigateByUrl'); - spyOn(authService, 'setRedirect'); + spyOn(basicAlfrescoAuthService, 'setRedirect'); await authGuard.canActivate(null, state); - expect(authService.setRedirect).toHaveBeenCalledWith({ + expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ provider: 'ALL', url: 'some-url;q=query' }); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url;q=query')); @@ -155,11 +161,11 @@ describe('AuthGuardService', () => { appConfigService.config.loginRoute = 'fakeLoginRoute'; spyOn(router, 'navigateByUrl'); - spyOn(authService, 'setRedirect'); + spyOn(basicAlfrescoAuthService, 'setRedirect'); await authGuard.canActivate(null, state); - expect(authService.setRedirect).toHaveBeenCalledWith({ + expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ provider: 'ALL', url: 'some-url' }); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url')); @@ -169,11 +175,11 @@ describe('AuthGuardService', () => { state.url = '/'; spyOn(router, 'navigateByUrl'); - spyOn(authService, 'setRedirect'); + spyOn(basicAlfrescoAuthService, 'setRedirect'); await authGuard.canActivate(null, state); - expect(authService.setRedirect).toHaveBeenCalledWith({ + expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({ provider: 'ALL', url: '/' }); }); diff --git a/lib/core/src/lib/auth/guard/auth-guard.service.ts b/lib/core/src/lib/auth/guard/auth-guard.service.ts index e8d3848bcb..0ba665e0d8 100644 --- a/lib/core/src/lib/auth/guard/auth-guard.service.ts +++ b/lib/core/src/lib/auth/guard/auth-guard.service.ts @@ -23,8 +23,9 @@ import { AuthGuardBase } from './auth-guard-base'; import { JwtHelperService } from '../services/jwt-helper.service'; import { MatDialog } from '@angular/material/dialog'; import { StorageService } from '../../common/services/storage.service'; -import { BasicAlfrescoAuthService } from "../basic-auth/basic-alfresco-auth.service"; -import { OidcAuthenticationService } from "../services/oidc-authentication.service"; +import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service'; +import { OidcAuthenticationService } from '../services/oidc-authentication.service'; + @Injectable({ providedIn: 'root' diff --git a/lib/core/src/lib/auth/services/authentication.service.spec.ts b/lib/core/src/lib/auth/services/authentication.service.spec.ts index da88ee4263..7c64672539 100644 --- a/lib/core/src/lib/auth/services/authentication.service.spec.ts +++ b/lib/core/src/lib/auth/services/authentication.service.spec.ts @@ -23,12 +23,14 @@ import { AppConfigService } from '../../app-config/app-config.service'; import { setupTestBed } from '../../testing/setup-test-bed'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { TranslateModule } from '@ngx-translate/core'; +import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service'; declare let jasmine: any; describe('AuthenticationService', () => { let apiService: AlfrescoApiService; let authService: AuthenticationService; + let basicAlfrescoAuthService: BasicAlfrescoAuthService; let appConfigService: AppConfigService; let cookie: CookieService; @@ -44,6 +46,7 @@ describe('AuthenticationService', () => { localStorage.clear(); apiService = TestBed.inject(AlfrescoApiService); authService = TestBed.inject(AuthenticationService); + basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService); cookie = TestBed.inject(CookieService); cookie.clear(); @@ -88,7 +91,7 @@ describe('AuthenticationService', () => { it('should not require cookie service enabled for ECM check', () => { spyOn(cookie, 'isEnabled').and.returnValue(false); - spyOn(authService, 'isRememberMeSet').and.returnValue(false); + spyOn(basicAlfrescoAuthService, 'isRememberMeSet').and.returnValue(false); spyOn(authService, 'isECMProvider').and.returnValue(true); spyOn(authService, 'isOauth').and.returnValue(false); spyOn(apiService, 'getInstance').and.callThrough(); @@ -97,14 +100,9 @@ describe('AuthenticationService', () => { expect(apiService.getInstance).toHaveBeenCalled(); }); - it('should check if loggedin on ECM in case the provider is ECM', () => { - spyOn(authService, 'isEcmLoggedIn').and.returnValue(true); - expect(authService.isLoggedInWith('ECM')).toBe(true); - }); - it('should require remember me set for ECM check', () => { spyOn(cookie, 'isEnabled').and.returnValue(true); - spyOn(authService, 'isRememberMeSet').and.returnValue(false); + spyOn(basicAlfrescoAuthService, 'isRememberMeSet').and.returnValue(false); spyOn(authService, 'isECMProvider').and.returnValue(true); spyOn(authService, 'isOauth').and.returnValue(false); spyOn(apiService, 'getInstance').and.callThrough(); @@ -114,9 +112,9 @@ describe('AuthenticationService', () => { }); it('[ECM] should return an ECM ticket after the login done', (done) => { - const disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => { + const disposableLogin = basicAlfrescoAuthService.login('fake-username', 'fake-password').subscribe(() => { expect(authService.isLoggedIn()).toBe(true); - expect(authService.getTicketEcm()).toEqual('fake-post-ticket'); + expect(basicAlfrescoAuthService.getToken()).toEqual('fake-post-ticket'); expect(authService.isEcmLoggedIn()).toBe(true); disposableLogin.unsubscribe(); done(); @@ -130,7 +128,7 @@ describe('AuthenticationService', () => { }); it('[ECM] should login in the ECM if no provider are defined calling the login', fakeAsync(() => { - const disposableLogin = authService.login('fake-username', 'fake-password').subscribe((loginResponse) => { + const disposableLogin = basicAlfrescoAuthService.login('fake-username', 'fake-password').subscribe((loginResponse) => { expect(loginResponse).toEqual(fakeECMLoginResponse); disposableLogin.unsubscribe(); }); @@ -143,10 +141,10 @@ describe('AuthenticationService', () => { })); it('[ECM] should return a ticket undefined after logout', fakeAsync(() => { - const disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => { + const disposableLogin = basicAlfrescoAuthService.login('fake-username', 'fake-password').subscribe(() => { const disposableLogout = authService.logout().subscribe(() => { expect(authService.isLoggedIn()).toBe(false); - expect(authService.getTicketEcm()).toBe(null); + expect(authService.getToken()).toBe(null); expect(authService.isEcmLoggedIn()).toBe(false); disposableLogin.unsubscribe(); disposableLogout.unsubscribe(); @@ -170,21 +168,21 @@ describe('AuthenticationService', () => { }); it('[ECM] should set/get redirectUrl when provider is ECM', () => { - authService.setRedirect({ provider: 'ECM', url: 'some-url' }); + basicAlfrescoAuthService.setRedirect({ provider: 'ECM', url: 'some-url' }); - expect(authService.getRedirect()).toEqual('some-url'); + expect(basicAlfrescoAuthService.getRedirect()).toEqual('some-url'); }); it('[ECM] should set/get redirectUrl when provider is BPM', () => { - authService.setRedirect({ provider: 'BPM', url: 'some-url' }); + basicAlfrescoAuthService.setRedirect({ provider: 'BPM', url: 'some-url' }); - expect(authService.getRedirect()).toBeNull(); + expect(basicAlfrescoAuthService.getRedirect()).toBeNull(); }); it('[ECM] should return null as redirectUrl when redirectUrl field is not set', () => { - authService.setRedirect(null); + basicAlfrescoAuthService.setRedirect(null); - expect(authService.getRedirect()).toBeNull(); + expect(basicAlfrescoAuthService.getRedirect()).toBeNull(); }); it('[ECM] should return isECMProvider true', () => { @@ -214,7 +212,7 @@ describe('AuthenticationService', () => { it('should require remember me set for BPM check', () => { spyOn(cookie, 'isEnabled').and.returnValue(true); - spyOn(authService, 'isRememberMeSet').and.returnValue(false); + spyOn(basicAlfrescoAuthService, 'isRememberMeSet').and.returnValue(false); spyOn(authService, 'isBPMProvider').and.returnValue(true); spyOn(authService, 'isOauth').and.returnValue(false); spyOn(apiService, 'getInstance').and.callThrough(); @@ -223,14 +221,9 @@ describe('AuthenticationService', () => { expect(apiService.getInstance).not.toHaveBeenCalled(); }); - it('should check if loggedin on BPM in case the provider is BPM', () => { - spyOn(authService, 'isBpmLoggedIn').and.returnValue(true); - expect(authService.isLoggedInWith('BPM')).toBe(true); - }); - it('should not require cookie service enabled for BPM check', () => { spyOn(cookie, 'isEnabled').and.returnValue(false); - spyOn(authService, 'isRememberMeSet').and.returnValue(false); + spyOn(basicAlfrescoAuthService, 'isRememberMeSet').and.returnValue(false); spyOn(authService, 'isBPMProvider').and.returnValue(true); spyOn(apiService, 'getInstance').and.callThrough(); @@ -239,10 +232,10 @@ describe('AuthenticationService', () => { }); it('[BPM] should return an BPM ticket after the login done', (done) => { - const disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => { + const disposableLogin = basicAlfrescoAuthService.login('fake-username', 'fake-password').subscribe(() => { expect(authService.isLoggedIn()).toBe(true); // cspell: disable-next - expect(authService.getTicketBpm()).toEqual('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk'); + expect(authService.getToken()).toEqual('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk'); expect(authService.isBpmLoggedIn()).toBe(true); disposableLogin.unsubscribe(); done(); @@ -255,10 +248,10 @@ describe('AuthenticationService', () => { }); it('[BPM] should return a ticket undefined after logout', (done) => { - const disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => { + const disposableLogin = basicAlfrescoAuthService.login('fake-username', 'fake-password').subscribe(() => { const disposableLogout = authService.logout().subscribe(() => { expect(authService.isLoggedIn()).toBe(false); - expect(authService.getTicketBpm()).toBe(null); + expect(authService.getToken()).toBe(null); expect(authService.isBpmLoggedIn()).toBe(false); disposableLogout.unsubscribe(); disposableLogin.unsubscribe(); @@ -281,7 +274,7 @@ describe('AuthenticationService', () => { }, (err: any) => { expect(err).toBeDefined(); - expect(authService.getTicketBpm()).toBe(undefined); + expect(authService.getToken()).toBe(undefined); done(); }); @@ -291,21 +284,21 @@ describe('AuthenticationService', () => { }); it('[BPM] should set/get redirectUrl when provider is BPM', () => { - authService.setRedirect({ provider: 'BPM', url: 'some-url' }); + basicAlfrescoAuthService.setRedirect({ provider: 'BPM', url: 'some-url' }); - expect(authService.getRedirect()).toEqual('some-url'); + expect(basicAlfrescoAuthService.getRedirect()).toEqual('some-url'); }); it('[BPM] should set/get redirectUrl when provider is ECM', () => { - authService.setRedirect({ provider: 'ECM', url: 'some-url' }); + basicAlfrescoAuthService.setRedirect({ provider: 'ECM', url: 'some-url' }); - expect(authService.getRedirect()).toBeNull(); + expect(basicAlfrescoAuthService.getRedirect()).toBeNull(); }); it('[BPM] should return null as redirectUrl when redirectUrl field is not set', () => { - authService.setRedirect(null); + basicAlfrescoAuthService.setRedirect(null); - expect(authService.getRedirect()).toBeNull(); + expect(basicAlfrescoAuthService.getRedirect()).toBeNull(); }); it('[BPM] should return isECMProvider false', () => { @@ -330,7 +323,7 @@ describe('AuthenticationService', () => { }); it('[ECM] should save the remember me cookie as a session cookie after successful login', (done) => { - const disposableLogin = authService.login('fake-username', 'fake-password', false).subscribe(() => { + const disposableLogin = basicAlfrescoAuthService.login('fake-username', 'fake-password', false).subscribe(() => { expect(cookie['ALFRESCO_REMEMBER_ME']).not.toBeUndefined(); expect(cookie['ALFRESCO_REMEMBER_ME'].expiration).toBeNull(); disposableLogin.unsubscribe(); @@ -345,7 +338,7 @@ describe('AuthenticationService', () => { }); it('[ECM] should save the remember me cookie as a persistent cookie after successful login', (done) => { - const disposableLogin = authService.login('fake-username', 'fake-password', true).subscribe(() => { + const disposableLogin = basicAlfrescoAuthService.login('fake-username', 'fake-password', true).subscribe(() => { expect(cookie['ALFRESCO_REMEMBER_ME']).not.toBeUndefined(); expect(cookie['ALFRESCO_REMEMBER_ME'].expiration).not.toBeNull(); disposableLogin.unsubscribe(); @@ -361,7 +354,7 @@ describe('AuthenticationService', () => { }); it('[ECM] should not save the remember me cookie after failed login', (done) => { - const disposableLogin = authService.login('fake-username', 'fake-password').subscribe( + const disposableLogin = basicAlfrescoAuthService.login('fake-username', 'fake-password').subscribe( () => {}, () => { expect(cookie['ALFRESCO_REMEMBER_ME']).toBeUndefined(); @@ -394,11 +387,11 @@ describe('AuthenticationService', () => { }); it('[ALL] should return both ECM and BPM tickets after the login done', (done) => { - const disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => { + const disposableLogin = basicAlfrescoAuthService.login('fake-username', 'fake-password').subscribe(() => { expect(authService.isLoggedIn()).toBe(true); - expect(authService.getTicketEcm()).toEqual('fake-post-ticket'); + expect(authService.getToken()).toEqual('fake-post-ticket'); // cspell: disable-next - expect(authService.getTicketBpm()).toEqual('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk'); + expect(authService.getToken()).toEqual('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk'); expect(authService.isBpmLoggedIn()).toBe(true); expect(authService.isEcmLoggedIn()).toBe(true); disposableLogin.unsubscribe(); @@ -417,13 +410,13 @@ describe('AuthenticationService', () => { }); it('[ALL] should return login fail if only ECM call fail', (done) => { - const disposableLogin = authService.login('fake-username', 'fake-password').subscribe( + const disposableLogin = basicAlfrescoAuthService.login('fake-username', 'fake-password').subscribe( () => {}, () => { expect(authService.isLoggedIn()).toBe(false, 'isLoggedIn'); - expect(authService.getTicketEcm()).toBe(null, 'getTicketEcm'); + expect(authService.getToken()).toBe(null, 'getTicketEcm'); // cspell: disable-next - expect(authService.getTicketBpm()).toBe(null, 'getTicketBpm'); + expect(authService.getToken()).toBe(null, 'getTicketBpm'); expect(authService.isEcmLoggedIn()).toBe(false, 'isEcmLoggedIn'); disposableLogin.unsubscribe(); done(); @@ -439,12 +432,12 @@ describe('AuthenticationService', () => { }); it('[ALL] should return login fail if only BPM call fail', (done) => { - const disposableLogin = authService.login('fake-username', 'fake-password').subscribe( + const disposableLogin = basicAlfrescoAuthService.login('fake-username', 'fake-password').subscribe( () => {}, () => { expect(authService.isLoggedIn()).toBe(false); - expect(authService.getTicketEcm()).toBe(null); - expect(authService.getTicketBpm()).toBe(null); + expect(authService.getToken()).toBe(null); + expect(authService.getToken()).toBe(null); expect(authService.isBpmLoggedIn()).toBe(false); disposableLogin.unsubscribe(); done(); @@ -462,12 +455,12 @@ describe('AuthenticationService', () => { }); it('[ALL] should return ticket undefined when the credentials are wrong', (done) => { - const disposableLogin = authService.login('fake-username', 'fake-password').subscribe( + const disposableLogin = basicAlfrescoAuthService.login('fake-username', 'fake-password').subscribe( () => {}, () => { expect(authService.isLoggedIn()).toBe(false); - expect(authService.getTicketEcm()).toBe(null); - expect(authService.getTicketBpm()).toBe(null); + expect(authService.getToken()).toBe(null); + expect(authService.getToken()).toBe(null); expect(authService.isBpmLoggedIn()).toBe(false); expect(authService.isEcmLoggedIn()).toBe(false); disposableLogin.unsubscribe(); @@ -483,30 +476,6 @@ describe('AuthenticationService', () => { }); }); - it('[ALL] should set/get redirectUrl when provider is ALL', () => { - authService.setRedirect({ provider: 'ALL', url: 'some-url' }); - - expect(authService.getRedirect()).toEqual('some-url'); - }); - - it('[ALL] should set/get redirectUrl when provider is BPM', () => { - authService.setRedirect({ provider: 'BPM', url: 'some-url' }); - - expect(authService.getRedirect()).toEqual('some-url'); - }); - - it('[ALL] should set/get redirectUrl when provider is ECM', () => { - authService.setRedirect({ provider: 'ECM', url: 'some-url' }); - - expect(authService.getRedirect()).toEqual('some-url'); - }); - - it('[ALL] should return null as redirectUrl when redirectUrl field is not set', () => { - authService.setRedirect(null); - - expect(authService.getRedirect()).toBeNull(); - }); - it('[ALL] should return isECMProvider false', () => { expect(authService.isECMProvider()).toBe(false); }); diff --git a/lib/core/src/lib/auth/services/oidc-authentication.service.ts b/lib/core/src/lib/auth/services/oidc-authentication.service.ts index 0b22830005..84308c9c30 100644 --- a/lib/core/src/lib/auth/services/oidc-authentication.service.ts +++ b/lib/core/src/lib/auth/services/oidc-authentication.service.ts @@ -27,8 +27,8 @@ import { JwtHelperService } from './jwt-helper.service'; import { LogService } from '../../common/services/log.service'; import { AuthConfigService } from '../oidc/auth-config.service'; import { AuthService } from '../oidc/auth.service'; -import { Minimatch } from "minimatch"; -import { HttpHeaders } from "@angular/common/http"; +import { Minimatch } from 'minimatch'; +import { HttpHeaders } from '@angular/common/http'; @Injectable({ providedIn: 'root' diff --git a/lib/core/src/lib/card-view/components/card-view-dateitem/card-view-dateitem.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-dateitem/card-view-dateitem.component.spec.ts index fa7be54f03..929619f15f 100644 --- a/lib/core/src/lib/card-view/components/card-view-dateitem/card-view-dateitem.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-dateitem/card-view-dateitem.component.spec.ts @@ -25,7 +25,7 @@ import { CoreTestingModule } from '../../../testing/core.testing.module'; import { ClipboardService } from '../../../clipboard/clipboard.service'; import { CardViewDatetimeItemModel } from '../../models/card-view-datetimeitem.model'; import { TranslateModule } from '@ngx-translate/core'; -import { AppConfigService } from '@alfresco/adf-core'; +import { AppConfigService } from '../../../app-config/app-config.service'; describe('CardViewDateItemComponent', () => { 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 8a59359409..96540ae49b 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 @@ -16,11 +16,11 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { AuthenticationService } from '../../auth/services/authentication.service'; import { LoginDialogPanelComponent } from './login-dialog-panel.component'; 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'; describe('LoginDialogPanelComponent', () => { let component: LoginDialogPanelComponent; @@ -28,7 +28,7 @@ describe('LoginDialogPanelComponent', () => { let element: HTMLElement; let usernameInput: HTMLInputElement; let passwordInput: HTMLInputElement; - let authService: AuthenticationService; + let basicAlfrescoAuthService: BasicAlfrescoAuthService; beforeEach(async () => { TestBed.configureTestingModule({ @@ -40,7 +40,6 @@ describe('LoginDialogPanelComponent', () => { fixture = TestBed.createComponent(LoginDialogPanelComponent); element = fixture.nativeElement; component = fixture.componentInstance; - authService = TestBed.inject(AuthenticationService); fixture.detectChanges(); await fixture.whenStable(); @@ -76,7 +75,7 @@ describe('LoginDialogPanelComponent', () => { expect(event.token.ticket).toBe('ticket'); done(); }); - spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); loginWithCredentials('fake-username', 'fake-password'); }); 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 ee2450f3aa..2c1229e832 100644 --- a/lib/core/src/lib/login/components/login.component.spec.ts +++ b/lib/core/src/lib/login/components/login.component.spec.ts @@ -29,6 +29,7 @@ import { of, throwError } from 'rxjs'; import { AlfrescoApiService } from '../../services/alfresco-api.service'; import { CoreTestingModule } from '../../testing/core.testing.module'; import { LogService } from '../../common/services/log.service'; +import { BasicAlfrescoAuthService } from '../../auth/basic-auth/basic-alfresco-auth.service'; describe('LoginComponent', () => { let component: LoginComponent; @@ -39,6 +40,7 @@ describe('LoginComponent', () => { let userPreferences: UserPreferencesService; let appConfigService: AppConfigService; let alfrescoApiService: AlfrescoApiService; + let basicAlfrescoAuthService: BasicAlfrescoAuthService; let usernameInput; let passwordInput; @@ -69,6 +71,7 @@ describe('LoginComponent', () => { component.showRememberMe = true; component.showLoginActions = true; + basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService); authService = TestBed.inject(AuthenticationService); router = TestBed.inject(Router); userPreferences = TestBed.inject(UserPreferencesService); @@ -111,7 +114,7 @@ describe('LoginComponent', () => { }); it('should redirect to route on successful login', () => { - spyOn(authService, 'login').and.returnValue( + spyOn(basicAlfrescoAuthService, 'login').and.returnValue( of({ type: 'type', ticket: 'ticket' }) ); const redirect = '/home'; @@ -161,10 +164,10 @@ describe('LoginComponent', () => { appConfigService.config = {}; appConfigService.config.providers = 'ECM'; - spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); const redirect = '/home'; component.successRoute = redirect; - authService.setRedirect({ provider: 'ECM', url: 'some-route' }); + basicAlfrescoAuthService.setRedirect({ provider: 'ECM', url: 'some-route' }); spyOn(router, 'navigateByUrl'); @@ -174,7 +177,7 @@ describe('LoginComponent', () => { it('should update user preferences upon login', async () => { spyOn(userPreferences, 'setStoragePrefix').and.callThrough(); - spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve()); component.success.subscribe(() => { @@ -206,14 +209,14 @@ describe('LoginComponent', () => { }); it('should be changed back to the default after a failed login attempt', () => { - spyOn(authService, 'login').and.returnValue(throwError('Fake server error')); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(throwError('Fake server error')); loginWithCredentials('fake-wrong-username', 'fake-wrong-password'); expect(getLoginButtonText()).toEqual('LOGIN.BUTTON.LOGIN'); }); it('should be changed to the "welcome key" after a successful login attempt', () => { - spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); loginWithCredentials('fake-username', 'fake-password'); expect(getLoginButtonText()).toEqual('LOGIN.BUTTON.WELCOME'); @@ -295,12 +298,12 @@ describe('LoginComponent', () => { }); it('should be taken into consideration during login attempt', fakeAsync(() => { - spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); component.rememberMe = false; loginWithCredentials('fake-username', 'fake-password'); - expect(authService.login).toHaveBeenCalledWith('fake-username', 'fake-password', false); + expect(basicAlfrescoAuthService.login).toHaveBeenCalledWith('fake-username', 'fake-password', false); })); }); @@ -516,7 +519,7 @@ describe('LoginComponent', () => { }); it('should return CORS error when server CORS error occurs', (done) => { - spyOn(authService, 'login').and.returnValue(throwError({ + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(throwError({ error: { crossDomain: true, message: 'ERROR: the network is offline, Origin is not allowed by Access-Control-Allow-Origin' @@ -537,7 +540,7 @@ describe('LoginComponent', () => { }); it('should return CSRF error when server CSRF error occurs', fakeAsync(() => { - spyOn(authService, 'login') + spyOn(basicAlfrescoAuthService, 'login') .and.returnValue(throwError({ message: 'ERROR: Invalid CSRF-token', status: 403 })); component.error.subscribe(() => { @@ -552,7 +555,7 @@ describe('LoginComponent', () => { })); it('should return ECM read-only error when error occurs', fakeAsync(() => { - spyOn(authService, 'login') + spyOn(basicAlfrescoAuthService, 'login') .and.returnValue( throwError( { @@ -600,7 +603,7 @@ describe('LoginComponent', () => { }); it('should return success event after the login have succeeded', (done) => { - spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); expect(component.isError).toBe(false); @@ -616,7 +619,7 @@ describe('LoginComponent', () => { }); it('should emit success event after the login has succeeded and discard password', fakeAsync(() => { - spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' })); component.success.subscribe((event) => { fixture.detectChanges(); @@ -631,7 +634,7 @@ describe('LoginComponent', () => { })); it('should emit error event after the login has failed', fakeAsync(() => { - spyOn(authService, 'login').and.returnValue(throwError('Fake server error')); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(throwError('Fake server error')); component.error.subscribe((error) => { fixture.detectChanges(); diff --git a/lib/core/src/lib/login/components/login.component.ts b/lib/core/src/lib/login/components/login.component.ts index 86a7f15a40..4e2aeb266c 100644 --- a/lib/core/src/lib/login/components/login.component.ts +++ b/lib/core/src/lib/login/components/login.component.ts @@ -36,7 +36,7 @@ import { DomSanitizer, SafeStyle } from '@angular/platform-browser'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { BasicAlfrescoAuthService } from '../../auth/basic-auth/basic-alfresco-auth.service'; -import { OidcAuthenticationService } from "../../auth/services/oidc-authentication.service"; +import { OidcAuthenticationService } from '../../auth/services/oidc-authentication.service'; // eslint-disable-next-line no-shadow enum LoginSteps { diff --git a/lib/core/src/lib/snackbar-content/snackbar-content.component.spec.ts b/lib/core/src/lib/snackbar-content/snackbar-content.component.spec.ts index cc8a2703c7..d9bff92a83 100644 --- a/lib/core/src/lib/snackbar-content/snackbar-content.component.spec.ts +++ b/lib/core/src/lib/snackbar-content/snackbar-content.component.spec.ts @@ -16,12 +16,12 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { SnackbarContentComponent } from '@alfresco/adf-core'; import { MatIcon, MatIconModule } from '@angular/material/icon'; import { MAT_SNACK_BAR_DATA, MatSnackBarModule, MatSnackBarRef } from '@angular/material/snack-bar'; import { MatButtonModule } from '@angular/material/button'; import { By } from '@angular/platform-browser'; import { TranslateModule } from '@ngx-translate/core'; +import { SnackbarContentComponent } from './snackbar-content.component'; describe('SnackbarContentComponent', () => { let component: SnackbarContentComponent; diff --git a/lib/core/src/lib/viewer/components/download-prompt-dialog/download-prompt-dialog.component.spec.ts b/lib/core/src/lib/viewer/components/download-prompt-dialog/download-prompt-dialog.component.spec.ts index 0bb1578954..18bf0235ed 100644 --- a/lib/core/src/lib/viewer/components/download-prompt-dialog/download-prompt-dialog.component.spec.ts +++ b/lib/core/src/lib/viewer/components/download-prompt-dialog/download-prompt-dialog.component.spec.ts @@ -17,10 +17,12 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { CoreTestingModule, DownloadPromptDialogComponent, DownloadPromptActions } from '@alfresco/adf-core'; import { By } from '@angular/platform-browser'; import { MatDialogRef } from '@angular/material/dialog'; import { TranslateModule } from '@ngx-translate/core'; +import { DownloadPromptDialogComponent } from './download-prompt-dialog.component'; +import { CoreTestingModule } from '../../../testing/core.testing.module'; +import { DownloadPromptActions } from '../../models/download-prompt.actions'; const mockDialog = { close: jasmine.createSpy('close') diff --git a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts index 988be084c0..8df8d88e37 100644 --- a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts +++ b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts @@ -21,7 +21,7 @@ import { ContentModule, ContentNodeSelectorPanelComponent, DocumentListService, import { EventEmitter, NO_ERRORS_SCHEMA } from '@angular/core'; import { ProcessTestingModule } from '../../../testing/process.testing.module'; import { AttachFileWidgetDialogComponent } from './attach-file-widget-dialog.component'; -import { AuthenticationService, AlfrescoApiService } from '@alfresco/adf-core'; +import { AlfrescoApiService, BasicAlfrescoAuthService } from '@alfresco/adf-core'; import { AttachFileWidgetDialogComponentData } from './attach-file-widget-dialog-component.interface'; import { of, throwError } from 'rxjs'; import { By } from '@angular/platform-browser'; @@ -40,7 +40,7 @@ describe('AttachFileWidgetDialogComponent', () => { ecmHost: 'http://fakeUrl.com' }; let element: HTMLInputElement; - let authService: AuthenticationService; + let basicAlfrescoAuthService: BasicAlfrescoAuthService; let siteService: SitesService; let nodeService: NodesApiService; let documentListService: DocumentListService; @@ -66,7 +66,7 @@ describe('AttachFileWidgetDialogComponent', () => { fixture = TestBed.createComponent(AttachFileWidgetDialogComponent); widget = fixture.componentInstance; element = fixture.nativeElement; - authService = fixture.debugElement.injector.get(AuthenticationService); + basicAlfrescoAuthService = fixture.debugElement.injector.get(BasicAlfrescoAuthService); siteService = fixture.debugElement.injector.get(SitesService); nodeService = fixture.debugElement.injector.get(NodesApiService); documentListService = fixture.debugElement.injector.get(DocumentListService); @@ -106,7 +106,7 @@ describe('AttachFileWidgetDialogComponent', () => { }); it('should be able to login', (done) => { - spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket'})); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket'})); isLogged = true; let loginButton: HTMLButtonElement = element.querySelector('button[data-automation-id="attach-file-dialog-actions-login"]'); const usernameInput: HTMLInputElement = element.querySelector('#username'); @@ -173,7 +173,7 @@ describe('AttachFileWidgetDialogComponent', () => { describe('login only', () => { beforeEach(() => { - spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket'})); + spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket'})); spyOn(matDialogRef, 'close').and.callThrough(); fixture.detectChanges(); widget.data.loginOnly = true; @@ -192,7 +192,7 @@ describe('AttachFileWidgetDialogComponent', () => { usernameInput.dispatchEvent(new Event('input')); passwordInput.dispatchEvent(new Event('input')); loginButton.click(); - authService.onLogin.next('logged In'); + basicAlfrescoAuthService.onLogin.next('logged In'); fixture.detectChanges(); expect(matDialogRef.close).toHaveBeenCalled(); });