mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Determine body presence according to RFC7230
Fixes https://github.com/solid/community-server/issues/121
This commit is contained in:
committed by
Joachim Van Herwegen
parent
ee3b847033
commit
a06a7ff685
@@ -12,13 +12,29 @@ describe('A RawBodyparser', (): void => {
|
||||
await expect(bodyParser.canHandle()).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns empty output if there was no content-type.', async(): Promise<void> => {
|
||||
await expect(bodyParser.handle({ headers: { }} as HttpRequest)).resolves.toBeUndefined();
|
||||
it('returns empty output if there was no content length or transfer encoding.', async(): Promise<void> => {
|
||||
const input = streamifyArray([ '' ]) as HttpRequest;
|
||||
input.headers = {};
|
||||
await expect(bodyParser.handle(input)).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('errors when a content length was specified without content type.', async(): Promise<void> => {
|
||||
const input = streamifyArray([ 'abc' ]) as HttpRequest;
|
||||
input.headers = { 'content-length': '0' };
|
||||
await expect(bodyParser.handle(input)).rejects
|
||||
.toThrow('An HTTP request body was passed without Content-Type header');
|
||||
});
|
||||
|
||||
it('errors when a transfer encoding was specified without content type.', async(): Promise<void> => {
|
||||
const input = streamifyArray([ 'abc' ]) as HttpRequest;
|
||||
input.headers = { 'transfer-encoding': 'chunked' };
|
||||
await expect(bodyParser.handle(input)).rejects
|
||||
.toThrow('An HTTP request body was passed without Content-Type header');
|
||||
});
|
||||
|
||||
it('returns a Representation if there was data.', 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' };
|
||||
input.headers = { 'transfer-encoding': 'chunked', 'content-type': 'text/turtle' };
|
||||
const result = (await bodyParser.handle(input))!;
|
||||
expect(result).toEqual({
|
||||
binary: true,
|
||||
@@ -35,7 +51,7 @@ describe('A RawBodyparser', (): void => {
|
||||
|
||||
it('adds the slug header to the metadata.', async(): Promise<void> => {
|
||||
const input = {} as HttpRequest;
|
||||
input.headers = { 'content-type': 'text/turtle', slug: 'slugText' };
|
||||
input.headers = { 'transfer-encoding': 'chunked', 'content-type': 'text/turtle', slug: 'slugText' };
|
||||
const result = (await bodyParser.handle(input))!;
|
||||
expect(result.metadata).toEqual({
|
||||
contentType: 'text/turtle',
|
||||
@@ -46,13 +62,17 @@ describe('A RawBodyparser', (): void => {
|
||||
|
||||
it('errors if there are multiple slugs.', async(): Promise<void> => {
|
||||
const input = {} as HttpRequest;
|
||||
input.headers = { 'content-type': 'text/turtle', slug: [ 'slugTextA', 'slugTextB' ]};
|
||||
input.headers = { 'transfer-encoding': 'chunked',
|
||||
'content-type': 'text/turtle',
|
||||
slug: [ 'slugTextA', 'slugTextB' ]};
|
||||
await expect(bodyParser.handle(input)).rejects.toThrow(UnsupportedHttpError);
|
||||
});
|
||||
|
||||
it('adds the link headers to the metadata.', async(): Promise<void> => {
|
||||
const input = {} as HttpRequest;
|
||||
input.headers = { 'content-type': 'text/turtle', link: '<http://www.w3.org/ns/ldp#Container>; rel="type"' };
|
||||
input.headers = { 'transfer-encoding': 'chunked',
|
||||
'content-type': 'text/turtle',
|
||||
link: '<http://www.w3.org/ns/ldp#Container>; rel="type"' };
|
||||
const result = (await bodyParser.handle(input))!;
|
||||
expect(result.metadata).toEqual({
|
||||
contentType: 'text/turtle',
|
||||
@@ -63,7 +83,8 @@ describe('A RawBodyparser', (): void => {
|
||||
|
||||
it('supports multiple link headers.', async(): Promise<void> => {
|
||||
const input = {} as HttpRequest;
|
||||
input.headers = { 'content-type': 'text/turtle',
|
||||
input.headers = { 'transfer-encoding': 'chunked',
|
||||
'content-type': 'text/turtle',
|
||||
link: [ '<http://www.w3.org/ns/ldp#Container>; rel="type"',
|
||||
'<http://www.w3.org/ns/ldp#Resource>; rel="type"',
|
||||
'<unrelatedLink>',
|
||||
|
||||
Reference in New Issue
Block a user