mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Throw correct error for invalid triple data
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { AcceptPreferenceParser } from '../../src/ldp/http/AcceptPreferenceParser';
|
||||
import arrayifyStream from 'arrayify-stream';
|
||||
import { HttpRequest } from '../../src/server/HttpRequest';
|
||||
import { Readable } from 'stream';
|
||||
import { SimpleBodyParser } from '../../src/ldp/http/SimpleBodyParser';
|
||||
import { SimpleRequestParser } from '../../src/ldp/http/SimpleRequestParser';
|
||||
import { SimpleTargetExtractor } from '../../src/ldp/http/SimpleTargetExtractor';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { StreamParser } from 'n3';
|
||||
import { namedNode, triple } from '@rdfjs/data-model';
|
||||
|
||||
describe('A SimpleRequestParser with simple input parsers', (): void => {
|
||||
@@ -34,7 +34,7 @@ describe('A SimpleRequestParser with simple input parsers', (): void => {
|
||||
language: [{ value: 'en-gb', weight: 1 }, { value: 'en', weight: 0.5 }],
|
||||
},
|
||||
body: {
|
||||
data: expect.any(StreamParser),
|
||||
data: expect.any(Readable),
|
||||
dataType: 'quad',
|
||||
metadata: {
|
||||
contentType: 'text/turtle',
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import arrayifyStream from 'arrayify-stream';
|
||||
import { HttpRequest } from '../../../../src/server/HttpRequest';
|
||||
import { Readable } from 'stream';
|
||||
import { SimpleBodyParser } from '../../../../src/ldp/http/SimpleBodyParser';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { StreamParser } from 'n3';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { UnsupportedMediaTypeHttpError } from '../../../../src/util/errors/UnsupportedMediaTypeHttpError';
|
||||
import { namedNode, triple } from '@rdfjs/data-model';
|
||||
import 'jest-rdf';
|
||||
@@ -42,7 +43,7 @@ describe('A SimpleBodyparser', (): void => {
|
||||
input.headers = { 'content-type': 'text/turtle' };
|
||||
const result = await bodyParser.handle(input);
|
||||
expect(result).toEqual({
|
||||
data: expect.any(StreamParser),
|
||||
data: expect.any(Readable),
|
||||
dataType: 'quad',
|
||||
metadata: {
|
||||
contentType: 'text/turtle',
|
||||
@@ -56,4 +57,11 @@ describe('A SimpleBodyparser', (): void => {
|
||||
namedNode('http://test.com/o'),
|
||||
) ]);
|
||||
});
|
||||
|
||||
it('throws an UnsupportedHttpError on invalid triple data when reading the stream.', async(): Promise<void> => {
|
||||
const input = streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.com/o>' ]) as HttpRequest;
|
||||
input.headers = { 'content-type': 'text/turtle' };
|
||||
const result = await bodyParser.handle(input);
|
||||
await expect(arrayifyStream(result.data)).rejects.toThrow(UnsupportedHttpError);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user