mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: new helper functions to replace regexes #807
Implemented new StringUtil helper functions: splitCommaSeparated, sanitizeUrlPart, isValidFileName. Added helper functions to HeaderUtil: matchesAuthorizationScheme, hasScheme. Added unit tests for the new helper functions. Refactored codebase to use helper functions instead of regexes if applicable.
This commit is contained in:
committed by
Joachim Van Herwegen
parent
1b7cc1ea3a
commit
283c301f08
@@ -3,6 +3,7 @@ import request from 'supertest';
|
||||
import type { BaseHttpServerFactory } from '../../src/server/BaseHttpServerFactory';
|
||||
import type { HttpHandlerInput } from '../../src/server/HttpHandler';
|
||||
import { HttpHandler } from '../../src/server/HttpHandler';
|
||||
import { splitCommaSeparated } from '../../src/util/StringUtil';
|
||||
import { getPort } from '../util/Util';
|
||||
import { getTestConfigPath, instantiateFromConfig } from './Config';
|
||||
|
||||
@@ -96,46 +97,46 @@ describe('An http server with middleware', (): void => {
|
||||
it('exposes the Accept-[Method] header via CORS.', async(): Promise<void> => {
|
||||
const res = await request(server).get('/').expect(200);
|
||||
const exposed = res.header['access-control-expose-headers'];
|
||||
expect(exposed.split(/\s*,\s*/u)).toContain('Accept-Patch');
|
||||
expect(exposed.split(/\s*,\s*/u)).toContain('Accept-Post');
|
||||
expect(exposed.split(/\s*,\s*/u)).toContain('Accept-Put');
|
||||
expect(splitCommaSeparated(exposed)).toContain('Accept-Patch');
|
||||
expect(splitCommaSeparated(exposed)).toContain('Accept-Post');
|
||||
expect(splitCommaSeparated(exposed)).toContain('Accept-Put');
|
||||
});
|
||||
|
||||
it('exposes the Last-Modified and ETag headers via CORS.', async(): Promise<void> => {
|
||||
const res = await request(server).get('/').expect(200);
|
||||
const exposed = res.header['access-control-expose-headers'];
|
||||
expect(exposed.split(/\s*,\s*/u)).toContain('ETag');
|
||||
expect(exposed.split(/\s*,\s*/u)).toContain('Last-Modified');
|
||||
expect(splitCommaSeparated(exposed)).toContain('ETag');
|
||||
expect(splitCommaSeparated(exposed)).toContain('Last-Modified');
|
||||
});
|
||||
|
||||
it('exposes the Link header via CORS.', async(): Promise<void> => {
|
||||
const res = await request(server).get('/').expect(200);
|
||||
const exposed = res.header['access-control-expose-headers'];
|
||||
expect(exposed.split(/\s*,\s*/u)).toContain('Link');
|
||||
expect(splitCommaSeparated(exposed)).toContain('Link');
|
||||
});
|
||||
|
||||
it('exposes the Location header via CORS.', async(): Promise<void> => {
|
||||
const res = await request(server).get('/').expect(200);
|
||||
const exposed = res.header['access-control-expose-headers'];
|
||||
expect(exposed.split(/\s*,\s*/u)).toContain('Location');
|
||||
expect(splitCommaSeparated(exposed)).toContain('Location');
|
||||
});
|
||||
|
||||
it('exposes the MS-Author-Via header via CORS.', async(): Promise<void> => {
|
||||
const res = await request(server).get('/').expect(200);
|
||||
const exposed = res.header['access-control-expose-headers'];
|
||||
expect(exposed.split(/\s*,\s*/u)).toContain('MS-Author-Via');
|
||||
expect(splitCommaSeparated(exposed)).toContain('MS-Author-Via');
|
||||
});
|
||||
|
||||
it('exposes the WAC-Allow header via CORS.', async(): Promise<void> => {
|
||||
const res = await request(server).get('/').expect(200);
|
||||
const exposed = res.header['access-control-expose-headers'];
|
||||
expect(exposed.split(/\s*,\s*/u)).toContain('WAC-Allow');
|
||||
expect(splitCommaSeparated(exposed)).toContain('WAC-Allow');
|
||||
});
|
||||
|
||||
it('exposes the Updates-Via header via CORS.', async(): Promise<void> => {
|
||||
const res = await request(server).get('/').expect(200);
|
||||
const exposed = res.header['access-control-expose-headers'];
|
||||
expect(exposed.split(/\s*,\s*/u)).toContain('Updates-Via');
|
||||
expect(splitCommaSeparated(exposed)).toContain('Updates-Via');
|
||||
});
|
||||
|
||||
it('sends incoming requests to the handler.', async(): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user