mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Full rework of account management
Complete rewrite of the account management and related systems. Makes the architecture more modular, allowing for easier extensions and configurations.
This commit is contained in:
34
test/unit/http/input/metadata/AuthorizationParser.test.ts
Normal file
34
test/unit/http/input/metadata/AuthorizationParser.test.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { DataFactory } from 'n3';
|
||||
import { AuthorizationParser } from '../../../../../src/http/input/metadata/AuthorizationParser';
|
||||
import { RepresentationMetadata } from '../../../../../src/http/representation/RepresentationMetadata';
|
||||
import type { HttpRequest } from '../../../../../src/server/HttpRequest';
|
||||
import namedNode = DataFactory.namedNode;
|
||||
|
||||
describe('An AuthorizationParser', (): void => {
|
||||
const parser = new AuthorizationParser({ custom: 'http://example.com/pred' });
|
||||
let request: HttpRequest;
|
||||
let metadata: RepresentationMetadata;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
request = { headers: {}} as HttpRequest;
|
||||
metadata = new RepresentationMetadata();
|
||||
});
|
||||
|
||||
it('does nothing if there is no authorization header.', async(): Promise<void> => {
|
||||
await parser.handle({ request, metadata });
|
||||
expect(metadata.quads()).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('converts the authorization header to the relevant triple.', async(): Promise<void> => {
|
||||
request.headers.authorization = 'custom my-value';
|
||||
await parser.handle({ request, metadata });
|
||||
expect(metadata.quads()).toHaveLength(1);
|
||||
expect(metadata.get(namedNode('http://example.com/pred'))?.value).toBe('my-value');
|
||||
});
|
||||
|
||||
it('ignores unknown values.', async(): Promise<void> => {
|
||||
request.headers.authorization = 'unknown my-value';
|
||||
await parser.handle({ request, metadata });
|
||||
expect(metadata.quads()).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user