mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[MNT-21636] Use URLTree for redirect (#6691)
* use URLTree for redirect * use always urltree * fix e2e * fix
This commit is contained in:
@@ -39,13 +39,11 @@ import CONSTANTS = require('../../util/constants');
|
|||||||
describe('Permissions Component', () => {
|
describe('Permissions Component', () => {
|
||||||
|
|
||||||
const apiService = new ApiService();
|
const apiService = new ApiService();
|
||||||
|
const uploadActions = new UploadActions(apiService);
|
||||||
|
|
||||||
const loginPage = new LoginPage();
|
const loginPage = new LoginPage();
|
||||||
const contentServicesPage = new ContentServicesPage();
|
const contentServicesPage = new ContentServicesPage();
|
||||||
const permissionsPage = new PermissionsPage();
|
const permissionsPage = new PermissionsPage();
|
||||||
const uploadActions = new UploadActions(apiService);
|
|
||||||
|
|
||||||
const contentList = contentServicesPage.getDocumentList();
|
|
||||||
|
|
||||||
const viewerPage = new ViewerPage();
|
const viewerPage = new ViewerPage();
|
||||||
const navigationBarPage = new NavigationBarPage();
|
const navigationBarPage = new NavigationBarPage();
|
||||||
const metadataViewPage = new MetadataViewPage();
|
const metadataViewPage = new MetadataViewPage();
|
||||||
@@ -53,6 +51,8 @@ describe('Permissions Component', () => {
|
|||||||
const uploadDialog = new UploadDialogPage();
|
const uploadDialog = new UploadDialogPage();
|
||||||
const versionManagePage = new VersionManagePage();
|
const versionManagePage = new VersionManagePage();
|
||||||
|
|
||||||
|
const contentList = contentServicesPage.getDocumentList();
|
||||||
|
|
||||||
let publicSite, privateSite, folderName;
|
let publicSite, privateSite, folderName;
|
||||||
|
|
||||||
const fileModel = new FileModel({
|
const fileModel = new FileModel({
|
||||||
|
@@ -75,12 +75,12 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
|
|||||||
return this.canActivate(route, state);
|
return this.canActivate(route, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async redirectSSOSuccessURL(): Promise<boolean> {
|
protected async redirectSSOSuccessURL(): Promise<boolean | UrlTree> {
|
||||||
const redirectFragment = this.storageService.getItem('loginFragment');
|
const redirectFragment = this.storageService.getItem('loginFragment');
|
||||||
|
|
||||||
if (redirectFragment && this.getLoginRoute() !== redirectFragment) {
|
if (redirectFragment && this.getLoginRoute() !== redirectFragment) {
|
||||||
this.storageService.removeItem('loginFragment');
|
this.storageService.removeItem('loginFragment');
|
||||||
return this.navigate(redirectFragment);
|
return this.router.parseUrl(redirectFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -90,7 +90,7 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
|
|||||||
return !!this.storageService.getItem('loginFragment');
|
return !!this.storageService.getItem('loginFragment');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async redirectToUrl(url: string): Promise<boolean> {
|
protected async redirectToUrl(url: string): Promise<boolean | UrlTree> {
|
||||||
let urlToRedirect = `/${this.getLoginRoute()}`;
|
let urlToRedirect = `/${this.getLoginRoute()}`;
|
||||||
|
|
||||||
if (!this.authenticationService.isOauth()) {
|
if (!this.authenticationService.isOauth()) {
|
||||||
@@ -110,9 +110,9 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected navigate(url: string): Promise<boolean> {
|
protected navigate(url: string): UrlTree {
|
||||||
this.dialog.closeAll();
|
this.dialog.closeAll();
|
||||||
return this.router.navigateByUrl(url);
|
return this.router.parseUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getOauthConfig(): OauthConfigModel {
|
protected getOauthConfig(): OauthConfigModel {
|
||||||
|
@@ -95,7 +95,7 @@ describe('AuthGuardService BPM', () => {
|
|||||||
spyOn(router, 'navigateByUrl').and.stub();
|
spyOn(router, 'navigateByUrl').and.stub();
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||||
|
|
||||||
expect(await authGuard.canActivate(null, route)).toBeFalsy();
|
expect(await authGuard.canActivate(null, route)).toEqual(router.parseUrl('/login?redirectUrl=some-url'));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('if the alfresco js api is NOT logged in should trigger a redirect event', async(async () => {
|
it('if the alfresco js api is NOT logged in should trigger a redirect event', async(async () => {
|
||||||
@@ -105,8 +105,7 @@ describe('AuthGuardService BPM', () => {
|
|||||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||||
|
|
||||||
expect(await authGuard.canActivate(null, route)).toBeFalsy();
|
expect(await authGuard.canActivate(null, route)).toEqual(router.parseUrl('/login?redirectUrl=some-url'));
|
||||||
expect(router.navigateByUrl).toHaveBeenCalledWith('/login?redirectUrl=some-url');
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async(async () => {
|
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async(async () => {
|
||||||
@@ -116,22 +115,20 @@ describe('AuthGuardService BPM', () => {
|
|||||||
appConfigService.config.oauth2.silentLogin = false;
|
appConfigService.config.oauth2.silentLogin = false;
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||||
|
|
||||||
expect(await authGuard.canActivate(null, route)).toBeFalsy();
|
expect(await authGuard.canActivate(null, route)).toEqual(router.parseUrl('/login'));
|
||||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(async () => {
|
it('should redirect to login url if NOT you are not logged in and silentLogin is false', async(async () => {
|
||||||
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);
|
||||||
appConfigService.config.oauth2.silentLogin = undefined;
|
appConfigService.config.oauth2.silentLogin = undefined;
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||||
|
|
||||||
expect(await authGuard.canActivate(null, route)).toBeFalsy();
|
expect(await authGuard.canActivate(null, route)).toEqual(router.parseUrl('/login'));
|
||||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should set redirect url', async(() => {
|
it('should set redirect url', async(async () => {
|
||||||
spyOn(authService, 'setRedirect').and.callThrough();
|
spyOn(authService, 'setRedirect').and.callThrough();
|
||||||
spyOn(router, 'navigateByUrl').and.stub();
|
spyOn(router, 'navigateByUrl').and.stub();
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||||
@@ -170,18 +167,13 @@ describe('AuthGuardService BPM', () => {
|
|||||||
expect(authService.getRedirect()).toEqual('/');
|
expect(authService.getRedirect()).toEqual('/');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should get redirect url from config if there is one configured', async(() => {
|
it('should get redirect url from config if there is one configured', async(async () => {
|
||||||
appConfigService.config.loginRoute = 'fakeLoginRoute';
|
appConfigService.config.loginRoute = 'fakeLoginRoute';
|
||||||
spyOn(authService, 'setRedirect').and.callThrough();
|
spyOn(authService, 'setRedirect').and.callThrough();
|
||||||
spyOn(router, 'navigateByUrl').and.stub();
|
spyOn(router, 'navigateByUrl').and.stub();
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||||
|
|
||||||
authGuard.canActivate(null, route);
|
expect(await authGuard.canActivate(null, route)).toEqual(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url'));
|
||||||
|
|
||||||
expect(authService.setRedirect).toHaveBeenCalledWith({
|
|
||||||
provider: 'BPM', url: 'some-url'
|
|
||||||
});
|
|
||||||
expect(router.navigateByUrl).toHaveBeenCalledWith('/fakeLoginRoute?redirectUrl=some-url');
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should to close the material dialog if is redirect to the login', () => {
|
it('should to close the material dialog if is redirect to the login', () => {
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { ActivatedRouteSnapshot, Router } from '@angular/router';
|
import { ActivatedRouteSnapshot, Router, UrlTree } from '@angular/router';
|
||||||
import { AppConfigService } from '../app-config/app-config.service';
|
import { AppConfigService } from '../app-config/app-config.service';
|
||||||
import { AuthenticationService } from './authentication.service';
|
import { AuthenticationService } from './authentication.service';
|
||||||
import { AuthGuardBase } from './auth-guard-base';
|
import { AuthGuardBase } from './auth-guard-base';
|
||||||
@@ -36,7 +36,7 @@ export class AuthGuardBpm extends AuthGuardBase {
|
|||||||
super(authenticationService, router, appConfigService, dialog, storageService);
|
super(authenticationService, router, appConfigService, dialog, storageService);
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkLogin(_: ActivatedRouteSnapshot, redirectUrl: string): Promise<boolean> {
|
async checkLogin(_: ActivatedRouteSnapshot, redirectUrl: string): Promise<boolean | UrlTree> {
|
||||||
if (this.authenticationService.isBpmLoggedIn() || this.withCredentials) {
|
if (this.authenticationService.isBpmLoggedIn() || this.withCredentials) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -51,53 +51,51 @@ describe('AuthGuardService ECM', () => {
|
|||||||
appConfigService.config.oauth2 = {};
|
appConfigService.config.oauth2 = {};
|
||||||
});
|
});
|
||||||
|
|
||||||
it('if the alfresco js api is logged in should canActivate be true', async(async() => {
|
it('if the alfresco js api is logged in should canActivate be true', async(async () => {
|
||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(true);
|
spyOn(authService, 'isEcmLoggedIn').and.returnValue(true);
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'some-url'};
|
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||||
|
|
||||||
expect(await authGuard.canActivate(null, route)).toBeTruthy();
|
expect(await authGuard.canActivate(null, route)).toBeTruthy();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async(async() => {
|
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async(async () => {
|
||||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
|
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
|
||||||
appConfigService.config.auth.withCredentials = true;
|
appConfigService.config.auth.withCredentials = true;
|
||||||
|
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'some-url'};
|
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||||
|
|
||||||
expect(await authGuard.canActivate(null, route)).toBeTruthy();
|
expect(await authGuard.canActivate(null, route)).toBeTruthy();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('if the alfresco js api is NOT logged in should canActivate be false', async(async() => {
|
it('if the alfresco js api is NOT logged in should canActivate be false', async(async () => {
|
||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
||||||
spyOn(router, 'navigateByUrl').and.stub();
|
spyOn(router, 'navigateByUrl').and.stub();
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||||
|
|
||||||
expect(await authGuard.canActivate(null, route)).toBeFalsy();
|
expect(await authGuard.canActivate(null, route)).toEqual(router.parseUrl('/login?redirectUrl=some-url'));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('if the alfresco js api is NOT logged in should trigger a redirect event', async(async() => {
|
it('if the alfresco js api is NOT logged in should trigger a redirect event', async(async () => {
|
||||||
appConfigService.config.loginRoute = 'login';
|
appConfigService.config.loginRoute = 'login';
|
||||||
|
|
||||||
spyOn(router, 'navigateByUrl');
|
spyOn(router, 'navigateByUrl');
|
||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'some-url'};
|
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||||
|
|
||||||
expect(await authGuard.canActivate(null, route)).toBeFalsy();
|
expect(await authGuard.canActivate(null, route)).toEqual(router.parseUrl('/login?redirectUrl=some-url'));
|
||||||
expect(router.navigateByUrl).toHaveBeenCalledWith('/login?redirectUrl=some-url');
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async(async() => {
|
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async(async () => {
|
||||||
spyOn(router, 'navigateByUrl').and.stub();
|
spyOn(router, 'navigateByUrl').and.stub();
|
||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||||
appConfigService.config.oauth2.silentLogin = false;
|
appConfigService.config.oauth2.silentLogin = false;
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'some-url'};
|
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||||
|
|
||||||
expect(await authGuard.canActivate(null, route)).toBeFalsy();
|
expect(await authGuard.canActivate(null, route)).toEqual(router.parseUrl('/login'));
|
||||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async(async() => {
|
it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async(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(authService, 'isPublicUrl').and.returnValue(false);
|
||||||
@@ -112,21 +110,20 @@ describe('AuthGuardService ECM', () => {
|
|||||||
scope: 'openid'
|
scope: 'openid'
|
||||||
};
|
};
|
||||||
|
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'abc'};
|
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'abc' };
|
||||||
|
|
||||||
expect(await authGuard.canActivate(null, route)).toBeFalsy();
|
expect(await authGuard.canActivate(null, route)).toBeFalsy();
|
||||||
expect(authService.ssoImplicitLogin).toHaveBeenCalledTimes(1);
|
expect(authService.ssoImplicitLogin).toHaveBeenCalledTimes(1);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should not redirect url if NOT logged in and isOAuth but no silentLogin configured', async(async() => {
|
it('should not redirect url if NOT logged in and isOAuth but no silentLogin configured', async(async () => {
|
||||||
spyOn(router, 'navigateByUrl').and.stub();
|
spyOn(router, 'navigateByUrl').and.stub();
|
||||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||||
appConfigService.config.oauth2.silentLogin = undefined;
|
appConfigService.config.oauth2.silentLogin = undefined;
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'some-url'};
|
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||||
|
|
||||||
expect(await authGuard.canActivate(null, route)).toBeFalsy();
|
expect(await authGuard.canActivate(null, route)).toEqual(router.parseUrl('/login'));
|
||||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should set redirect navigation commands', async(() => {
|
it('should set redirect navigation commands', async(() => {
|
||||||
@@ -168,18 +165,13 @@ describe('AuthGuardService ECM', () => {
|
|||||||
expect(authService.getRedirect()).toEqual('/');
|
expect(authService.getRedirect()).toEqual('/');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should get redirect url from config if there is one configured', async(() => {
|
it('should get redirect url from config if there is one configured', async(async () => {
|
||||||
appConfigService.config.loginRoute = 'fakeLoginRoute';
|
appConfigService.config.loginRoute = 'fakeLoginRoute';
|
||||||
spyOn(authService, 'setRedirect').and.callThrough();
|
spyOn(authService, 'setRedirect').and.callThrough();
|
||||||
spyOn(router, 'navigateByUrl').and.stub();
|
spyOn(router, 'navigateByUrl').and.stub();
|
||||||
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
|
||||||
|
|
||||||
authGuard.canActivate(null, route);
|
expect(await authGuard.canActivate(null, route)).toEqual(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url'));
|
||||||
|
|
||||||
expect(authService.setRedirect).toHaveBeenCalledWith({
|
|
||||||
provider: 'ECM', url: 'some-url'
|
|
||||||
});
|
|
||||||
expect(router.navigateByUrl).toHaveBeenCalledWith('/fakeLoginRoute?redirectUrl=some-url');
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should to close the material dialog if is redirect to the login', () => {
|
it('should to close the material dialog if is redirect to the login', () => {
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
ActivatedRouteSnapshot, Router
|
ActivatedRouteSnapshot, Router, UrlTree
|
||||||
} from '@angular/router';
|
} from '@angular/router';
|
||||||
import { AuthenticationService } from './authentication.service';
|
import { AuthenticationService } from './authentication.service';
|
||||||
import { AppConfigService } from '../app-config/app-config.service';
|
import { AppConfigService } from '../app-config/app-config.service';
|
||||||
@@ -38,7 +38,7 @@ export class AuthGuardEcm extends AuthGuardBase {
|
|||||||
super(authenticationService, router, appConfigService, dialog, storageService);
|
super(authenticationService, router, appConfigService, dialog, storageService);
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkLogin(_: ActivatedRouteSnapshot, redirectUrl: string): Promise<boolean> {
|
async checkLogin(_: ActivatedRouteSnapshot, redirectUrl: string): Promise<boolean | UrlTree> {
|
||||||
if (this.authenticationService.isEcmLoggedIn() || this.withCredentials) {
|
if (this.authenticationService.isEcmLoggedIn() || this.withCredentials) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -66,8 +66,7 @@ describe('AuthGuardService', () => {
|
|||||||
spyOn(router, 'navigateByUrl');
|
spyOn(router, 'navigateByUrl');
|
||||||
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
spyOn(authService, 'isLoggedIn').and.returnValue(false);
|
||||||
|
|
||||||
expect(await authGuard.canActivate(null, state)).toBeFalsy();
|
expect(await authGuard.canActivate(null, state)).toEqual(router.parseUrl('/login?redirectUrl=some-url'));
|
||||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async(async () => {
|
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async(async () => {
|
||||||
@@ -97,8 +96,7 @@ describe('AuthGuardService', () => {
|
|||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||||
appConfigService.config.oauth2.silentLogin = false;
|
appConfigService.config.oauth2.silentLogin = false;
|
||||||
|
|
||||||
expect(await authGuard.canActivate(null, state)).toBeFalsy();
|
expect(await authGuard.canActivate(null, state)).toEqual(router.parseUrl('/login'));
|
||||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should redirect url if the User is NOT logged in and isOAuth but no silentLogin configured', async(async () => {
|
it('should redirect url if the User is NOT logged in and isOAuth but no silentLogin configured', async(async () => {
|
||||||
@@ -107,8 +105,7 @@ describe('AuthGuardService', () => {
|
|||||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||||
appConfigService.config.oauth2.silentLogin = undefined;
|
appConfigService.config.oauth2.silentLogin = undefined;
|
||||||
|
|
||||||
expect(await authGuard.canActivate(null, state)).toBeFalsy();
|
expect(await authGuard.canActivate(null, state)).toEqual(router.parseUrl('/login'));
|
||||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should NOT redirect url if the User is NOT logged in and isOAuth but with silentLogin configured', async(async () => {
|
it('should NOT redirect url if the User is NOT logged in and isOAuth but with silentLogin configured', async(async () => {
|
||||||
@@ -128,12 +125,7 @@ describe('AuthGuardService', () => {
|
|||||||
spyOn(router, 'navigateByUrl');
|
spyOn(router, 'navigateByUrl');
|
||||||
spyOn(authService, 'setRedirect');
|
spyOn(authService, 'setRedirect');
|
||||||
|
|
||||||
await authGuard.canActivate(null, state);
|
expect(await authGuard.canActivate(null, state)).toEqual(router.parseUrl('/login?redirectUrl=some-url'));
|
||||||
|
|
||||||
expect(authService.setRedirect).toHaveBeenCalledWith({
|
|
||||||
provider: 'ALL', url: 'some-url'
|
|
||||||
});
|
|
||||||
expect(router.navigateByUrl).toHaveBeenCalledWith('/login?redirectUrl=some-url');
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should set redirect url with query params', async(async () => {
|
it('should set redirect url with query params', async(async () => {
|
||||||
@@ -144,12 +136,7 @@ describe('AuthGuardService', () => {
|
|||||||
spyOn(router, 'navigateByUrl');
|
spyOn(router, 'navigateByUrl');
|
||||||
spyOn(authService, 'setRedirect');
|
spyOn(authService, 'setRedirect');
|
||||||
|
|
||||||
await authGuard.canActivate(null, state);
|
expect(await authGuard.canActivate(null, state)).toEqual(router.parseUrl('/login?redirectUrl=some-url;q=query'));
|
||||||
|
|
||||||
expect(authService.setRedirect).toHaveBeenCalledWith({
|
|
||||||
provider: 'ALL', url: 'some-url;q=query'
|
|
||||||
});
|
|
||||||
expect(router.navigateByUrl).toHaveBeenCalledWith('/login?redirectUrl=some-url;q=query');
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should get redirect url from config if there is one configured', async(async () => {
|
it('should get redirect url from config if there is one configured', async(async () => {
|
||||||
@@ -159,12 +146,7 @@ describe('AuthGuardService', () => {
|
|||||||
spyOn(router, 'navigateByUrl');
|
spyOn(router, 'navigateByUrl');
|
||||||
spyOn(authService, 'setRedirect');
|
spyOn(authService, 'setRedirect');
|
||||||
|
|
||||||
await authGuard.canActivate(null, state);
|
expect(await authGuard.canActivate(null, state)).toEqual(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url'));
|
||||||
|
|
||||||
expect(authService.setRedirect).toHaveBeenCalledWith({
|
|
||||||
provider: 'ALL', url: 'some-url'
|
|
||||||
});
|
|
||||||
expect(router.navigateByUrl).toHaveBeenCalledWith('/fakeLoginRoute?redirectUrl=some-url');
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should pass actual redirect when no state segments exists', async(async () => {
|
it('should pass actual redirect when no state segments exists', async(async () => {
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { ActivatedRouteSnapshot, Router } from '@angular/router';
|
import { ActivatedRouteSnapshot, Router, UrlTree } from '@angular/router';
|
||||||
import { AuthenticationService } from './authentication.service';
|
import { AuthenticationService } from './authentication.service';
|
||||||
import { AppConfigService } from '../app-config/app-config.service';
|
import { AppConfigService } from '../app-config/app-config.service';
|
||||||
import { AuthGuardBase } from './auth-guard-base';
|
import { AuthGuardBase } from './auth-guard-base';
|
||||||
@@ -67,11 +67,11 @@ export class AuthGuard extends AuthGuardBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkLogin(_: ActivatedRouteSnapshot, redirectUrl: string): Promise<boolean> {
|
async checkLogin(_: ActivatedRouteSnapshot, redirectUrl: string): Promise<boolean | UrlTree> {
|
||||||
if (this.authenticationService.isLoggedIn() || this.withCredentials) {
|
if (this.authenticationService.isLoggedIn() || this.withCredentials) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return this.redirectToUrl( redirectUrl);
|
return this.redirectToUrl(redirectUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user