fix: Set max-len to 120

This commit is contained in:
Joachim Van Herwegen
2020-07-24 14:59:41 +02:00
parent dcff424f58
commit aaba113563
23 changed files with 152 additions and 71 deletions

View File

@@ -39,7 +39,9 @@ describe('An AuthenticatedLdpHandler', (): void => {
it('can check if it handles input.', async(): Promise<void> => {
const handler = new AuthenticatedLdpHandler(args);
await expect(handler.canHandle({ request: {} as HttpRequest, response: {} as HttpResponse })).resolves.toBeUndefined();
await expect(handler.canHandle(
{ request: {} as HttpRequest, response: {} as HttpResponse },
)).resolves.toBeUndefined();
});
it('can handle input.', async(): Promise<void> => {

View File

@@ -18,22 +18,29 @@ describe('An AcceptPreferenceParser', (): void => {
});
it('parses accept-charset headers.', async(): Promise<void> => {
await expect(preferenceParser.handle({ headers: { 'accept-charset': 'iso-8859-5, unicode-1-1;q=0.8' }} as unknown as HttpRequest))
.resolves.toEqual({ charset: [{ value: 'iso-8859-5', weight: 1 }, { value: 'unicode-1-1', weight: 0.8 }]});
await expect(preferenceParser.handle(
{ headers: { 'accept-charset': 'iso-8859-5, unicode-1-1;q=0.8' }} as unknown as HttpRequest,
)).resolves.toEqual({ charset: [{ value: 'iso-8859-5', weight: 1 }, { value: 'unicode-1-1', weight: 0.8 }]});
});
it('parses accept-datetime headers.', async(): Promise<void> => {
await expect(preferenceParser.handle({ headers: { 'accept-datetime': 'Tue, 20 Mar 2001 20:35:00 GMT' }} as unknown as HttpRequest))
.resolves.toEqual({ datetime: [{ value: 'Tue, 20 Mar 2001 20:35:00 GMT', weight: 1 }]});
await expect(preferenceParser.handle(
{ headers: { 'accept-datetime': 'Tue, 20 Mar 2001 20:35:00 GMT' }} as unknown as HttpRequest,
)).resolves.toEqual({ datetime: [{ value: 'Tue, 20 Mar 2001 20:35:00 GMT', weight: 1 }]});
});
it('parses accept-encoding headers.', async(): Promise<void> => {
await expect(preferenceParser.handle({ headers: { 'accept-encoding': 'gzip;q=1.0, identity; q=0.5, *;q=0' }} as unknown as HttpRequest))
.resolves.toEqual({ encoding: [{ value: 'gzip', weight: 1 }, { value: 'identity', weight: 0.5 }, { value: '*', weight: 0 }]});
await expect(preferenceParser.handle(
{ headers: { 'accept-encoding': 'gzip;q=1.0, identity; q=0.5, *;q=0' }} as unknown as HttpRequest,
)).resolves.toEqual(
{ encoding: [{ value: 'gzip', weight: 1 }, { value: 'identity', weight: 0.5 }, { value: '*', weight: 0 }]},
);
});
it('parses accept-language headers.', async(): Promise<void> => {
await expect(preferenceParser.handle({ headers: { 'accept-language': 'da, en-gb;q=0.8, en;q=0.7' }} as HttpRequest))
.resolves.toEqual({ language: [{ value: 'da', weight: 1 }, { value: 'en-gb', weight: 0.8 }, { value: 'en', weight: 0.7 }]});
.resolves.toEqual(
{ language: [{ value: 'da', weight: 1 }, { value: 'en-gb', weight: 0.8 }, { value: 'en', weight: 0.7 }]},
);
});
});

View File

@@ -15,9 +15,12 @@ describe('A SimpleResponseWriter', (): void => {
});
it('requires the description body to be a string or binary stream if present.', async(): Promise<void> => {
await expect(writer.canHandle({ response, result: { body: { dataType: 'quad' }} as ResponseDescription })).rejects.toThrow(UnsupportedHttpError);
await expect(writer.canHandle({ response, result: { body: { dataType: 'string' }} as ResponseDescription })).resolves.toBeUndefined();
await expect(writer.canHandle({ response, result: { body: { dataType: 'binary' }} as ResponseDescription })).resolves.toBeUndefined();
await expect(writer.canHandle({ response, result: { body: { dataType: 'quad' }} as ResponseDescription }))
.rejects.toThrow(UnsupportedHttpError);
await expect(writer.canHandle({ response, result: { body: { dataType: 'string' }} as ResponseDescription }))
.resolves.toBeUndefined();
await expect(writer.canHandle({ response, result: { body: { dataType: 'binary' }} as ResponseDescription }))
.resolves.toBeUndefined();
});
it('responds with status code 200 and a location header if there is a description.', async(): Promise<void> => {

View File

@@ -11,12 +11,15 @@ describe('A SimpleSparqlUpdateBodyParser', (): void => {
it('only accepts application/sparql-update content.', async(): Promise<void> => {
await expect(bodyParser.canHandle({ headers: {}} as HttpRequest)).rejects.toThrow(UnsupportedMediaTypeHttpError);
await expect(bodyParser.canHandle({ headers: { 'content-type': 'text/plain' }} as HttpRequest)).rejects.toThrow(UnsupportedMediaTypeHttpError);
await expect(bodyParser.canHandle({ headers: { 'content-type': 'application/sparql-update' }} as HttpRequest)).resolves.toBeUndefined();
await expect(bodyParser.canHandle({ headers: { 'content-type': 'text/plain' }} as HttpRequest))
.rejects.toThrow(UnsupportedMediaTypeHttpError);
await expect(bodyParser.canHandle({ headers: { 'content-type': 'application/sparql-update' }} as HttpRequest))
.resolves.toBeUndefined();
});
it('errors when handling invalid SPARQL updates.', async(): Promise<void> => {
await expect(bodyParser.handle(streamifyArray([ 'VERY INVALID UPDATE' ]) as HttpRequest)).rejects.toThrow(UnsupportedHttpError);
await expect(bodyParser.handle(streamifyArray([ 'VERY INVALID UPDATE' ]) as HttpRequest))
.rejects.toThrow(UnsupportedHttpError);
});
it('converts SPARQL updates to algebra.', async(): Promise<void> => {

View File

@@ -16,7 +16,8 @@ describe('A SimpleTargetExtractor', (): void => {
});
it('uses https protocol if the connection is secure.', async(): Promise<void> => {
await expect(extractor.handle({ url: 'url', headers: { host: 'test.com' }, connection: { encrypted: true } as any } as any))
.resolves.toEqual({ path: 'https://test.com/url' });
await expect(extractor.handle(
{ url: 'url', headers: { host: 'test.com' }, connection: { encrypted: true } as any } as any,
)).resolves.toEqual({ path: 'https://test.com/url' });
});
});

View File

@@ -17,7 +17,8 @@ describe('A SimpleDeleteOperationHandler', (): void => {
});
it('deletes the resource from the store and returns its identifier.', async(): Promise<void> => {
await expect(handler.handle({ target: { path: 'url' }} as Operation)).resolves.toEqual({ identifier: { path: 'url' }});
await expect(handler.handle({ target: { path: 'url' }} as Operation))
.resolves.toEqual({ identifier: { path: 'url' }});
expect(store.deleteResource).toHaveBeenCalledTimes(1);
expect(store.deleteResource).toHaveBeenLastCalledWith({ path: 'url' });
});

View File

@@ -11,8 +11,10 @@ describe('A SimplePostOperationHandler', (): void => {
const handler = new SimplePostOperationHandler(store);
it('only supports POST operations with a body.', async(): Promise<void> => {
await expect(handler.canHandle({ method: 'POST', body: { dataType: 'test' }} as Operation)).resolves.toBeUndefined();
await expect(handler.canHandle({ method: 'GET', body: { dataType: 'test' }} as Operation)).rejects.toThrow(UnsupportedHttpError);
await expect(handler.canHandle({ method: 'POST', body: { dataType: 'test' }} as Operation))
.resolves.toBeUndefined();
await expect(handler.canHandle({ method: 'GET', body: { dataType: 'test' }} as Operation))
.rejects.toThrow(UnsupportedHttpError);
await expect(handler.canHandle({ method: 'POST' } as Operation)).rejects.toThrow(UnsupportedHttpError);
});
@@ -21,6 +23,7 @@ describe('A SimplePostOperationHandler', (): void => {
});
it('adds the given representation to the store and returns the new identifier.', async(): Promise<void> => {
await expect(handler.handle({ method: 'POST', body: { dataType: 'test' }} as Operation)).resolves.toEqual({ identifier: { path: 'newPath' }});
await expect(handler.handle({ method: 'POST', body: { dataType: 'test' }} as Operation))
.resolves.toEqual({ identifier: { path: 'newPath' }});
});
});

View File

@@ -53,7 +53,8 @@ describe('ExpressHttpServer', (): void => {
'access-control-allow-origin': '*',
'access-control-allow-headers': 'content-type',
}));
const corsMethods = res.header['access-control-allow-methods'].split(',').map((method: string): string => method.trim());
const corsMethods = res.header['access-control-allow-methods'].split(',')
.map((method: string): string => method.trim());
const allowedMethods = [ 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE' ];
expect(corsMethods).toEqual(expect.arrayContaining(allowedMethods));
expect(corsMethods.length).toBe(allowedMethods.length);

View File

@@ -24,11 +24,16 @@ describe('A LockingResourceStore', (): void => {
};
source = {
getRepresentation: jest.fn(async(): Promise<any> => new Promise((resolve): any => delayedResolve(resolve, 'getRepresentation'))),
addResource: jest.fn(async(): Promise<any> => new Promise((resolve): any => delayedResolve(resolve, 'addResource'))),
setRepresentation: jest.fn(async(): Promise<any> => new Promise((resolve): any => delayedResolve(resolve, 'setRepresentation'))),
deleteResource: jest.fn(async(): Promise<any> => new Promise((resolve): any => delayedResolve(resolve, 'deleteResource'))),
modifyResource: jest.fn(async(): Promise<any> => new Promise((resolve): any => delayedResolve(resolve, 'modifyResource'))),
getRepresentation: jest.fn(async(): Promise<any> =>
new Promise((resolve): any => delayedResolve(resolve, 'getRepresentation'))),
addResource: jest.fn(async(): Promise<any> =>
new Promise((resolve): any => delayedResolve(resolve, 'addResource'))),
setRepresentation: jest.fn(async(): Promise<any> =>
new Promise((resolve): any => delayedResolve(resolve, 'setRepresentation'))),
deleteResource: jest.fn(async(): Promise<any> =>
new Promise((resolve): any => delayedResolve(resolve, 'deleteResource'))),
modifyResource: jest.fn(async(): Promise<any> =>
new Promise((resolve): any => delayedResolve(resolve, 'modifyResource'))),
};
release = jest.fn(async(): Promise<any> => order.push('release'));
locker = {

View File

@@ -31,9 +31,11 @@ describe('A SimpleResourceStore', (): void => {
it('errors if a resource was not found.', async(): Promise<void> => {
await expect(store.getRepresentation({ path: `${base}wrong` }, {})).rejects.toThrow(NotFoundHttpError);
await expect(store.addResource({ path: 'http://wrong.com/wrong' }, representation)).rejects.toThrow(NotFoundHttpError);
await expect(store.addResource({ path: 'http://wrong.com/wrong' }, representation))
.rejects.toThrow(NotFoundHttpError);
await expect(store.deleteResource({ path: 'wrong' })).rejects.toThrow(NotFoundHttpError);
await expect(store.setRepresentation({ path: 'http://wrong.com/' }, representation)).rejects.toThrow(NotFoundHttpError);
await expect(store.setRepresentation({ path: 'http://wrong.com/' }, representation))
.rejects.toThrow(NotFoundHttpError);
});
it('errors when modifying resources.', async(): Promise<void> => {

View File

@@ -63,7 +63,9 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => {
const basicChecks = async(quads: Quad[]): Promise<void> => {
expect(source.getRepresentation).toHaveBeenCalledTimes(1);
expect(source.getRepresentation).toHaveBeenLastCalledWith({ path: 'path' }, { type: [{ value: 'internal/quads', weight: 1 }]});
expect(source.getRepresentation).toHaveBeenLastCalledWith(
{ path: 'path' }, { type: [{ value: 'internal/quads', weight: 1 }]},
);
expect(source.setRepresentation).toHaveBeenCalledTimes(1);
expect(order).toEqual([ 'acquire', 'getRepresentation', 'setRepresentation', 'release' ]);
const setParams = (source.setRepresentation as jest.Mock).mock.calls[0];
@@ -76,7 +78,8 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => {
};
it('only accepts SPARQL updates.', async(): Promise<void> => {
const input = { identifier: { path: 'path' }, patch: { dataType: 'sparql-algebra', algebra: {}} as SparqlUpdatePatch };
const input = { identifier: { path: 'path' },
patch: { dataType: 'sparql-algebra', algebra: {}} as SparqlUpdatePatch };
await expect(handler.canHandle(input)).resolves.toBeUndefined();
input.patch.dataType = 'notAlgebra';
await expect(handler.canHandle(input)).rejects.toThrow(UnsupportedHttpError);
@@ -102,7 +105,9 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => {
{ quads: true },
) } as SparqlUpdatePatch });
await basicChecks(
[ quad(namedNode('http://test.com/startS2'), namedNode('http://test.com/startP2'), namedNode('http://test.com/startO2')) ],
[ quad(namedNode('http://test.com/startS2'),
namedNode('http://test.com/startP2'),
namedNode('http://test.com/startO2')) ],
);
});
@@ -113,7 +118,9 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => {
{ quads: true },
) } as SparqlUpdatePatch });
await basicChecks(
[ quad(namedNode('http://test.com/startS2'), namedNode('http://test.com/startP2'), namedNode('http://test.com/startO2')) ],
[ quad(namedNode('http://test.com/startS2'),
namedNode('http://test.com/startP2'),
namedNode('http://test.com/startO2')) ],
);
});
@@ -125,16 +132,21 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => {
'WHERE {}',
{ quads: true },
) } as SparqlUpdatePatch });
await basicChecks(
[ quad(namedNode('http://test.com/startS2'), namedNode('http://test.com/startP2'), namedNode('http://test.com/startO2')),
quad(namedNode('http://test.com/s1'), namedNode('http://test.com/p1'), namedNode('http://test.com/o1')) ],
);
await basicChecks([
quad(namedNode('http://test.com/startS2'),
namedNode('http://test.com/startP2'),
namedNode('http://test.com/startO2')),
quad(namedNode('http://test.com/s1'),
namedNode('http://test.com/p1'),
namedNode('http://test.com/o1')),
]);
});
it('rejects GRAPH inserts.', async(): Promise<void> => {
const handle = handler.handle({ identifier: { path: 'path' },
patch: { algebra: translate(
'INSERT DATA { GRAPH <http://test.com/graph> { <http://test.com/startS1> <http://test.com/startP1> <http://test.com/startO1> } }',
'INSERT DATA { GRAPH <http://test.com/graph> { ' +
'<http://test.com/startS1> <http://test.com/startP1> <http://test.com/startO1> } }',
{ quads: true },
) } as SparqlUpdatePatch });
await expect(handle).rejects.toThrow('GRAPH statements are not supported.');
@@ -144,7 +156,8 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => {
it('rejects GRAPH deletes.', async(): Promise<void> => {
const handle = handler.handle({ identifier: { path: 'path' },
patch: { algebra: translate(
'DELETE DATA { GRAPH <http://test.com/graph> { <http://test.com/startS1> <http://test.com/startP1> <http://test.com/startO1> } }',
'DELETE DATA { GRAPH <http://test.com/graph> { ' +
'<http://test.com/startS1> <http://test.com/startP1> <http://test.com/startO1> } }',
{ quads: true },
) } as SparqlUpdatePatch });
await expect(handle).rejects.toThrow('GRAPH statements are not supported.');

View File

@@ -25,7 +25,9 @@ describe('AcceptParser', (): void => {
});
it('parses complex Accept headers.', async(): Promise<void> => {
expect(parseAccept('text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4,text/x-dvi; q=0.8; mxb=100000; mxt')).toEqual([
expect(parseAccept(
'text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4,text/x-dvi; q=0.8; mxb=100000; mxt',
)).toEqual([
{ range: 'text/html', weight: 1, parameters: { mediaType: { level: '1' }, extension: {}}},
{ range: 'text/x-dvi', weight: 0.8, parameters: { mediaType: {}, extension: { mxb: '100000', mxt: '' }}},
{ range: 'text/html', weight: 0.7, parameters: { mediaType: {}, extension: {}}},
@@ -35,7 +37,9 @@ describe('AcceptParser', (): void => {
it('parses Accept headers with double quoted values.', async(): Promise<void> => {
expect(parseAccept('audio/basic; param1="val" ; q=0.5 ;param2="\\\\\\"valid"')).toEqual([
{ range: 'audio/basic', weight: 0.5, parameters: { mediaType: { param1: '"val"' }, extension: { param2: '"\\\\\\"valid"' }}},
{ range: 'audio/basic',
weight: 0.5,
parameters: { mediaType: { param1: '"val"' }, extension: { param2: '"\\\\\\"valid"' }}},
]);
});

View File

@@ -67,7 +67,7 @@ describe('A CompositeAsyncHandler', (): void => {
expect(handleFn).toHaveBeenCalledTimes(1);
});
it('throws the same error as canHandle when calling handleSafe if no handler supports the data.', async(): Promise<void> => {
it('throws the canHandle error when calling handleSafe if the data is not supported.', async(): Promise<void> => {
const handler = new CompositeAsyncHandler([ handlerFalse, handlerFalse ]);
await expect(handler.handleSafe(null)).rejects.toThrow('[Not supported., Not supported.]');