@@ -34,6 +34,7 @@ import { NotificationsServiceStub } from '../../shared/testing/notifications-ser
3434import { SetUserAsIdleAction , UnsetUserAsIdleAction } from './auth.actions' ;
3535import { SpecialGroupDataMock , SpecialGroupDataMock$ } from '../../shared/testing/special-group.mock' ;
3636import { cold } from 'jasmine-marbles' ;
37+ import { environment } from '../../../environments/environment' ;
3738
3839describe ( 'AuthService test' , ( ) => {
3940
@@ -103,7 +104,7 @@ describe('AuthService test', () => {
103104 linkService = {
104105 resolveLinks : { }
105106 } ;
106- hardRedirectService = jasmine . createSpyObj ( 'hardRedirectService' , [ 'redirect' ] ) ;
107+ hardRedirectService = jasmine . createSpyObj ( 'hardRedirectService' , [ 'redirect' , 'getCurrentRoute' ] ) ;
107108 spyOn ( linkService , 'resolveLinks' ) . and . returnValue ( { authenticated : true , eperson : observableOf ( { payload : { } } ) } ) ;
108109
109110 }
@@ -374,28 +375,39 @@ describe('AuthService test', () => {
374375 expect ( storage . remove ) . toHaveBeenCalled ( ) ;
375376 } ) ;
376377
377- it ( 'should redirect to reload with redirect url' , ( ) => {
378+ // The reload URL must be absolute (nameSpace-aware): a relative 'reload/...' URL is resolved
379+ // against the current URL - e.g. against /bitstreams/<uuid>/download after an external
380+ // (Shibboleth) login - producing invalid nested URLs like /bitstreams/<uuid>/reload/reload/...
381+ const reloadPrefix = environment . ui . nameSpace . replace ( / \/ $ / , '' ) + '/reload/' ;
382+
383+ it ( 'should redirect to the absolute reload URL with redirect url' , ( ) => {
378384 authService . navigateToRedirectUrl ( '/collection/123' ) ;
379385 // Reload with redirect URL set to /collection/123
380- expect ( hardRedirectService . redirect ) . toHaveBeenCalledWith ( jasmine . stringMatching ( new RegExp ( 'reload/ [0-9]* \\?redirect=' + encodeURIComponent ( '/collection/123' ) ) ) ) ;
386+ expect ( hardRedirectService . redirect ) . toHaveBeenCalledWith ( jasmine . stringMatching ( new RegExp ( '^' + reloadPrefix + ' [0-9]+ \\?redirect=' + encodeURIComponent ( '/collection/123' ) + '$' ) ) ) ;
381387 } ) ;
382388
383- it ( 'should redirect to reload with /home' , ( ) => {
389+ it ( 'should redirect to the absolute reload URL with /home' , ( ) => {
384390 authService . navigateToRedirectUrl ( '/home' ) ;
385391 // Reload with redirect URL set to /home
386- expect ( hardRedirectService . redirect ) . toHaveBeenCalledWith ( jasmine . stringMatching ( new RegExp ( 'reload/ [0-9]* \\?redirect=' + encodeURIComponent ( '/home' ) ) ) ) ;
392+ expect ( hardRedirectService . redirect ) . toHaveBeenCalledWith ( jasmine . stringMatching ( new RegExp ( '^' + reloadPrefix + ' [0-9]+ \\?redirect=' + encodeURIComponent ( '/home' ) + '$' ) ) ) ;
387393 } ) ;
388394
389- it ( 'should redirect to regular reload and not to /login' , ( ) => {
395+ it ( 'should redirect to the absolute reload URL and not to /login' , ( ) => {
390396 authService . navigateToRedirectUrl ( '/login' ) ;
391397 // Reload without a redirect URL
392- expect ( hardRedirectService . redirect ) . toHaveBeenCalledWith ( jasmine . stringMatching ( new RegExp ( 'reload/ [0-9]*(?!\\?) $' ) ) ) ;
398+ expect ( hardRedirectService . redirect ) . toHaveBeenCalledWith ( jasmine . stringMatching ( new RegExp ( '^' + reloadPrefix + ' [0-9]+ $') ) ) ;
393399 } ) ;
394400
395- it ( 'should redirect to regular reload when no redirect url is found' , ( ) => {
401+ it ( 'should redirect to the absolute reload URL when no redirect url is found' , ( ) => {
396402 authService . navigateToRedirectUrl ( undefined ) ;
397403 // Reload without a redirect URL
398- expect ( hardRedirectService . redirect ) . toHaveBeenCalledWith ( jasmine . stringMatching ( new RegExp ( 'reload/[0-9]*(?!\\?)$' ) ) ) ;
404+ expect ( hardRedirectService . redirect ) . toHaveBeenCalledWith ( jasmine . stringMatching ( new RegExp ( '^' + reloadPrefix + '[0-9]+$' ) ) ) ;
405+ } ) ;
406+
407+ it ( 'should not redirect again when the current route is already the reload page' , ( ) => {
408+ hardRedirectService . getCurrentRoute . and . returnValue ( reloadPrefix + '123456789?redirect=' + encodeURIComponent ( '/home' ) ) ;
409+ authService . navigateToRedirectUrl ( '/collection/123' ) ;
410+ expect ( hardRedirectService . redirect ) . not . toHaveBeenCalled ( ) ;
399411 } ) ;
400412
401413 describe ( 'impersonate' , ( ) => {
0 commit comments