feat: init
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { TestBed } from '@/testing';
|
||||
import { of, throwError } from 'rxjs';
|
||||
import { mockProvider } from '../../../test/auto-mock';
|
||||
import { createRetriableStream } from '../../../test/create-retriable-stream.helper';
|
||||
import { vi } from 'vitest';
|
||||
import { DataService } from '../../api/data.service';
|
||||
import { LoggerService } from '../../logging/logger.service';
|
||||
import { createRetriableStream } from '../../testing/create-retriable-stream.helper';
|
||||
import { mockProvider } from '../../testing/mock';
|
||||
import { AuthWellKnownDataService } from './auth-well-known-data.service';
|
||||
import { AuthWellKnownEndpoints } from './auth-well-known-endpoints';
|
||||
import type { AuthWellKnownEndpoints } from './auth-well-known-endpoints';
|
||||
|
||||
const DUMMY_WELL_KNOWN_DOCUMENT = {
|
||||
issuer: 'https://identity-server.test/realms/main',
|
||||
@@ -51,56 +52,65 @@ describe('AuthWellKnownDataService', () => {
|
||||
});
|
||||
|
||||
describe('getWellKnownDocument', () => {
|
||||
it('should add suffix if it does not exist on current URL', waitForAsync(() => {
|
||||
const dataServiceSpy = spyOn(dataService, 'get').and.returnValue(
|
||||
of(null)
|
||||
);
|
||||
it('should add suffix if it does not exist on current URL', async () => {
|
||||
const dataServiceSpy = vi
|
||||
.spyOn(dataService, 'get')
|
||||
.mockReturnValue(of(null));
|
||||
const urlWithoutSuffix = 'myUrl';
|
||||
const urlWithSuffix = `${urlWithoutSuffix}/.well-known/openid-configuration`;
|
||||
|
||||
(service as any)
|
||||
.getWellKnownDocument(urlWithoutSuffix, { configId: 'configId1' })
|
||||
.subscribe(() => {
|
||||
expect(dataServiceSpy).toHaveBeenCalledOnceWith(urlWithSuffix, {
|
||||
configId: 'configId1',
|
||||
});
|
||||
expect(dataServiceSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
urlWithSuffix,
|
||||
{
|
||||
configId: 'configId1',
|
||||
}
|
||||
);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should not add suffix if it does exist on current url', waitForAsync(() => {
|
||||
const dataServiceSpy = spyOn(dataService, 'get').and.returnValue(
|
||||
of(null)
|
||||
);
|
||||
it('should not add suffix if it does exist on current url', async () => {
|
||||
const dataServiceSpy = vi
|
||||
.spyOn(dataService, 'get')
|
||||
.mockReturnValue(of(null));
|
||||
const urlWithSuffix = `myUrl/.well-known/openid-configuration`;
|
||||
|
||||
(service as any)
|
||||
.getWellKnownDocument(urlWithSuffix, { configId: 'configId1' })
|
||||
.subscribe(() => {
|
||||
expect(dataServiceSpy).toHaveBeenCalledOnceWith(urlWithSuffix, {
|
||||
configId: 'configId1',
|
||||
});
|
||||
expect(dataServiceSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
urlWithSuffix,
|
||||
{
|
||||
configId: 'configId1',
|
||||
}
|
||||
);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should not add suffix if it does exist in the middle of current url', waitForAsync(() => {
|
||||
const dataServiceSpy = spyOn(dataService, 'get').and.returnValue(
|
||||
of(null)
|
||||
);
|
||||
it('should not add suffix if it does exist in the middle of current url', async () => {
|
||||
const dataServiceSpy = vi
|
||||
.spyOn(dataService, 'get')
|
||||
.mockReturnValue(of(null));
|
||||
const urlWithSuffix = `myUrl/.well-known/openid-configuration/and/some/more/stuff`;
|
||||
|
||||
(service as any)
|
||||
.getWellKnownDocument(urlWithSuffix, { configId: 'configId1' })
|
||||
.subscribe(() => {
|
||||
expect(dataServiceSpy).toHaveBeenCalledOnceWith(urlWithSuffix, {
|
||||
configId: 'configId1',
|
||||
});
|
||||
expect(dataServiceSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
urlWithSuffix,
|
||||
{
|
||||
configId: 'configId1',
|
||||
}
|
||||
);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should use the custom suffix provided in the config', waitForAsync(() => {
|
||||
const dataServiceSpy = spyOn(dataService, 'get').and.returnValue(
|
||||
of(null)
|
||||
);
|
||||
it('should use the custom suffix provided in the config', async () => {
|
||||
const dataServiceSpy = vi
|
||||
.spyOn(dataService, 'get')
|
||||
.mockReturnValue(of(null));
|
||||
const urlWithoutSuffix = `myUrl`;
|
||||
const urlWithSuffix = `${urlWithoutSuffix}/.well-known/test-openid-configuration`;
|
||||
|
||||
@@ -110,15 +120,18 @@ describe('AuthWellKnownDataService', () => {
|
||||
authWellknownUrlSuffix: '/.well-known/test-openid-configuration',
|
||||
})
|
||||
.subscribe(() => {
|
||||
expect(dataServiceSpy).toHaveBeenCalledOnceWith(urlWithSuffix, {
|
||||
configId: 'configId1',
|
||||
authWellknownUrlSuffix: '/.well-known/test-openid-configuration',
|
||||
});
|
||||
expect(dataServiceSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
urlWithSuffix,
|
||||
{
|
||||
configId: 'configId1',
|
||||
authWellknownUrlSuffix: '/.well-known/test-openid-configuration',
|
||||
}
|
||||
);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should retry once', waitForAsync(() => {
|
||||
spyOn(dataService, 'get').and.returnValue(
|
||||
it('should retry once', async () => {
|
||||
vi.spyOn(dataService, 'get').mockReturnValue(
|
||||
createRetriableStream(
|
||||
throwError(() => new Error('one')),
|
||||
of(DUMMY_WELL_KNOWN_DOCUMENT)
|
||||
@@ -133,10 +146,10 @@ describe('AuthWellKnownDataService', () => {
|
||||
expect(res).toEqual(DUMMY_WELL_KNOWN_DOCUMENT);
|
||||
},
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should retry twice', waitForAsync(() => {
|
||||
spyOn(dataService, 'get').and.returnValue(
|
||||
it('should retry twice', async () => {
|
||||
vi.spyOn(dataService, 'get').mockReturnValue(
|
||||
createRetriableStream(
|
||||
throwError(() => new Error('one')),
|
||||
throwError(() => new Error('two')),
|
||||
@@ -152,10 +165,10 @@ describe('AuthWellKnownDataService', () => {
|
||||
expect(res).toEqual(DUMMY_WELL_KNOWN_DOCUMENT);
|
||||
},
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should fail after three tries', waitForAsync(() => {
|
||||
spyOn(dataService, 'get').and.returnValue(
|
||||
it('should fail after three tries', async () => {
|
||||
vi.spyOn(dataService, 'get').mockReturnValue(
|
||||
createRetriableStream(
|
||||
throwError(() => new Error('one')),
|
||||
throwError(() => new Error('two')),
|
||||
@@ -169,17 +182,16 @@ describe('AuthWellKnownDataService', () => {
|
||||
expect(err).toBeTruthy();
|
||||
},
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('getWellKnownEndPointsForConfig', () => {
|
||||
it('calling internal getWellKnownDocument and maps', waitForAsync(() => {
|
||||
spyOn(dataService, 'get').and.returnValue(of({ jwks_uri: 'jwks_uri' }));
|
||||
it('calling internal getWellKnownDocument and maps', async () => {
|
||||
vi.spyOn(dataService, 'get').mockReturnValue(
|
||||
of({ jwks_uri: 'jwks_uri' })
|
||||
);
|
||||
|
||||
const spy = spyOn(
|
||||
service as any,
|
||||
'getWellKnownDocument'
|
||||
).and.callThrough();
|
||||
const spy = vi.spyOn(service as any, 'getWellKnownDocument')();
|
||||
|
||||
service
|
||||
.getWellKnownEndPointsForConfig({
|
||||
@@ -191,10 +203,10 @@ describe('AuthWellKnownDataService', () => {
|
||||
expect((result as any).jwks_uri).toBeUndefined();
|
||||
expect(result.jwksUri).toBe('jwks_uri');
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('throws error and logs if no authwellknownUrl is given', waitForAsync(() => {
|
||||
const loggerSpy = spyOn(loggerService, 'logError');
|
||||
it('throws error and logs if no authwellknownUrl is given', async () => {
|
||||
const loggerSpy = vi.spyOn(loggerService, 'logError');
|
||||
const config = {
|
||||
configId: 'configId1',
|
||||
authWellknownEndpointUrl: undefined,
|
||||
@@ -202,17 +214,19 @@ describe('AuthWellKnownDataService', () => {
|
||||
|
||||
service.getWellKnownEndPointsForConfig(config).subscribe({
|
||||
error: (error) => {
|
||||
expect(loggerSpy).toHaveBeenCalledOnceWith(
|
||||
expect(loggerSpy).toHaveBeenCalledExactlyOnceWith(
|
||||
config,
|
||||
'no authWellknownEndpoint given!'
|
||||
);
|
||||
expect(error.message).toEqual('no authWellknownEndpoint given!');
|
||||
},
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should merge the mapped endpoints with the provided endpoints', waitForAsync(() => {
|
||||
spyOn(dataService, 'get').and.returnValue(of(DUMMY_WELL_KNOWN_DOCUMENT));
|
||||
it('should merge the mapped endpoints with the provided endpoints', async () => {
|
||||
vi.spyOn(dataService, 'get').mockReturnValue(
|
||||
of(DUMMY_WELL_KNOWN_DOCUMENT)
|
||||
);
|
||||
|
||||
const expected: AuthWellKnownEndpoints = {
|
||||
endSessionEndpoint: 'config-endSessionEndpoint',
|
||||
@@ -232,6 +246,6 @@ describe('AuthWellKnownDataService', () => {
|
||||
.subscribe((result) => {
|
||||
expect(result).toEqual(jasmine.objectContaining(expected));
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user