mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
fix unit test
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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;
|
||||
|
@@ -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 {
|
||||
|
||||
|
@@ -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'
|
||||
});
|
||||
|
||||
|
@@ -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'
|
||||
|
@@ -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'
|
||||
});
|
||||
|
||||
|
@@ -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'
|
||||
|
@@ -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: '/'
|
||||
});
|
||||
});
|
||||
|
@@ -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'
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -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'
|
||||
|
@@ -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', () => {
|
||||
|
||||
|
@@ -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');
|
||||
});
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -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 {
|
||||
|
@@ -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;
|
||||
|
@@ -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')
|
||||
|
Reference in New Issue
Block a user