fix: fix some tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { TestBed } from '@/testing';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { CryptoService } from '../utils/crypto/crypto.service';
|
||||
import { JwtWindowCryptoService } from './jwt-window-crypto.service';
|
||||
|
||||
@@ -25,7 +25,7 @@ describe('JwtWindowCryptoService', () => {
|
||||
'44445543344242132145455aaabbdc3b4'
|
||||
);
|
||||
|
||||
const value = await lastValueFrom(observable);
|
||||
const value = await firstValueFrom(observable);
|
||||
expect(value).toBe(outcome);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { inject, Injectable } from 'injection-js';
|
||||
import { from, type Observable } from 'rxjs';
|
||||
import { Injectable, inject } from 'injection-js';
|
||||
import { BehaviorSubject, type Observable, from } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { CryptoService } from '../utils/crypto/crypto.service';
|
||||
import { MockUtil } from '../utils/reflect';
|
||||
|
||||
@Injectable()
|
||||
export class JwtWindowCryptoService {
|
||||
private readonly cryptoService = inject(CryptoService);
|
||||
|
||||
@MockUtil({ implementation: () => new BehaviorSubject(undefined) })
|
||||
generateCodeChallenge(codeVerifier: string): Observable<string> {
|
||||
return this.calcHash(codeVerifier).pipe(
|
||||
map((challengeRaw: string) => this.base64UrlEncode(challengeRaw))
|
||||
|
||||
@@ -2,22 +2,12 @@ import { ValidationResult } from './validation-result';
|
||||
|
||||
export class StateValidationResult {
|
||||
constructor(
|
||||
// biome-ignore lint/style/noParameterProperties: <explanation>
|
||||
// biome-ignore lint/nursery/useConsistentMemberAccessibility: <explanation>
|
||||
public accessToken = '',
|
||||
// biome-ignore lint/style/noParameterProperties: <explanation>
|
||||
// biome-ignore lint/nursery/useConsistentMemberAccessibility: <explanation>
|
||||
public idToken = '',
|
||||
// biome-ignore lint/style/noParameterProperties: <explanation>
|
||||
// biome-ignore lint/nursery/useConsistentMemberAccessibility: <explanation>
|
||||
public authResponseIsValid = false,
|
||||
// biome-ignore lint/style/noParameterProperties: <explanation>
|
||||
// biome-ignore lint/nursery/useConsistentMemberAccessibility: <explanation>
|
||||
public decodedIdToken: any = {
|
||||
at_hash: '',
|
||||
},
|
||||
// biome-ignore lint/style/noParameterProperties: <explanation>
|
||||
// biome-ignore lint/nursery/useConsistentMemberAccessibility: <explanation>
|
||||
public state: ValidationResult = ValidationResult.NotSet
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { TestBed } from '@/testing';
|
||||
import { lastValueFrom, of } from 'rxjs';
|
||||
import {
|
||||
mockImplementationWhenArgs,
|
||||
mockImplementationWhenArgsEqual,
|
||||
} from '@/testing/spy';
|
||||
import { firstValueFrom, of } from 'rxjs';
|
||||
import { vi } from 'vitest';
|
||||
import type { AuthWellKnownEndpoints } from '../config/auth-well-known/auth-well-known-endpoints';
|
||||
import type { OpenIdConfiguration } from '../config/openid-configuration';
|
||||
@@ -28,6 +32,7 @@ describe('State Validation Service', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
StateValidationService,
|
||||
mockProvider(StoragePersistenceService),
|
||||
mockProvider(TokenValidationService),
|
||||
mockProvider(LoggerService),
|
||||
@@ -687,8 +692,8 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const isValid = await lastValueFrom(isValidObs$);
|
||||
expect(isValid.authResponseIsValid).toBe(false);
|
||||
const isValid = await firstValueFrom(isValidObs$);
|
||||
expect(isValid.authResponseIsValid).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return invalid context error', async () => {
|
||||
@@ -723,7 +728,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const isValid = await lastValueFrom(isValidObs$);
|
||||
const isValid = await firstValueFrom(isValidObs$);
|
||||
expect(isValid.authResponseIsValid).toBe(false);
|
||||
});
|
||||
|
||||
@@ -787,13 +792,23 @@ describe('State Validation Service', () => {
|
||||
).mockReturnValue(false);
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
|
||||
const logWarningSpy = vi
|
||||
.spyOn(loggerService, 'logWarning')
|
||||
@@ -818,7 +833,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(logWarningSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
'authCallback id token expired'
|
||||
@@ -832,12 +847,18 @@ describe('State Validation Service', () => {
|
||||
it('should return invalid result if validateStateFromHashCallback is false', async () => {
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
|
||||
vi.spyOn(
|
||||
tokenValidationService,
|
||||
'validateStateFromHashCallback'
|
||||
@@ -870,7 +891,7 @@ describe('State Validation Service', () => {
|
||||
tokenValidationService.validateStateFromHashCallback
|
||||
).toHaveBeenCalled();
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(logWarningSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
'authCallback incorrect state'
|
||||
@@ -940,13 +961,23 @@ describe('State Validation Service', () => {
|
||||
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
|
||||
const callbackContext = {
|
||||
code: 'fdffsdfsdf',
|
||||
@@ -967,7 +998,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(state.accessToken).toBe('access_tokenTEST');
|
||||
expect(state.idToken).toBe('id_tokenTEST');
|
||||
expect(state.decodedIdToken).toBe('decoded_id_token');
|
||||
@@ -990,12 +1021,16 @@ describe('State Validation Service', () => {
|
||||
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
const logDebugSpy = vi
|
||||
.spyOn(loggerService, 'logDebug')
|
||||
.mockImplementation(() => undefined);
|
||||
@@ -1020,8 +1055,8 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
expect(logDebugSpy).toBeCalledWith([
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(logDebugSpy.mock.calls).toEqual([
|
||||
[config, 'authCallback Signature validation failed id_token'],
|
||||
[config, 'authCallback token(s) invalid'],
|
||||
]);
|
||||
@@ -1049,13 +1084,21 @@ describe('State Validation Service', () => {
|
||||
);
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
|
||||
const logWarningSpy = vi
|
||||
.spyOn(loggerService, 'logWarning')
|
||||
@@ -1080,7 +1123,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(logWarningSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
'authCallback incorrect nonce, did you call the checkAuth() method multiple times?'
|
||||
@@ -1118,13 +1161,21 @@ describe('State Validation Service', () => {
|
||||
).mockReturnValue(false);
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
const logDebugSpy = vi
|
||||
.spyOn(loggerService, 'logDebug')
|
||||
.mockImplementation(() => undefined);
|
||||
@@ -1148,7 +1199,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(logDebugSpy).toHaveBeenCalledWith(
|
||||
config,
|
||||
'authCallback Validation, one of the REQUIRED properties missing from id_token'
|
||||
@@ -1193,13 +1244,21 @@ describe('State Validation Service', () => {
|
||||
config.maxIdTokenIatOffsetAllowedInSeconds = 0;
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
const logWarningSpy = vi
|
||||
.spyOn(loggerService, 'logWarning')
|
||||
.mockImplementation(() => undefined);
|
||||
@@ -1223,7 +1282,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(logWarningSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
'authCallback Validation, iat rejected id_token was issued too far away from the current time'
|
||||
@@ -1271,13 +1330,21 @@ describe('State Validation Service', () => {
|
||||
);
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
const logWarningSpy = vi
|
||||
.spyOn(loggerService, 'logWarning')
|
||||
.mockImplementation(() => undefined);
|
||||
@@ -1301,7 +1368,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(logWarningSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
'authCallback incorrect iss does not match authWellKnownEndpoints issuer'
|
||||
@@ -1339,11 +1406,21 @@ describe('State Validation Service', () => {
|
||||
config.maxIdTokenIatOffsetAllowedInSeconds = 0;
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy.withArgs('authWellKnownEndPoints', config).mockReturnValue(null);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => null
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
const logWarningSpy = vi
|
||||
.spyOn(loggerService, 'logWarning')
|
||||
.mockImplementation(() => undefined);
|
||||
@@ -1367,7 +1444,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(logWarningSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
'authWellKnownEndpoints is undefined'
|
||||
@@ -1414,13 +1491,21 @@ describe('State Validation Service', () => {
|
||||
config.clientId = '';
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
const logWarningSpy = vi
|
||||
.spyOn(loggerService, 'logWarning')
|
||||
.mockImplementation(() => undefined);
|
||||
@@ -1444,7 +1529,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(logWarningSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
'authCallback incorrect aud'
|
||||
@@ -1494,13 +1579,21 @@ describe('State Validation Service', () => {
|
||||
config.clientId = '';
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
const logWarningSpy = vi
|
||||
.spyOn(loggerService, 'logWarning')
|
||||
.mockImplementation(() => undefined);
|
||||
@@ -1524,7 +1617,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(logWarningSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
'authCallback missing azp'
|
||||
@@ -1579,13 +1672,21 @@ describe('State Validation Service', () => {
|
||||
config.clientId = '';
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
const logWarningSpy = vi
|
||||
.spyOn(loggerService, 'logWarning')
|
||||
.mockImplementation(() => undefined);
|
||||
@@ -1609,7 +1710,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(logWarningSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
'authCallback incorrect azp'
|
||||
@@ -1668,13 +1769,21 @@ describe('State Validation Service', () => {
|
||||
config.clientId = '';
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
const logWarningSpy = vi
|
||||
.spyOn(loggerService, 'logWarning')
|
||||
.mockImplementation(() => undefined);
|
||||
@@ -1698,7 +1807,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(logWarningSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
'authCallback pre, post id_token claims do not match in refresh'
|
||||
@@ -1769,13 +1878,21 @@ describe('State Validation Service', () => {
|
||||
config.autoCleanStateAfterAuthentication = false;
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
|
||||
const logDebugSpy = vi
|
||||
.spyOn(loggerService, 'logDebug')
|
||||
@@ -1801,7 +1918,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(logDebugSpy).toHaveBeenCalledWith(
|
||||
config,
|
||||
'authCallback token(s) validated, continue'
|
||||
@@ -1875,13 +1992,21 @@ describe('State Validation Service', () => {
|
||||
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
|
||||
const logWarningSpy = vi
|
||||
.spyOn(loggerService, 'logWarning')
|
||||
@@ -1906,7 +2031,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(logWarningSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
'authCallback incorrect at_hash'
|
||||
@@ -1974,13 +2099,21 @@ describe('State Validation Service', () => {
|
||||
config.responseType = 'id_token token';
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
|
||||
const logDebugSpy = vi.spyOn(loggerService, 'logDebug'); // .mockImplementation(() => undefined);
|
||||
|
||||
@@ -2003,8 +2136,9 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
expect(logDebugSpy).toBeCalledWith([
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
|
||||
expect(logDebugSpy.mock.calls).toEqual([
|
||||
[config, 'iss validation is turned off, this is not recommended!'],
|
||||
[config, 'authCallback token(s) validated, continue'],
|
||||
]);
|
||||
@@ -2060,13 +2194,21 @@ describe('State Validation Service', () => {
|
||||
|
||||
const readSpy = vi.spyOn(storagePersistenceService, 'read');
|
||||
|
||||
readSpy
|
||||
.withArgs('authWellKnownEndPoints', config)
|
||||
.mockReturnValue(authWellKnownEndpoints);
|
||||
readSpy
|
||||
.withArgs('authStateControl', config)
|
||||
.mockReturnValue('authStateControl');
|
||||
readSpy.withArgs('authNonce', config).mockReturnValue('authNonce');
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authWellKnownEndPoints', config],
|
||||
() => authWellKnownEndpoints
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authStateControl', config],
|
||||
() => 'authStateControl'
|
||||
);
|
||||
mockImplementationWhenArgsEqual(
|
||||
readSpy,
|
||||
['authNonce', config],
|
||||
() => 'authNonce'
|
||||
);
|
||||
|
||||
const callbackContext = {
|
||||
code: 'fdffsdfsdf',
|
||||
@@ -2088,7 +2230,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const state = await lastValueFrom(stateObs$);
|
||||
const state = await firstValueFrom(stateObs$);
|
||||
expect(state.accessToken).toBe('access_tokenTEST');
|
||||
expect(state.idToken).toBe('');
|
||||
expect(state.decodedIdToken).toBeDefined();
|
||||
@@ -2127,7 +2269,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const isValid = await lastValueFrom(isValidObs$);
|
||||
const isValid = await firstValueFrom(isValidObs$);
|
||||
expect(isValid.state).toBe(ValidationResult.Ok);
|
||||
expect(isValid.authResponseIsValid).toBe(true);
|
||||
});
|
||||
@@ -2164,7 +2306,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const isValid = await lastValueFrom(isValidObs$);
|
||||
const isValid = await firstValueFrom(isValidObs$);
|
||||
expect(isValid.state).toBe(ValidationResult.Ok);
|
||||
expect(isValid.authResponseIsValid).toBe(true);
|
||||
});
|
||||
@@ -2201,7 +2343,7 @@ describe('State Validation Service', () => {
|
||||
config
|
||||
);
|
||||
|
||||
const isValid = await lastValueFrom(isValidObs$);
|
||||
const isValid = await firstValueFrom(isValidObs$);
|
||||
expect(isValid.state).toBe(ValidationResult.Ok);
|
||||
expect(isValid.authResponseIsValid).toBe(true);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { TestBed } from '@/testing';
|
||||
import { lastValueFrom, of } from 'rxjs';
|
||||
import { firstValueFrom, of } from 'rxjs';
|
||||
import { vi } from 'vitest';
|
||||
import { JwkExtractor } from '../extractors/jwk.extractor';
|
||||
import { LoggerService } from '../logging/logger.service';
|
||||
@@ -503,7 +503,7 @@ describe('TokenValidationService', () => {
|
||||
{ configId: 'configId1' }
|
||||
);
|
||||
|
||||
const valueFalse = await lastValueFrom(valueFalse$);
|
||||
const valueFalse = await firstValueFrom(valueFalse$);
|
||||
expect(valueFalse).toEqual(false);
|
||||
});
|
||||
|
||||
@@ -514,7 +514,7 @@ describe('TokenValidationService', () => {
|
||||
{ configId: 'configId1' }
|
||||
);
|
||||
|
||||
const valueFalse = await lastValueFrom(valueFalse$);
|
||||
const valueFalse = await firstValueFrom(valueFalse$);
|
||||
expect(valueFalse).toEqual(true);
|
||||
});
|
||||
|
||||
@@ -525,7 +525,7 @@ describe('TokenValidationService', () => {
|
||||
{ configId: 'configId1' }
|
||||
);
|
||||
|
||||
const valueFalse = await lastValueFrom(valueFalse$);
|
||||
const valueFalse = await firstValueFrom(valueFalse$);
|
||||
expect(valueFalse).toEqual(false);
|
||||
});
|
||||
|
||||
@@ -542,7 +542,7 @@ describe('TokenValidationService', () => {
|
||||
{ configId: 'configId1' }
|
||||
);
|
||||
|
||||
const valueFalse = await lastValueFrom(valueFalse$);
|
||||
const valueFalse = await firstValueFrom(valueFalse$);
|
||||
expect(valueFalse).toEqual(false);
|
||||
});
|
||||
|
||||
@@ -561,7 +561,7 @@ describe('TokenValidationService', () => {
|
||||
{ configId: 'configId1' }
|
||||
);
|
||||
|
||||
const valueFalse = await lastValueFrom(valueFalse$);
|
||||
const valueFalse = await firstValueFrom(valueFalse$);
|
||||
expect(valueFalse).toEqual(false);
|
||||
});
|
||||
|
||||
@@ -597,7 +597,7 @@ describe('TokenValidationService', () => {
|
||||
{ configId: 'configId1' }
|
||||
);
|
||||
|
||||
const valueFalse = await lastValueFrom(valueFalse$);
|
||||
const valueFalse = await firstValueFrom(valueFalse$);
|
||||
expect(valueFalse).toEqual(false);
|
||||
});
|
||||
|
||||
@@ -634,7 +634,7 @@ describe('TokenValidationService', () => {
|
||||
{ configId: 'configId1' }
|
||||
);
|
||||
|
||||
const valueTrue = await lastValueFrom(valueTrue$);
|
||||
const valueTrue = await firstValueFrom(valueTrue$);
|
||||
expect(valueTrue).toEqual(true);
|
||||
});
|
||||
});
|
||||
@@ -651,7 +651,7 @@ describe('TokenValidationService', () => {
|
||||
{ configId: 'configId1' }
|
||||
);
|
||||
|
||||
const result = await lastValueFrom(result$);
|
||||
const result = await firstValueFrom(result$);
|
||||
expect(result).toEqual(true);
|
||||
});
|
||||
|
||||
@@ -660,7 +660,7 @@ describe('TokenValidationService', () => {
|
||||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ilg1ZVhrNHh5b2pORnVtMWtsMll0djhkbE5QNC1jNTdkTzZRR1RWQndhTmsifQ.eyJleHAiOjE1ODkyMTAwODYsIm5iZiI6MTU4OTIwNjQ4NiwidmVyIjoiMS4wIiwiaXNzIjoiaHR0cHM6Ly9kYW1pZW5ib2QuYjJjbG9naW4uY29tL2EwOTU4ZjQ1LTE5NWItNDAzNi05MjU5LWRlMmY3ZTU5NGRiNi92Mi4wLyIsInN1YiI6ImY4MzZmMzgwLTNjNjQtNDgwMi04ZGJjLTAxMTk4MWMwNjhmNSIsImF1ZCI6ImYxOTM0YTZlLTk1OGQtNDE5OC05ZjM2LTYxMjdjZmM0Y2RiMyIsIm5vbmNlIjoiMDA3YzQxNTNiNmEwNTE3YzBlNDk3NDc2ZmIyNDk5NDhlYzVjbE92UVEiLCJpYXQiOjE1ODkyMDY0ODYsImF1dGhfdGltZSI6MTU4OTIwNjQ4NiwibmFtZSI6ImRhbWllbmJvZCIsImVtYWlscyI6WyJkYW1pZW5AZGFtaWVuYm9kLm9ubWljcm9zb2Z0LmNvbSJdLCJ0ZnAiOiJCMkNfMV9iMmNwb2xpY3lkYW1pZW4iLCJhdF9oYXNoIjoiWmswZktKU19wWWhPcE04SUJhMTJmdyJ9.E5Z-0kOzNU7LBkeVHHMyNoER8TUapGzUUfXmW6gVu4v6QMM5fQ4sJ7KC8PHh8lBFYiCnaDiTtpn3QytUwjXEFnLDAX5qcZT1aPoEgL_OmZMC-8y-4GyHp35l7VFD4iNYM9fJmLE8SYHTVl7eWPlXSyz37Ip0ciiV0Fd6eoksD_aVc-hkIqngDfE4fR8ZKfv4yLTNN_SfknFfuJbZ56yN-zIBL4GkuHsbQCBYpjtWQ62v98p1jO7NhHKV5JP2ec_Ge6oYc_bKTrE6OIX38RJ2rIm7zU16mtdjnl_350Nw3ytHcTPnA1VpP_VLElCfe83jr5aDHc_UQRYaAcWlOgvmVg';
|
||||
const atHash = 'bad';
|
||||
|
||||
const result = await lastValueFrom(
|
||||
const result = await firstValueFrom(
|
||||
tokenValidationService.validateIdTokenAtHash(
|
||||
accessToken,
|
||||
atHash,
|
||||
@@ -688,7 +688,7 @@ describe('TokenValidationService', () => {
|
||||
{ configId: 'configId1' }
|
||||
);
|
||||
|
||||
const result = await lastValueFrom(result$);
|
||||
const result = await firstValueFrom(result$);
|
||||
expect(result).toEqual(true);
|
||||
});
|
||||
|
||||
@@ -704,7 +704,7 @@ describe('TokenValidationService', () => {
|
||||
{ configId: 'configId1' }
|
||||
);
|
||||
|
||||
const result = await lastValueFrom(result$);
|
||||
const result = await firstValueFrom(result$);
|
||||
expect(result).toEqual(false);
|
||||
});
|
||||
|
||||
@@ -720,7 +720,7 @@ describe('TokenValidationService', () => {
|
||||
{ configId: 'configId1' }
|
||||
);
|
||||
|
||||
const result = await lastValueFrom(result$);
|
||||
const result = await firstValueFrom(result$);
|
||||
expect(result).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -390,7 +390,8 @@ export class TokenValidationService {
|
||||
localState: any,
|
||||
configuration: OpenIdConfiguration
|
||||
): boolean {
|
||||
if ((state as string) !== (localState as string)) {
|
||||
console.error(state, localState, `${state}`, `${localState}`);
|
||||
if (`${state}` !== `${localState}`) {
|
||||
this.loggerService.logDebug(
|
||||
configuration,
|
||||
`ValidateStateFromHashCallback failed, state: ${state} local_state:${localState}`
|
||||
|
||||
Reference in New Issue
Block a user