mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge pull request #511 from mspalti/login_redirect_encoding_fix
Prevent encoding of query after login redirect.
This commit is contained in:
@@ -249,30 +249,34 @@ describe('AuthService test', () => {
|
|||||||
|
|
||||||
it ('should set redirect url to previous page', () => {
|
it ('should set redirect url to previous page', () => {
|
||||||
spyOn(routeServiceMock, 'getHistory').and.callThrough();
|
spyOn(routeServiceMock, 'getHistory').and.callThrough();
|
||||||
|
spyOn(routerStub, 'navigateByUrl');
|
||||||
authService.redirectAfterLoginSuccess(true);
|
authService.redirectAfterLoginSuccess(true);
|
||||||
expect(routeServiceMock.getHistory).toHaveBeenCalled();
|
expect(routeServiceMock.getHistory).toHaveBeenCalled();
|
||||||
expect(routerStub.navigate).toHaveBeenCalledWith(['/collection/123']);
|
expect(routerStub.navigateByUrl).toHaveBeenCalledWith('/collection/123');
|
||||||
});
|
});
|
||||||
|
|
||||||
it ('should set redirect url to current page', () => {
|
it ('should set redirect url to current page', () => {
|
||||||
spyOn(routeServiceMock, 'getHistory').and.callThrough();
|
spyOn(routeServiceMock, 'getHistory').and.callThrough();
|
||||||
|
spyOn(routerStub, 'navigateByUrl');
|
||||||
authService.redirectAfterLoginSuccess(false);
|
authService.redirectAfterLoginSuccess(false);
|
||||||
expect(routeServiceMock.getHistory).toHaveBeenCalled();
|
expect(routeServiceMock.getHistory).toHaveBeenCalled();
|
||||||
expect(routerStub.navigate).toHaveBeenCalledWith(['/home']);
|
expect(routerStub.navigateByUrl).toHaveBeenCalledWith('/home');
|
||||||
});
|
});
|
||||||
|
|
||||||
it ('should redirect to / and not to /login', () => {
|
it ('should redirect to / and not to /login', () => {
|
||||||
spyOn(routeServiceMock, 'getHistory').and.returnValue(observableOf(['/login', '/login']));
|
spyOn(routeServiceMock, 'getHistory').and.returnValue(observableOf(['/login', '/login']));
|
||||||
|
spyOn(routerStub, 'navigateByUrl');
|
||||||
authService.redirectAfterLoginSuccess(true);
|
authService.redirectAfterLoginSuccess(true);
|
||||||
expect(routeServiceMock.getHistory).toHaveBeenCalled();
|
expect(routeServiceMock.getHistory).toHaveBeenCalled();
|
||||||
expect(routerStub.navigate).toHaveBeenCalledWith(['/']);
|
expect(routerStub.navigateByUrl).toHaveBeenCalledWith('/');
|
||||||
});
|
});
|
||||||
|
|
||||||
it ('should redirect to / when no redirect url is found', () => {
|
it ('should redirect to / when no redirect url is found', () => {
|
||||||
spyOn(routeServiceMock, 'getHistory').and.returnValue(observableOf(['']));
|
spyOn(routeServiceMock, 'getHistory').and.returnValue(observableOf(['']));
|
||||||
|
spyOn(routerStub, 'navigateByUrl');
|
||||||
authService.redirectAfterLoginSuccess(true);
|
authService.redirectAfterLoginSuccess(true);
|
||||||
expect(routeServiceMock.getHistory).toHaveBeenCalled();
|
expect(routeServiceMock.getHistory).toHaveBeenCalled();
|
||||||
expect(routerStub.navigate).toHaveBeenCalledWith(['/']);
|
expect(routerStub.navigateByUrl).toHaveBeenCalledWith('/');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -347,8 +347,7 @@ export class AuthService {
|
|||||||
if (isNotEmpty(redirectUrl)) {
|
if (isNotEmpty(redirectUrl)) {
|
||||||
this.clearRedirectUrl();
|
this.clearRedirectUrl();
|
||||||
this.router.onSameUrlNavigation = 'reload';
|
this.router.onSameUrlNavigation = 'reload';
|
||||||
const url = decodeURIComponent(redirectUrl);
|
this.navigateToRedirectUrl(redirectUrl);
|
||||||
this.navigateToRedirectUrl(url);
|
|
||||||
} else {
|
} else {
|
||||||
// If redirectUrl is empty use history.
|
// If redirectUrl is empty use history.
|
||||||
this.routeService.getHistory().pipe(
|
this.routeService.getHistory().pipe(
|
||||||
@@ -368,16 +367,17 @@ export class AuthService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected navigateToRedirectUrl(url: string) {
|
protected navigateToRedirectUrl(redirectUrl: string) {
|
||||||
|
const url = decodeURIComponent(redirectUrl);
|
||||||
// in case the user navigates directly to /login (via bookmark, etc), or the route history is not found.
|
// in case the user navigates directly to /login (via bookmark, etc), or the route history is not found.
|
||||||
if (isEmpty(url) || url.startsWith(LOGIN_ROUTE)) {
|
if (isEmpty(url) || url.startsWith(LOGIN_ROUTE)) {
|
||||||
this.router.navigate(['/']);
|
this.router.navigateByUrl('/');
|
||||||
/* TODO Reenable hard redirect when REST API can handle x-forwarded-for, see https://github.com/DSpace/DSpace/pull/2207 */
|
/* TODO Reenable hard redirect when REST API can handle x-forwarded-for, see https://github.com/DSpace/DSpace/pull/2207 */
|
||||||
// this._window.nativeWindow.location.href = '/';
|
// this._window.nativeWindow.location.href = '/';
|
||||||
} else {
|
} else {
|
||||||
/* TODO Reenable hard redirect when REST API can handle x-forwarded-for, see https://github.com/DSpace/DSpace/pull/2207 */
|
/* TODO Reenable hard redirect when REST API can handle x-forwarded-for, see https://github.com/DSpace/DSpace/pull/2207 */
|
||||||
// this._window.nativeWindow.location.href = url;
|
// this._window.nativeWindow.location.href = url;
|
||||||
this.router.navigate([url]);
|
this.router.navigateByUrl(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user