-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-132648 / 25.04 / query param handling for auth tokens (#11080)
* NAS-132648: adds query param handling to signin.store and auth.service. forward query params on redirect in auth-guard.service * NAS-132648: patch signin.store tests for now * NAS-132648: flag in websocket-handler.service to determine if a socket connection to the NAS has opened at least once. adds queryToken to signin.store state. * NAS-132648: remove router debugging * NAS-132648: add method for handling query token login. remove queryToken from signin.store state. * NAS-132648: update resetUi method to preserve query params during redirect to /signin * NAS-132648: unit test coverage for AuthService.setQueryToken * NAS-132648: test coverage for AuthGuardService
- Loading branch information
Showing
9 changed files
with
142 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router'; | ||
import { | ||
createServiceFactory, | ||
mockProvider, | ||
SpectatorService, | ||
} from '@ngneat/spectator/jest'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { AuthGuardService } from 'app/services/auth/auth-guard.service'; | ||
import { AuthService } from 'app/services/auth/auth.service'; | ||
|
||
describe('AuthGuardService', () => { | ||
const redirectUrl = 'storage/disks'; | ||
const isAuthenticated$ = new BehaviorSubject(false); | ||
const arSnapshot = { queryParams: {} } as ActivatedRouteSnapshot; | ||
const state = { url: redirectUrl } as RouterStateSnapshot; | ||
|
||
let spectator: SpectatorService<AuthGuardService>; | ||
const createService = createServiceFactory({ | ||
service: AuthGuardService, | ||
providers: [mockProvider(AuthService, { isAuthenticated$ })], | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createService(); | ||
isAuthenticated$.next(false); | ||
}); | ||
|
||
describe('canActivate', () => { | ||
it('allows activation if the user is logged in', () => { | ||
expect(spectator.service.canActivate(arSnapshot, state)).toBe(false); | ||
isAuthenticated$.next(true); | ||
expect(spectator.service.canActivate(arSnapshot, state)).toBe(true); | ||
}); | ||
|
||
it('if the user is not logged in, the redirect URL is saved to sessionStorage', () => { | ||
spectator.service.canActivate(arSnapshot, state); | ||
expect(sessionStorage.getItem('redirectUrl')).toEqual(redirectUrl); | ||
}); | ||
|
||
it('if the user is not logged in, the user is redirected to signin', () => { | ||
const router = spectator.inject(Router); | ||
const navigateSpy = jest.spyOn(router, 'navigate'); | ||
spectator.service.canActivate(arSnapshot, state); | ||
expect(navigateSpy).toHaveBeenCalledWith(['/signin'], { queryParams: {} }); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters