mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Move OIDC library behaviour to separate path
This commit is contained in:
@@ -378,7 +378,7 @@ describe('A Solid server with IDP', (): void => {
|
||||
});
|
||||
|
||||
it('should return correct error output.', async(): Promise<void> => {
|
||||
const res = await fetch(`${baseUrl}idp/auth`);
|
||||
const res = await fetch(`${baseUrl}.oidc/auth`);
|
||||
expect(res.status).toBe(400);
|
||||
await expect(res.text()).resolves.toContain('InvalidRequest: invalid_request');
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"files-scs:config/app/main/default.json",
|
||||
"files-scs:config/app/init/initialize-root.json",
|
||||
"files-scs:config/app/setup/disabled.json",
|
||||
"files-scs:config/http/handler/default.json",
|
||||
"files-scs:config/http/handler/simple.json",
|
||||
"files-scs:config/http/middleware/websockets.json",
|
||||
"files-scs:config/http/server-factory/websockets.json",
|
||||
"files-scs:config/http/static/default.json",
|
||||
@@ -26,9 +26,5 @@
|
||||
"files-scs:config/util/variables/default.json"
|
||||
],
|
||||
"@graph": [
|
||||
{
|
||||
"@id": "urn:solid-server:default:IdentityProviderHandler",
|
||||
"@type": "UnsupportedAsyncHandler"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import type {
|
||||
RepresentationConverter,
|
||||
RepresentationConverterArgs,
|
||||
} from '../../../src/storage/conversion/RepresentationConverter';
|
||||
import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError';
|
||||
import { joinUrl } from '../../../src/util/PathUtil';
|
||||
import { guardedStreamFrom, readableToString } from '../../../src/util/StreamUtil';
|
||||
import { CONTENT_TYPE, SOLID_HTTP, SOLID_META } from '../../../src/util/Vocabularies';
|
||||
@@ -46,7 +47,6 @@ describe('An IdentityProviderHttpHandler', (): void => {
|
||||
};
|
||||
|
||||
provider = {
|
||||
callback: jest.fn(),
|
||||
interactionDetails: jest.fn(),
|
||||
} as any;
|
||||
|
||||
@@ -113,11 +113,9 @@ describe('An IdentityProviderHttpHandler', (): void => {
|
||||
handler = new IdentityProviderHttpHandler(args);
|
||||
});
|
||||
|
||||
it('calls the provider if there is no matching route.', async(): Promise<void> => {
|
||||
it('throws a 404 if there is no matching route.', async(): Promise<void> => {
|
||||
operation.target.path = joinUrl(baseUrl, 'invalid');
|
||||
await expect(handler.handle({ request, response, operation })).resolves.toBeUndefined();
|
||||
expect(provider.callback).toHaveBeenCalledTimes(1);
|
||||
expect(provider.callback).toHaveBeenLastCalledWith(request, response);
|
||||
await expect(handler.handle({ request, response, operation })).rejects.toThrow(NotFoundHttpError);
|
||||
});
|
||||
|
||||
it('creates Representations for InteractionResponseResults.', async(): Promise<void> => {
|
||||
|
||||
31
test/unit/identity/OidcHttpHandler.test.ts
Normal file
31
test/unit/identity/OidcHttpHandler.test.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { Provider } from 'oidc-provider';
|
||||
import type { ProviderFactory } from '../../../src/identity/configuration/ProviderFactory';
|
||||
import { OidcHttpHandler } from '../../../src/identity/OidcHttpHandler';
|
||||
import type { HttpRequest } from '../../../src/server/HttpRequest';
|
||||
import type { HttpResponse } from '../../../src/server/HttpResponse';
|
||||
|
||||
describe('An OidcHttpHandler', (): void => {
|
||||
const request: HttpRequest = {} as any;
|
||||
const response: HttpResponse = {} as any;
|
||||
let provider: jest.Mocked<Provider>;
|
||||
let providerFactory: jest.Mocked<ProviderFactory>;
|
||||
let handler: OidcHttpHandler;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
provider = {
|
||||
callback: jest.fn(),
|
||||
} as any;
|
||||
|
||||
providerFactory = {
|
||||
getProvider: jest.fn().mockResolvedValue(provider),
|
||||
};
|
||||
|
||||
handler = new OidcHttpHandler(providerFactory);
|
||||
});
|
||||
|
||||
it('sends all requests to the OIDC library.', async(): Promise<void> => {
|
||||
await expect(handler.handle({ request, response })).resolves.toBeUndefined();
|
||||
expect(provider.callback).toHaveBeenCalledTimes(1);
|
||||
expect(provider.callback).toHaveBeenLastCalledWith(request, response);
|
||||
});
|
||||
});
|
||||
@@ -12,23 +12,24 @@ jest.mock('oidc-provider', (): any => ({
|
||||
}));
|
||||
|
||||
const routes = {
|
||||
authorization: '/foo/idp/auth',
|
||||
check_session: '/foo/idp/session/check',
|
||||
code_verification: '/foo/idp/device',
|
||||
device_authorization: '/foo/idp/device/auth',
|
||||
end_session: '/foo/idp/session/end',
|
||||
introspection: '/foo/idp/token/introspection',
|
||||
jwks: '/foo/idp/jwks',
|
||||
pushed_authorization_request: '/foo/idp/request',
|
||||
registration: '/foo/idp/reg',
|
||||
revocation: '/foo/idp/token/revocation',
|
||||
token: '/foo/idp/token',
|
||||
userinfo: '/foo/idp/me',
|
||||
authorization: '/foo/oidc/auth',
|
||||
check_session: '/foo/oidc/session/check',
|
||||
code_verification: '/foo/oidc/device',
|
||||
device_authorization: '/foo/oidc/device/auth',
|
||||
end_session: '/foo/oidc/session/end',
|
||||
introspection: '/foo/oidc/token/introspection',
|
||||
jwks: '/foo/oidc/jwks',
|
||||
pushed_authorization_request: '/foo/oidc/request',
|
||||
registration: '/foo/oidc/reg',
|
||||
revocation: '/foo/oidc/token/revocation',
|
||||
token: '/foo/oidc/token',
|
||||
userinfo: '/foo/oidc/me',
|
||||
};
|
||||
|
||||
describe('An IdentityProviderFactory', (): void => {
|
||||
let baseConfig: Configuration;
|
||||
const baseUrl = 'http://test.com/foo/';
|
||||
const oidcPath = '/oidc';
|
||||
const idpPath = '/idp';
|
||||
const webId = 'http://alice.test.com/card#me';
|
||||
let adapterFactory: jest.Mocked<AdapterFactory>;
|
||||
@@ -59,6 +60,7 @@ describe('An IdentityProviderFactory', (): void => {
|
||||
factory = new IdentityProviderFactory(baseConfig, {
|
||||
adapterFactory,
|
||||
baseUrl,
|
||||
oidcPath,
|
||||
idpPath,
|
||||
storage,
|
||||
errorHandler,
|
||||
@@ -70,6 +72,7 @@ describe('An IdentityProviderFactory', (): void => {
|
||||
expect((): any => new IdentityProviderFactory(baseConfig, {
|
||||
adapterFactory,
|
||||
baseUrl,
|
||||
oidcPath,
|
||||
idpPath: 'idp',
|
||||
storage,
|
||||
errorHandler,
|
||||
@@ -127,6 +130,7 @@ describe('An IdentityProviderFactory', (): void => {
|
||||
factory = new IdentityProviderFactory(baseConfig, {
|
||||
adapterFactory,
|
||||
baseUrl,
|
||||
oidcPath,
|
||||
idpPath,
|
||||
storage,
|
||||
errorHandler,
|
||||
@@ -148,6 +152,7 @@ describe('An IdentityProviderFactory', (): void => {
|
||||
const factory2 = new IdentityProviderFactory(baseConfig, {
|
||||
adapterFactory,
|
||||
baseUrl,
|
||||
oidcPath,
|
||||
idpPath,
|
||||
storage,
|
||||
errorHandler,
|
||||
|
||||
Reference in New Issue
Block a user