mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Output required OAuth error fields
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { BasicRepresentation } from '../../../../src/http/representation/BasicRepresentation';
|
||||
import { ErrorToJsonConverter } from '../../../../src/storage/conversion/ErrorToJsonConverter';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
import type { OAuthErrorFields } from '../../../../src/util/errors/OAuthHttpError';
|
||||
import { OAuthHttpError } from '../../../../src/util/errors/OAuthHttpError';
|
||||
import { readJsonStream } from '../../../../src/util/StreamUtil';
|
||||
|
||||
describe('An ErrorToJsonConverter', (): void => {
|
||||
@@ -47,6 +49,35 @@ describe('An ErrorToJsonConverter', (): void => {
|
||||
});
|
||||
});
|
||||
|
||||
it('adds OAuth fields if present.', async(): Promise<void> => {
|
||||
const out: OAuthErrorFields = {
|
||||
error: 'error',
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
error_description: 'error_description',
|
||||
scope: 'scope',
|
||||
state: 'state',
|
||||
};
|
||||
const error = new OAuthHttpError(out, 'InvalidRequest', 400, 'error text');
|
||||
const representation = new BasicRepresentation([ error ], 'internal/error', false);
|
||||
const prom = converter.handle({ identifier, representation, preferences });
|
||||
await expect(prom).resolves.toBeDefined();
|
||||
const result = await prom;
|
||||
expect(result.binary).toBe(true);
|
||||
expect(result.metadata.contentType).toBe('application/json');
|
||||
await expect(readJsonStream(result.data)).resolves.toEqual({
|
||||
name: 'InvalidRequest',
|
||||
message: 'error text',
|
||||
statusCode: 400,
|
||||
errorCode: 'H400',
|
||||
stack: error.stack,
|
||||
error: 'error',
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
error_description: 'error_description',
|
||||
scope: 'scope',
|
||||
state: 'state',
|
||||
});
|
||||
});
|
||||
|
||||
it('does not copy the details if they are not serializable.', async(): Promise<void> => {
|
||||
const error = new BadRequestHttpError('error text', { details: { object: BigInt(1) }});
|
||||
const representation = new BasicRepresentation([ error ], 'internal/error', false);
|
||||
|
||||
Reference in New Issue
Block a user