Should not redirect if is SilentLogin on (#5216)

* fix redirect

* fix lint

* remove false behaviour alrady tested in the new unit test

* Update auth-guard-base.ts
This commit is contained in:
Eugenio Romano
2019-11-06 13:56:01 +02:00
committed by Denys Vuika
parent 3c1097fb84
commit 5578b7b851
4 changed files with 27 additions and 38 deletions

View File

@@ -64,6 +64,7 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
}
protected redirectToUrl(provider: string, url: string) {
if (!this.isSilentLogin()) {
this.authenticationService.setRedirect({ provider, url });
const pathToLogin = this.getLoginRoute();
@@ -71,6 +72,7 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
this.router.navigateByUrl(urlToRedirect);
}
}
protected getLoginRoute(): string {
return (
@@ -91,4 +93,13 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
this.authenticationService.isOauth() && !!oauth && !oauth.silentLogin
);
}
protected isSilentLogin(): boolean {
const oauth = this.appConfigService.get<OauthConfigModel>(
AppConfigValues.OAUTHCONFIG,
null
);
return this.authenticationService.isOauth() && oauth && oauth.silentLogin;
}
}

View File

@@ -92,17 +92,6 @@ describe('AuthGuardService BPM', () => {
expect(router.navigateByUrl).toHaveBeenCalled();
}));
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithSilentLogin', async(() => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
appConfigService.config.oauth2.silentLogin = true;
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'some-url'};
expect(authGuard.canActivate(null, route)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalled();
}));
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(() => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);

View File

@@ -92,17 +92,6 @@ describe('AuthGuardService ECM', () => {
expect(router.navigateByUrl).toHaveBeenCalled();
}));
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithSilentLogin', async(() => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
appConfigService.config.oauth2.silentLogin = true;
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'some-url'};
expect(authGuard.canActivate(null, route)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalled();
}));
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(() => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);

View File

@@ -72,7 +72,7 @@ describe('AuthGuardService', () => {
expect(authGuard.canActivate(null, route)).toBeTruthy();
}));
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async(() => {
it('should redirect url if the User is NOT logged in and isOAuthWithoutSilentLogin', async(() => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
@@ -82,17 +82,7 @@ describe('AuthGuardService', () => {
expect(router.navigateByUrl).toHaveBeenCalled();
}));
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithSilentLogin', async(() => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
appConfigService.config.oauth2.silentLogin = true;
expect(authGuard.canActivate(null, state)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalled();
}));
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(() => {
it('should redirect url if the User is NOT logged in and isOAuth but no silentLogin configured', async(() => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
@@ -102,6 +92,16 @@ describe('AuthGuardService', () => {
expect(router.navigateByUrl).toHaveBeenCalled();
}));
it('should NOT redirect url if the User is NOT logged in and isOAuth but with silentLogin configured', async(() => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
appConfigService.config.oauth2.silentLogin = true;
expect(authGuard.canActivate(null, state)).toBeFalsy();
expect(router.navigateByUrl).not.toHaveBeenCalled();
}));
it('should set redirect url', async(() => {
state.url = 'some-url';
appConfigService.config.loginRoute = 'login';