fix: Correctly render internal IDP errors

This commit is contained in:
Joachim Van Herwegen 2021-06-24 16:51:23 +02:00
parent 3a0cf60a55
commit c18b8526cc
2 changed files with 11 additions and 2 deletions

View File

@ -84,6 +84,8 @@ export class IdentityProviderFactory {
}, },
renderError: renderError:
async(ctx: KoaContextWithOIDC, out: ErrorOut, error: Error): Promise<void> => { async(ctx: KoaContextWithOIDC, out: ErrorOut, error: Error): Promise<void> => {
// This allows us to stream directly to to the response object, see https://github.com/koajs/koa/issues/944
ctx.respond = false;
const preferences: RepresentationPreferences = { type: { 'text/plain': 1 }}; const preferences: RepresentationPreferences = { type: { 'text/plain': 1 }};
const result = await this.errorHandler.handleSafe({ error, preferences }); const result = await this.errorHandler.handleSafe({ error, preferences });
await this.responseWriter.handleSafe({ response: ctx.res, result }); await this.responseWriter.handleSafe({ response: ctx.res, result });

View File

@ -335,13 +335,20 @@ describe('A Solid server with IDP', (): void => {
}); });
}); });
describe('openid-configuration', (): void => { describe('setup', (): void => {
it('should contain solid_oidc_supported key.', async(): Promise<void> => { it('should contain the required configuration keys.', async(): Promise<void> => {
const res = await fetch(`${baseUrl}.well-known/openid-configuration`); const res = await fetch(`${baseUrl}.well-known/openid-configuration`);
const jsonBody = await res.json(); const jsonBody = await res.json();
expect(res.status).toBe(200); expect(res.status).toBe(200);
// https://solid.github.io/authentication-panel/solid-oidc/#discovery
expect(jsonBody.solid_oidc_supported).toEqual('https://solidproject.org/TR/solid-oidc'); expect(jsonBody.solid_oidc_supported).toEqual('https://solidproject.org/TR/solid-oidc');
}); });
it('should return correct error output.', async(): Promise<void> => {
const res = await fetch(`${baseUrl}idp/auth`);
expect(res.status).toBe(400);
await expect(res.text()).resolves.toContain('InvalidRequest: invalid_request');
});
}); });
}); });