fix unit test

This commit is contained in:
eromano
2023-06-22 15:24:54 +02:00
parent 58ba5b730a
commit ccde807f0e
19 changed files with 154 additions and 191 deletions

View File

@@ -21,16 +21,11 @@ import { AppConfigService, AuthenticationService, StorageService, CoreTestingMod
import { Node } from '@alfresco/js-api'; import { Node } from '@alfresco/js-api';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
declare let jasmine: any;
describe('ContentService', () => { describe('ContentService', () => {
let contentService: ContentService; let contentService: ContentService;
let authService: AuthenticationService; let authService: AuthenticationService;
let storage: StorageService; let storage: StorageService;
let node: any;
const nodeId = 'fake-node-id';
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@@ -44,14 +39,6 @@ describe('ContentService', () => {
storage = TestBed.inject(StorageService); storage = TestBed.inject(StorageService);
storage.clear(); storage.clear();
node = {
entry: {
id: nodeId
}
};
jasmine.Ajax.install();
const appConfig: AppConfigService = TestBed.inject(AppConfigService); const appConfig: AppConfigService = TestBed.inject(AppConfigService);
appConfig.config = { appConfig.config = {
ecmHost: 'http://localhost:9876/ecm', 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', () => { describe('AllowableOperations', () => {
it('should hasAllowableOperations be false if allowableOperation is not present in the node', () => { it('should hasAllowableOperations be false if allowableOperation is not present in the node', () => {

View File

@@ -22,7 +22,7 @@ import {
HttpSentEvent, HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpUserEvent, HttpHeaders HttpSentEvent, HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpUserEvent, HttpHeaders
} from '@angular/common/http'; } from '@angular/common/http';
import { catchError, mergeMap } from 'rxjs/operators'; import { catchError, mergeMap } from 'rxjs/operators';
import { AuthenticationService } from "../services/authentication.service"; import { AuthenticationService } from '../services/authentication.service';
@Injectable() @Injectable()
export class AuthBearerInterceptor implements HttpInterceptor { export class AuthBearerInterceptor implements HttpInterceptor {

View File

@@ -23,10 +23,10 @@ import { ContentAuth } from './contentAuth';
import { ProcessAuth } from './processAuth'; import { ProcessAuth } from './processAuth';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { from, Observable } from 'rxjs'; import { from, Observable } from 'rxjs';
import { RedirectionModel } from "../index"; import { RedirectionModel } from '../models/redirection.model';
import { BaseAuthenticationService } from "../services/base-authentication.service"; import { BaseAuthenticationService } from '../services/base-authentication.service';
import { LogService } from "../../common"; import { LogService } from '../../common';
import { HttpHeaders } from "@angular/common/http"; import { HttpHeaders } from '@angular/common/http';
const REMEMBER_ME_COOKIE_KEY = 'ALFRESCO_REMEMBER_ME'; const REMEMBER_ME_COOKIE_KEY = 'ALFRESCO_REMEMBER_ME';
const REMEMBER_ME_UNTIL = 1000 * 60 * 60 * 24 * 30; const REMEMBER_ME_UNTIL = 1000 * 60 * 60 * 24 * 30;

View File

@@ -32,8 +32,9 @@ import { OauthConfigModel } from '../models/oauth-config.model';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { StorageService } from '../../common/services/storage.service'; import { StorageService } from '../../common/services/storage.service';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { BasicAlfrescoAuthService } from "../basic-auth/basic-alfresco-auth.service"; import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service';
import { OidcAuthenticationService } from "../services/oidc-authentication.service"; import { OidcAuthenticationService } from '../services/oidc-authentication.service';
export abstract class AuthGuardBase implements CanActivate, CanActivateChild { export abstract class AuthGuardBase implements CanActivate, CanActivateChild {

View File

@@ -23,11 +23,16 @@ import { RouterStateSnapshot, Router } from '@angular/router';
import { CoreTestingModule } from '../../testing/core.testing.module'; import { CoreTestingModule } from '../../testing/core.testing.module';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { TranslateModule } from '@ngx-translate/core'; 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', () => { describe('AuthGuardService BPM', () => {
let authGuard: AuthGuardBpm; let authGuard: AuthGuardBpm;
let authService: AuthenticationService; let authService: AuthenticationService;
let basicAlfrescoAuthService: BasicAlfrescoAuthService;
let oidcAuthenticationService: OidcAuthenticationService;
let router: Router; let router: Router;
let appConfigService: AppConfigService; let appConfigService: AppConfigService;
@@ -39,6 +44,7 @@ describe('AuthGuardService BPM', () => {
] ]
}); });
localStorage.clear(); localStorage.clear();
basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService);
authService = TestBed.inject(AuthenticationService); authService = TestBed.inject(AuthenticationService);
authGuard = TestBed.inject(AuthGuardBpm); authGuard = TestBed.inject(AuthGuardBpm);
router = TestBed.inject(Router); router = TestBed.inject(Router);
@@ -53,8 +59,8 @@ describe('AuthGuardService BPM', () => {
spyOn(router, 'navigateByUrl').and.stub(); spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false); spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true); spyOn(authService, 'isOauth').and.returnValue(true);
spyOn(authService, 'isPublicUrl').and.returnValue(false); spyOn(oidcAuthenticationService, 'isPublicUrl').and.returnValue(false);
spyOn(authService, 'ssoImplicitLogin').and.stub(); spyOn(oidcAuthenticationService, 'ssoImplicitLogin').and.stub();
appConfigService.config.oauth2 = { appConfigService.config.oauth2 = {
silentLogin: true, silentLogin: true,
@@ -69,7 +75,7 @@ describe('AuthGuardService BPM', () => {
const route = { url: 'abc' } as RouterStateSnapshot; const route = { url: 'abc' } as RouterStateSnapshot;
expect(await authGuard.canActivate(null, route)).toBeFalsy(); 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 () => { 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', () => { it('should set redirect url', () => {
spyOn(authService, 'setRedirect').and.callThrough(); spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub(); spyOn(router, 'navigateByUrl').and.stub();
const route = { url: 'some-url' } as RouterStateSnapshot; const route = { url: 'some-url' } as RouterStateSnapshot;
authGuard.canActivate(null, route); authGuard.canActivate(null, route);
expect(authService.setRedirect).toHaveBeenCalledWith({ expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
provider: 'BPM', url: 'some-url' 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', () => { it('should set redirect navigation commands with query params', () => {
spyOn(authService, 'setRedirect').and.callThrough(); spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub(); spyOn(router, 'navigateByUrl').and.stub();
const route = { url: 'some-url;q=123' } as RouterStateSnapshot; const route = { url: 'some-url;q=123' } as RouterStateSnapshot;
authGuard.canActivate(null, route); authGuard.canActivate(null, route);
expect(authService.setRedirect).toHaveBeenCalledWith({ expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
provider: 'BPM', url: 'some-url;q=123' 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', () => { it('should set redirect navigation commands with query params', () => {
spyOn(authService, 'setRedirect').and.callThrough(); spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub(); spyOn(router, 'navigateByUrl').and.stub();
const route = { url: '/' } as RouterStateSnapshot; const route = { url: '/' } as RouterStateSnapshot;
authGuard.canActivate(null, route); authGuard.canActivate(null, route);
expect(authService.setRedirect).toHaveBeenCalledWith({ expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
provider: 'BPM', url: '/' provider: 'BPM', url: '/'
}); });
expect(authService.getRedirect()).toEqual('/'); expect(basicAlfrescoAuthService.getRedirect()).toEqual('/');
}); });
it('should get redirect url from config if there is one configured', () => { it('should get redirect url from config if there is one configured', () => {
appConfigService.config.loginRoute = 'fakeLoginRoute'; appConfigService.config.loginRoute = 'fakeLoginRoute';
spyOn(authService, 'setRedirect').and.callThrough(); spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub(); spyOn(router, 'navigateByUrl').and.stub();
const route = { url: 'some-url' } as RouterStateSnapshot; const route = { url: 'some-url' } as RouterStateSnapshot;
authGuard.canActivate(null, route); authGuard.canActivate(null, route);
expect(authService.setRedirect).toHaveBeenCalledWith({ expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
provider: 'BPM', url: 'some-url' provider: 'BPM', url: 'some-url'
}); });
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url')); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url'));
@@ -187,13 +193,13 @@ describe('AuthGuardService BPM', () => {
spyOn(materialDialog, 'closeAll'); spyOn(materialDialog, 'closeAll');
spyOn(authService, 'setRedirect').and.callThrough(); spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub(); spyOn(router, 'navigateByUrl').and.stub();
const route = { url: 'some-url' } as RouterStateSnapshot; const route = { url: 'some-url' } as RouterStateSnapshot;
authGuard.canActivate(null, route); authGuard.canActivate(null, route);
expect(authService.setRedirect).toHaveBeenCalledWith({ expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
provider: 'BPM', url: 'some-url' provider: 'BPM', url: 'some-url'
}); });

View File

@@ -22,8 +22,8 @@ import { AuthenticationService } from '../services/authentication.service';
import { AuthGuardBase } from './auth-guard-base'; import { AuthGuardBase } from './auth-guard-base';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { StorageService } from '../../common/services/storage.service'; import { StorageService } from '../../common/services/storage.service';
import { BasicAlfrescoAuthService } from "../basic-auth/basic-alfresco-auth.service"; import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service';
import { OidcAuthenticationService } from "../services/oidc-authentication.service"; import { OidcAuthenticationService } from '../services/oidc-authentication.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'

View File

@@ -23,11 +23,15 @@ import { RouterStateSnapshot, Router } from '@angular/router';
import { CoreTestingModule } from '../../testing/core.testing.module'; import { CoreTestingModule } from '../../testing/core.testing.module';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { TranslateModule } from '@ngx-translate/core'; 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', () => { describe('AuthGuardService ECM', () => {
let authGuard: AuthGuardEcm; let authGuard: AuthGuardEcm;
let authService: AuthenticationService; let authService: AuthenticationService;
let basicAlfrescoAuthService: BasicAlfrescoAuthService;
let oidcAuthenticationService: OidcAuthenticationService;
let router: Router; let router: Router;
let appConfigService: AppConfigService; let appConfigService: AppConfigService;
@@ -39,6 +43,8 @@ describe('AuthGuardService ECM', () => {
] ]
}); });
localStorage.clear(); localStorage.clear();
oidcAuthenticationService = TestBed.inject(OidcAuthenticationService);
basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService);
authService = TestBed.inject(AuthenticationService); authService = TestBed.inject(AuthenticationService);
authGuard = TestBed.inject(AuthGuardEcm); authGuard = TestBed.inject(AuthGuardEcm);
router = TestBed.inject(Router); 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 () => { 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, 'isEcmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true); spyOn(authService, 'isOauth').and.returnValue(true);
spyOn(authService, 'isPublicUrl').and.returnValue(false); spyOn(oidcAuthenticationService, 'isPublicUrl').and.returnValue(false);
spyOn(authService, 'ssoImplicitLogin').and.stub(); spyOn(oidcAuthenticationService, 'ssoImplicitLogin').and.stub();
appConfigService.config.oauth2 = { appConfigService.config.oauth2 = {
silentLogin: true, silentLogin: true,
@@ -113,7 +119,7 @@ describe('AuthGuardService ECM', () => {
const route = {url : 'abc'} as RouterStateSnapshot; const route = {url : 'abc'} as RouterStateSnapshot;
expect(await authGuard.canActivate(null, route)).toBeFalsy(); 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 () => { 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', () => { it('should set redirect navigation commands', () => {
spyOn(authService, 'setRedirect').and.callThrough(); spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub(); spyOn(router, 'navigateByUrl').and.stub();
const route = { url: 'some-url' } as RouterStateSnapshot; const route = { url: 'some-url' } as RouterStateSnapshot;
authGuard.canActivate(null, route); authGuard.canActivate(null, route);
expect(authService.setRedirect).toHaveBeenCalledWith({ expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
provider: 'ECM', url: 'some-url' 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', () => { it('should set redirect navigation commands with query params', () => {
spyOn(authService, 'setRedirect').and.callThrough(); spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub(); spyOn(router, 'navigateByUrl').and.stub();
const route = { url: 'some-url;q=123' } as RouterStateSnapshot; const route = { url: 'some-url;q=123' } as RouterStateSnapshot;
authGuard.canActivate(null, route); authGuard.canActivate(null, route);
expect(authService.setRedirect).toHaveBeenCalledWith({ expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
provider: 'ECM', url: 'some-url;q=123' 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', () => { it('should set redirect navigation commands with query params', () => {
spyOn(authService, 'setRedirect').and.callThrough(); spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub(); spyOn(router, 'navigateByUrl').and.stub();
const route = { url: '/' } as RouterStateSnapshot; const route = { url: '/' } as RouterStateSnapshot;
authGuard.canActivate(null, route); authGuard.canActivate(null, route);
expect(authService.setRedirect).toHaveBeenCalledWith({ expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
provider: 'ECM', url: '/' provider: 'ECM', url: '/'
}); });
expect(authService.getRedirect()).toEqual('/'); expect(basicAlfrescoAuthService.getRedirect()).toEqual('/');
}); });
it('should get redirect url from config if there is one configured', () => { it('should get redirect url from config if there is one configured', () => {
appConfigService.config.loginRoute = 'fakeLoginRoute'; appConfigService.config.loginRoute = 'fakeLoginRoute';
spyOn(authService, 'setRedirect').and.callThrough(); spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub(); spyOn(router, 'navigateByUrl').and.stub();
const route = { url: 'some-url' } as RouterStateSnapshot; const route = { url: 'some-url' } as RouterStateSnapshot;
authGuard.canActivate(null, route); authGuard.canActivate(null, route);
expect(authService.setRedirect).toHaveBeenCalledWith({ expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
provider: 'ECM', url: 'some-url' provider: 'ECM', url: 'some-url'
}); });
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url')); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url'));
@@ -185,13 +191,13 @@ describe('AuthGuardService ECM', () => {
spyOn(materialDialog, 'closeAll'); spyOn(materialDialog, 'closeAll');
spyOn(authService, 'setRedirect').and.callThrough(); spyOn(basicAlfrescoAuthService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub(); spyOn(router, 'navigateByUrl').and.stub();
const route = { url: 'some-url' } as RouterStateSnapshot; const route = { url: 'some-url' } as RouterStateSnapshot;
authGuard.canActivate(null, route); authGuard.canActivate(null, route);
expect(authService.setRedirect).toHaveBeenCalledWith({ expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
provider: 'ECM', url: 'some-url' provider: 'ECM', url: 'some-url'
}); });

View File

@@ -24,8 +24,9 @@ import { AppConfigService } from '../../app-config/app-config.service';
import { AuthGuardBase } from './auth-guard-base'; import { AuthGuardBase } from './auth-guard-base';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { StorageService } from '../../common/services/storage.service'; import { StorageService } from '../../common/services/storage.service';
import { BasicAlfrescoAuthService } from "../basic-auth/basic-alfresco-auth.service"; import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service';
import { OidcAuthenticationService } from "../services/oidc-authentication.service"; import { OidcAuthenticationService } from '../services/oidc-authentication.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'

View File

@@ -23,6 +23,8 @@ import { AuthenticationService } from '../services/authentication.service';
import { CoreTestingModule } from '../../testing/core.testing.module'; import { CoreTestingModule } from '../../testing/core.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { StorageService } from '../../common/services/storage.service'; 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', () => { describe('AuthGuardService', () => {
let state; let state;
@@ -31,6 +33,8 @@ describe('AuthGuardService', () => {
let authGuard: AuthGuard; let authGuard: AuthGuard;
let storageService: StorageService; let storageService: StorageService;
let appConfigService: AppConfigService; let appConfigService: AppConfigService;
let basicAlfrescoAuthService: BasicAlfrescoAuthService;
let oidcAuthenticationService: OidcAuthenticationService;
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@@ -42,6 +46,8 @@ describe('AuthGuardService', () => {
localStorage.clear(); localStorage.clear();
state = { url: '' }; state = { url: '' };
authService = TestBed.inject(AuthenticationService); authService = TestBed.inject(AuthenticationService);
basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService);
oidcAuthenticationService = TestBed.inject(OidcAuthenticationService);
router = TestBed.inject(Router); router = TestBed.inject(Router);
authGuard = TestBed.inject(AuthGuard); authGuard = TestBed.inject(AuthGuard);
appConfigService = TestBed.inject(AppConfigService); 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 () => { 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, 'isLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true); spyOn(authService, 'isOauth').and.returnValue(true);
appConfigService.config.oauth2.silentLogin = true; appConfigService.config.oauth2.silentLogin = true;
expect(await authGuard.canActivate(null, state)).toBeFalsy(); expect(await authGuard.canActivate(null, state)).toBeFalsy();
expect(authService.ssoImplicitLogin).toHaveBeenCalledTimes(1); expect(oidcAuthenticationService.ssoImplicitLogin).toHaveBeenCalledTimes(1);
}); });
it('should set redirect url', async () => { it('should set redirect url', async () => {
@@ -124,11 +130,11 @@ describe('AuthGuardService', () => {
appConfigService.config.loginRoute = 'login'; appConfigService.config.loginRoute = 'login';
spyOn(router, 'navigateByUrl'); spyOn(router, 'navigateByUrl');
spyOn(authService, 'setRedirect'); spyOn(basicAlfrescoAuthService, 'setRedirect');
await authGuard.canActivate(null, state); await authGuard.canActivate(null, state);
expect(authService.setRedirect).toHaveBeenCalledWith({ expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
provider: 'ALL', url: 'some-url' provider: 'ALL', url: 'some-url'
}); });
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url')); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url'));
@@ -140,11 +146,11 @@ describe('AuthGuardService', () => {
appConfigService.config.provider = 'ALL'; appConfigService.config.provider = 'ALL';
spyOn(router, 'navigateByUrl'); spyOn(router, 'navigateByUrl');
spyOn(authService, 'setRedirect'); spyOn(basicAlfrescoAuthService, 'setRedirect');
await authGuard.canActivate(null, state); await authGuard.canActivate(null, state);
expect(authService.setRedirect).toHaveBeenCalledWith({ expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
provider: 'ALL', url: 'some-url;q=query' provider: 'ALL', url: 'some-url;q=query'
}); });
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=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'; appConfigService.config.loginRoute = 'fakeLoginRoute';
spyOn(router, 'navigateByUrl'); spyOn(router, 'navigateByUrl');
spyOn(authService, 'setRedirect'); spyOn(basicAlfrescoAuthService, 'setRedirect');
await authGuard.canActivate(null, state); await authGuard.canActivate(null, state);
expect(authService.setRedirect).toHaveBeenCalledWith({ expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
provider: 'ALL', url: 'some-url' provider: 'ALL', url: 'some-url'
}); });
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url')); expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url'));
@@ -169,11 +175,11 @@ describe('AuthGuardService', () => {
state.url = '/'; state.url = '/';
spyOn(router, 'navigateByUrl'); spyOn(router, 'navigateByUrl');
spyOn(authService, 'setRedirect'); spyOn(basicAlfrescoAuthService, 'setRedirect');
await authGuard.canActivate(null, state); await authGuard.canActivate(null, state);
expect(authService.setRedirect).toHaveBeenCalledWith({ expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
provider: 'ALL', url: '/' provider: 'ALL', url: '/'
}); });
}); });

View File

@@ -23,8 +23,9 @@ import { AuthGuardBase } from './auth-guard-base';
import { JwtHelperService } from '../services/jwt-helper.service'; import { JwtHelperService } from '../services/jwt-helper.service';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { StorageService } from '../../common/services/storage.service'; import { StorageService } from '../../common/services/storage.service';
import { BasicAlfrescoAuthService } from "../basic-auth/basic-alfresco-auth.service"; import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service';
import { OidcAuthenticationService } from "../services/oidc-authentication.service"; import { OidcAuthenticationService } from '../services/oidc-authentication.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'

View File

@@ -23,12 +23,14 @@ import { AppConfigService } from '../../app-config/app-config.service';
import { setupTestBed } from '../../testing/setup-test-bed'; import { setupTestBed } from '../../testing/setup-test-bed';
import { CoreTestingModule } from '../../testing/core.testing.module'; import { CoreTestingModule } from '../../testing/core.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service';
declare let jasmine: any; declare let jasmine: any;
describe('AuthenticationService', () => { describe('AuthenticationService', () => {
let apiService: AlfrescoApiService; let apiService: AlfrescoApiService;
let authService: AuthenticationService; let authService: AuthenticationService;
let basicAlfrescoAuthService: BasicAlfrescoAuthService;
let appConfigService: AppConfigService; let appConfigService: AppConfigService;
let cookie: CookieService; let cookie: CookieService;
@@ -44,6 +46,7 @@ describe('AuthenticationService', () => {
localStorage.clear(); localStorage.clear();
apiService = TestBed.inject(AlfrescoApiService); apiService = TestBed.inject(AlfrescoApiService);
authService = TestBed.inject(AuthenticationService); authService = TestBed.inject(AuthenticationService);
basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService);
cookie = TestBed.inject(CookieService); cookie = TestBed.inject(CookieService);
cookie.clear(); cookie.clear();
@@ -88,7 +91,7 @@ describe('AuthenticationService', () => {
it('should not require cookie service enabled for ECM check', () => { it('should not require cookie service enabled for ECM check', () => {
spyOn(cookie, 'isEnabled').and.returnValue(false); 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, 'isECMProvider').and.returnValue(true);
spyOn(authService, 'isOauth').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(false);
spyOn(apiService, 'getInstance').and.callThrough(); spyOn(apiService, 'getInstance').and.callThrough();
@@ -97,14 +100,9 @@ describe('AuthenticationService', () => {
expect(apiService.getInstance).toHaveBeenCalled(); 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', () => { it('should require remember me set for ECM check', () => {
spyOn(cookie, 'isEnabled').and.returnValue(true); 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, 'isECMProvider').and.returnValue(true);
spyOn(authService, 'isOauth').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(false);
spyOn(apiService, 'getInstance').and.callThrough(); spyOn(apiService, 'getInstance').and.callThrough();
@@ -114,9 +112,9 @@ describe('AuthenticationService', () => {
}); });
it('[ECM] should return an ECM ticket after the login done', (done) => { 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.isLoggedIn()).toBe(true);
expect(authService.getTicketEcm()).toEqual('fake-post-ticket'); expect(basicAlfrescoAuthService.getToken()).toEqual('fake-post-ticket');
expect(authService.isEcmLoggedIn()).toBe(true); expect(authService.isEcmLoggedIn()).toBe(true);
disposableLogin.unsubscribe(); disposableLogin.unsubscribe();
done(); done();
@@ -130,7 +128,7 @@ describe('AuthenticationService', () => {
}); });
it('[ECM] should login in the ECM if no provider are defined calling the login', fakeAsync(() => { 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); expect(loginResponse).toEqual(fakeECMLoginResponse);
disposableLogin.unsubscribe(); disposableLogin.unsubscribe();
}); });
@@ -143,10 +141,10 @@ describe('AuthenticationService', () => {
})); }));
it('[ECM] should return a ticket undefined after logout', fakeAsync(() => { 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(() => { const disposableLogout = authService.logout().subscribe(() => {
expect(authService.isLoggedIn()).toBe(false); expect(authService.isLoggedIn()).toBe(false);
expect(authService.getTicketEcm()).toBe(null); expect(authService.getToken()).toBe(null);
expect(authService.isEcmLoggedIn()).toBe(false); expect(authService.isEcmLoggedIn()).toBe(false);
disposableLogin.unsubscribe(); disposableLogin.unsubscribe();
disposableLogout.unsubscribe(); disposableLogout.unsubscribe();
@@ -170,21 +168,21 @@ describe('AuthenticationService', () => {
}); });
it('[ECM] should set/get redirectUrl when provider is ECM', () => { 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', () => { 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', () => { 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', () => { it('[ECM] should return isECMProvider true', () => {
@@ -214,7 +212,7 @@ describe('AuthenticationService', () => {
it('should require remember me set for BPM check', () => { it('should require remember me set for BPM check', () => {
spyOn(cookie, 'isEnabled').and.returnValue(true); 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, 'isBPMProvider').and.returnValue(true);
spyOn(authService, 'isOauth').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(false);
spyOn(apiService, 'getInstance').and.callThrough(); spyOn(apiService, 'getInstance').and.callThrough();
@@ -223,14 +221,9 @@ describe('AuthenticationService', () => {
expect(apiService.getInstance).not.toHaveBeenCalled(); 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', () => { it('should not require cookie service enabled for BPM check', () => {
spyOn(cookie, 'isEnabled').and.returnValue(false); 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(authService, 'isBPMProvider').and.returnValue(true);
spyOn(apiService, 'getInstance').and.callThrough(); spyOn(apiService, 'getInstance').and.callThrough();
@@ -239,10 +232,10 @@ describe('AuthenticationService', () => {
}); });
it('[BPM] should return an BPM ticket after the login done', (done) => { 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); expect(authService.isLoggedIn()).toBe(true);
// cspell: disable-next // cspell: disable-next
expect(authService.getTicketBpm()).toEqual('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk'); expect(authService.getToken()).toEqual('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk');
expect(authService.isBpmLoggedIn()).toBe(true); expect(authService.isBpmLoggedIn()).toBe(true);
disposableLogin.unsubscribe(); disposableLogin.unsubscribe();
done(); done();
@@ -255,10 +248,10 @@ describe('AuthenticationService', () => {
}); });
it('[BPM] should return a ticket undefined after logout', (done) => { 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(() => { const disposableLogout = authService.logout().subscribe(() => {
expect(authService.isLoggedIn()).toBe(false); expect(authService.isLoggedIn()).toBe(false);
expect(authService.getTicketBpm()).toBe(null); expect(authService.getToken()).toBe(null);
expect(authService.isBpmLoggedIn()).toBe(false); expect(authService.isBpmLoggedIn()).toBe(false);
disposableLogout.unsubscribe(); disposableLogout.unsubscribe();
disposableLogin.unsubscribe(); disposableLogin.unsubscribe();
@@ -281,7 +274,7 @@ describe('AuthenticationService', () => {
}, },
(err: any) => { (err: any) => {
expect(err).toBeDefined(); expect(err).toBeDefined();
expect(authService.getTicketBpm()).toBe(undefined); expect(authService.getToken()).toBe(undefined);
done(); done();
}); });
@@ -291,21 +284,21 @@ describe('AuthenticationService', () => {
}); });
it('[BPM] should set/get redirectUrl when provider is BPM', () => { 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', () => { 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', () => { 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', () => { 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) => { 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']).not.toBeUndefined();
expect(cookie['ALFRESCO_REMEMBER_ME'].expiration).toBeNull(); expect(cookie['ALFRESCO_REMEMBER_ME'].expiration).toBeNull();
disposableLogin.unsubscribe(); disposableLogin.unsubscribe();
@@ -345,7 +338,7 @@ describe('AuthenticationService', () => {
}); });
it('[ECM] should save the remember me cookie as a persistent cookie after successful login', (done) => { 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']).not.toBeUndefined();
expect(cookie['ALFRESCO_REMEMBER_ME'].expiration).not.toBeNull(); expect(cookie['ALFRESCO_REMEMBER_ME'].expiration).not.toBeNull();
disposableLogin.unsubscribe(); disposableLogin.unsubscribe();
@@ -361,7 +354,7 @@ describe('AuthenticationService', () => {
}); });
it('[ECM] should not save the remember me cookie after failed login', (done) => { 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(); 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) => { 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.isLoggedIn()).toBe(true);
expect(authService.getTicketEcm()).toEqual('fake-post-ticket'); expect(authService.getToken()).toEqual('fake-post-ticket');
// cspell: disable-next // cspell: disable-next
expect(authService.getTicketBpm()).toEqual('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk'); expect(authService.getToken()).toEqual('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk');
expect(authService.isBpmLoggedIn()).toBe(true); expect(authService.isBpmLoggedIn()).toBe(true);
expect(authService.isEcmLoggedIn()).toBe(true); expect(authService.isEcmLoggedIn()).toBe(true);
disposableLogin.unsubscribe(); disposableLogin.unsubscribe();
@@ -417,13 +410,13 @@ describe('AuthenticationService', () => {
}); });
it('[ALL] should return login fail if only ECM call fail', (done) => { 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.isLoggedIn()).toBe(false, 'isLoggedIn');
expect(authService.getTicketEcm()).toBe(null, 'getTicketEcm'); expect(authService.getToken()).toBe(null, 'getTicketEcm');
// cspell: disable-next // cspell: disable-next
expect(authService.getTicketBpm()).toBe(null, 'getTicketBpm'); expect(authService.getToken()).toBe(null, 'getTicketBpm');
expect(authService.isEcmLoggedIn()).toBe(false, 'isEcmLoggedIn'); expect(authService.isEcmLoggedIn()).toBe(false, 'isEcmLoggedIn');
disposableLogin.unsubscribe(); disposableLogin.unsubscribe();
done(); done();
@@ -439,12 +432,12 @@ describe('AuthenticationService', () => {
}); });
it('[ALL] should return login fail if only BPM call fail', (done) => { 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.isLoggedIn()).toBe(false);
expect(authService.getTicketEcm()).toBe(null); expect(authService.getToken()).toBe(null);
expect(authService.getTicketBpm()).toBe(null); expect(authService.getToken()).toBe(null);
expect(authService.isBpmLoggedIn()).toBe(false); expect(authService.isBpmLoggedIn()).toBe(false);
disposableLogin.unsubscribe(); disposableLogin.unsubscribe();
done(); done();
@@ -462,12 +455,12 @@ describe('AuthenticationService', () => {
}); });
it('[ALL] should return ticket undefined when the credentials are wrong', (done) => { 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.isLoggedIn()).toBe(false);
expect(authService.getTicketEcm()).toBe(null); expect(authService.getToken()).toBe(null);
expect(authService.getTicketBpm()).toBe(null); expect(authService.getToken()).toBe(null);
expect(authService.isBpmLoggedIn()).toBe(false); expect(authService.isBpmLoggedIn()).toBe(false);
expect(authService.isEcmLoggedIn()).toBe(false); expect(authService.isEcmLoggedIn()).toBe(false);
disposableLogin.unsubscribe(); 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', () => { it('[ALL] should return isECMProvider false', () => {
expect(authService.isECMProvider()).toBe(false); expect(authService.isECMProvider()).toBe(false);
}); });

View File

@@ -27,8 +27,8 @@ import { JwtHelperService } from './jwt-helper.service';
import { LogService } from '../../common/services/log.service'; import { LogService } from '../../common/services/log.service';
import { AuthConfigService } from '../oidc/auth-config.service'; import { AuthConfigService } from '../oidc/auth-config.service';
import { AuthService } from '../oidc/auth.service'; import { AuthService } from '../oidc/auth.service';
import { Minimatch } from "minimatch"; import { Minimatch } from 'minimatch';
import { HttpHeaders } from "@angular/common/http"; import { HttpHeaders } from '@angular/common/http';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'

View File

@@ -25,7 +25,7 @@ import { CoreTestingModule } from '../../../testing/core.testing.module';
import { ClipboardService } from '../../../clipboard/clipboard.service'; import { ClipboardService } from '../../../clipboard/clipboard.service';
import { CardViewDatetimeItemModel } from '../../models/card-view-datetimeitem.model'; import { CardViewDatetimeItemModel } from '../../models/card-view-datetimeitem.model';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { AppConfigService } from '@alfresco/adf-core'; import { AppConfigService } from '../../../app-config/app-config.service';
describe('CardViewDateItemComponent', () => { describe('CardViewDateItemComponent', () => {

View File

@@ -16,11 +16,11 @@
*/ */
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AuthenticationService } from '../../auth/services/authentication.service';
import { LoginDialogPanelComponent } from './login-dialog-panel.component'; import { LoginDialogPanelComponent } from './login-dialog-panel.component';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { CoreTestingModule } from '../../testing/core.testing.module'; import { CoreTestingModule } from '../../testing/core.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { BasicAlfrescoAuthService } from '../../auth/basic-auth/basic-alfresco-auth.service';
describe('LoginDialogPanelComponent', () => { describe('LoginDialogPanelComponent', () => {
let component: LoginDialogPanelComponent; let component: LoginDialogPanelComponent;
@@ -28,7 +28,7 @@ describe('LoginDialogPanelComponent', () => {
let element: HTMLElement; let element: HTMLElement;
let usernameInput: HTMLInputElement; let usernameInput: HTMLInputElement;
let passwordInput: HTMLInputElement; let passwordInput: HTMLInputElement;
let authService: AuthenticationService; let basicAlfrescoAuthService: BasicAlfrescoAuthService;
beforeEach(async () => { beforeEach(async () => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@@ -40,7 +40,6 @@ describe('LoginDialogPanelComponent', () => {
fixture = TestBed.createComponent(LoginDialogPanelComponent); fixture = TestBed.createComponent(LoginDialogPanelComponent);
element = fixture.nativeElement; element = fixture.nativeElement;
component = fixture.componentInstance; component = fixture.componentInstance;
authService = TestBed.inject(AuthenticationService);
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
@@ -76,7 +75,7 @@ describe('LoginDialogPanelComponent', () => {
expect(event.token.ticket).toBe('ticket'); expect(event.token.ticket).toBe('ticket');
done(); 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'); loginWithCredentials('fake-username', 'fake-password');
}); });

View File

@@ -29,6 +29,7 @@ import { of, throwError } from 'rxjs';
import { AlfrescoApiService } from '../../services/alfresco-api.service'; import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { CoreTestingModule } from '../../testing/core.testing.module'; import { CoreTestingModule } from '../../testing/core.testing.module';
import { LogService } from '../../common/services/log.service'; import { LogService } from '../../common/services/log.service';
import { BasicAlfrescoAuthService } from '../../auth/basic-auth/basic-alfresco-auth.service';
describe('LoginComponent', () => { describe('LoginComponent', () => {
let component: LoginComponent; let component: LoginComponent;
@@ -39,6 +40,7 @@ describe('LoginComponent', () => {
let userPreferences: UserPreferencesService; let userPreferences: UserPreferencesService;
let appConfigService: AppConfigService; let appConfigService: AppConfigService;
let alfrescoApiService: AlfrescoApiService; let alfrescoApiService: AlfrescoApiService;
let basicAlfrescoAuthService: BasicAlfrescoAuthService;
let usernameInput; let usernameInput;
let passwordInput; let passwordInput;
@@ -69,6 +71,7 @@ describe('LoginComponent', () => {
component.showRememberMe = true; component.showRememberMe = true;
component.showLoginActions = true; component.showLoginActions = true;
basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService);
authService = TestBed.inject(AuthenticationService); authService = TestBed.inject(AuthenticationService);
router = TestBed.inject(Router); router = TestBed.inject(Router);
userPreferences = TestBed.inject(UserPreferencesService); userPreferences = TestBed.inject(UserPreferencesService);
@@ -111,7 +114,7 @@ describe('LoginComponent', () => {
}); });
it('should redirect to route on successful login', () => { it('should redirect to route on successful login', () => {
spyOn(authService, 'login').and.returnValue( spyOn(basicAlfrescoAuthService, 'login').and.returnValue(
of({ type: 'type', ticket: 'ticket' }) of({ type: 'type', ticket: 'ticket' })
); );
const redirect = '/home'; const redirect = '/home';
@@ -161,10 +164,10 @@ describe('LoginComponent', () => {
appConfigService.config = {}; appConfigService.config = {};
appConfigService.config.providers = 'ECM'; 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'; const redirect = '/home';
component.successRoute = redirect; component.successRoute = redirect;
authService.setRedirect({ provider: 'ECM', url: 'some-route' }); basicAlfrescoAuthService.setRedirect({ provider: 'ECM', url: 'some-route' });
spyOn(router, 'navigateByUrl'); spyOn(router, 'navigateByUrl');
@@ -174,7 +177,7 @@ describe('LoginComponent', () => {
it('should update user preferences upon login', async () => { it('should update user preferences upon login', async () => {
spyOn(userPreferences, 'setStoragePrefix').and.callThrough(); 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()); spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve());
component.success.subscribe(() => { component.success.subscribe(() => {
@@ -206,14 +209,14 @@ describe('LoginComponent', () => {
}); });
it('should be changed back to the default after a failed login attempt', () => { 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'); loginWithCredentials('fake-wrong-username', 'fake-wrong-password');
expect(getLoginButtonText()).toEqual('LOGIN.BUTTON.LOGIN'); expect(getLoginButtonText()).toEqual('LOGIN.BUTTON.LOGIN');
}); });
it('should be changed to the "welcome key" after a successful login attempt', () => { 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'); loginWithCredentials('fake-username', 'fake-password');
expect(getLoginButtonText()).toEqual('LOGIN.BUTTON.WELCOME'); expect(getLoginButtonText()).toEqual('LOGIN.BUTTON.WELCOME');
@@ -295,12 +298,12 @@ describe('LoginComponent', () => {
}); });
it('should be taken into consideration during login attempt', fakeAsync(() => { 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; component.rememberMe = false;
loginWithCredentials('fake-username', 'fake-password'); 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) => { it('should return CORS error when server CORS error occurs', (done) => {
spyOn(authService, 'login').and.returnValue(throwError({ spyOn(basicAlfrescoAuthService, 'login').and.returnValue(throwError({
error: { error: {
crossDomain: true, crossDomain: true,
message: 'ERROR: the network is offline, Origin is not allowed by Access-Control-Allow-Origin' 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(() => { 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 })); .and.returnValue(throwError({ message: 'ERROR: Invalid CSRF-token', status: 403 }));
component.error.subscribe(() => { component.error.subscribe(() => {
@@ -552,7 +555,7 @@ describe('LoginComponent', () => {
})); }));
it('should return ECM read-only error when error occurs', fakeAsync(() => { it('should return ECM read-only error when error occurs', fakeAsync(() => {
spyOn(authService, 'login') spyOn(basicAlfrescoAuthService, 'login')
.and.returnValue( .and.returnValue(
throwError( throwError(
{ {
@@ -600,7 +603,7 @@ describe('LoginComponent', () => {
}); });
it('should return success event after the login have succeeded', (done) => { 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); 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(() => { 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) => { component.success.subscribe((event) => {
fixture.detectChanges(); fixture.detectChanges();
@@ -631,7 +634,7 @@ describe('LoginComponent', () => {
})); }));
it('should emit error event after the login has failed', fakeAsync(() => { 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) => { component.error.subscribe((error) => {
fixture.detectChanges(); fixture.detectChanges();

View File

@@ -36,7 +36,7 @@ import { DomSanitizer, SafeStyle } from '@angular/platform-browser';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { BasicAlfrescoAuthService } from '../../auth/basic-auth/basic-alfresco-auth.service'; 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 // eslint-disable-next-line no-shadow
enum LoginSteps { enum LoginSteps {

View File

@@ -16,12 +16,12 @@
*/ */
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SnackbarContentComponent } from '@alfresco/adf-core';
import { MatIcon, MatIconModule } from '@angular/material/icon'; import { MatIcon, MatIconModule } from '@angular/material/icon';
import { MAT_SNACK_BAR_DATA, MatSnackBarModule, MatSnackBarRef } from '@angular/material/snack-bar'; import { MAT_SNACK_BAR_DATA, MatSnackBarModule, MatSnackBarRef } from '@angular/material/snack-bar';
import { MatButtonModule } from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { SnackbarContentComponent } from './snackbar-content.component';
describe('SnackbarContentComponent', () => { describe('SnackbarContentComponent', () => {
let component: SnackbarContentComponent; let component: SnackbarContentComponent;

View File

@@ -17,10 +17,12 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CoreTestingModule, DownloadPromptDialogComponent, DownloadPromptActions } from '@alfresco/adf-core';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { MatDialogRef } from '@angular/material/dialog'; import { MatDialogRef } from '@angular/material/dialog';
import { TranslateModule } from '@ngx-translate/core'; 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 = { const mockDialog = {
close: jasmine.createSpy('close') close: jasmine.createSpy('close')

View File

@@ -21,7 +21,7 @@ import { ContentModule, ContentNodeSelectorPanelComponent, DocumentListService,
import { EventEmitter, NO_ERRORS_SCHEMA } from '@angular/core'; import { EventEmitter, NO_ERRORS_SCHEMA } from '@angular/core';
import { ProcessTestingModule } from '../../../testing/process.testing.module'; import { ProcessTestingModule } from '../../../testing/process.testing.module';
import { AttachFileWidgetDialogComponent } from './attach-file-widget-dialog.component'; 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 { AttachFileWidgetDialogComponentData } from './attach-file-widget-dialog-component.interface';
import { of, throwError } from 'rxjs'; import { of, throwError } from 'rxjs';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
@@ -40,7 +40,7 @@ describe('AttachFileWidgetDialogComponent', () => {
ecmHost: 'http://fakeUrl.com' ecmHost: 'http://fakeUrl.com'
}; };
let element: HTMLInputElement; let element: HTMLInputElement;
let authService: AuthenticationService; let basicAlfrescoAuthService: BasicAlfrescoAuthService;
let siteService: SitesService; let siteService: SitesService;
let nodeService: NodesApiService; let nodeService: NodesApiService;
let documentListService: DocumentListService; let documentListService: DocumentListService;
@@ -66,7 +66,7 @@ describe('AttachFileWidgetDialogComponent', () => {
fixture = TestBed.createComponent(AttachFileWidgetDialogComponent); fixture = TestBed.createComponent(AttachFileWidgetDialogComponent);
widget = fixture.componentInstance; widget = fixture.componentInstance;
element = fixture.nativeElement; element = fixture.nativeElement;
authService = fixture.debugElement.injector.get(AuthenticationService); basicAlfrescoAuthService = fixture.debugElement.injector.get(BasicAlfrescoAuthService);
siteService = fixture.debugElement.injector.get(SitesService); siteService = fixture.debugElement.injector.get(SitesService);
nodeService = fixture.debugElement.injector.get(NodesApiService); nodeService = fixture.debugElement.injector.get(NodesApiService);
documentListService = fixture.debugElement.injector.get(DocumentListService); documentListService = fixture.debugElement.injector.get(DocumentListService);
@@ -106,7 +106,7 @@ describe('AttachFileWidgetDialogComponent', () => {
}); });
it('should be able to login', (done) => { 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; isLogged = true;
let loginButton: HTMLButtonElement = element.querySelector('button[data-automation-id="attach-file-dialog-actions-login"]'); let loginButton: HTMLButtonElement = element.querySelector('button[data-automation-id="attach-file-dialog-actions-login"]');
const usernameInput: HTMLInputElement = element.querySelector('#username'); const usernameInput: HTMLInputElement = element.querySelector('#username');
@@ -173,7 +173,7 @@ describe('AttachFileWidgetDialogComponent', () => {
describe('login only', () => { describe('login only', () => {
beforeEach(() => { 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(); spyOn(matDialogRef, 'close').and.callThrough();
fixture.detectChanges(); fixture.detectChanges();
widget.data.loginOnly = true; widget.data.loginOnly = true;
@@ -192,7 +192,7 @@ describe('AttachFileWidgetDialogComponent', () => {
usernameInput.dispatchEvent(new Event('input')); usernameInput.dispatchEvent(new Event('input'));
passwordInput.dispatchEvent(new Event('input')); passwordInput.dispatchEvent(new Event('input'));
loginButton.click(); loginButton.click();
authService.onLogin.next('logged In'); basicAlfrescoAuthService.onLogin.next('logged In');
fixture.detectChanges(); fixture.detectChanges();
expect(matDialogRef.close).toHaveBeenCalled(); expect(matDialogRef.close).toHaveBeenCalled();
}); });