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);
|
||||
});
|
||||
});
|
||||
29
test/unit/http/input/metadata/CookieParser.test.ts
Normal file
29
test/unit/http/input/metadata/CookieParser.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { DataFactory } from 'n3';
|
||||
import { CookieParser } from '../../../../../src/http/input/metadata/CookieParser';
|
||||
import { RepresentationMetadata } from '../../../../../src/http/representation/RepresentationMetadata';
|
||||
import type { HttpRequest } from '../../../../../src/server/HttpRequest';
|
||||
import namedNode = DataFactory.namedNode;
|
||||
|
||||
describe('A CookieParser', (): void => {
|
||||
const parser = new CookieParser({ custom1: 'http://example.com/pred1', custom2: 'http://example.com/pred2' });
|
||||
let request: HttpRequest;
|
||||
let metadata: RepresentationMetadata;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
request = { headers: {}} as HttpRequest;
|
||||
metadata = new RepresentationMetadata();
|
||||
});
|
||||
|
||||
it('does nothing if there is no cookie 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.cookie = 'custom1=my-value;unknown=unknown-value;custom2=other-value';
|
||||
await parser.handle({ request, metadata });
|
||||
expect(metadata.quads()).toHaveLength(2);
|
||||
expect(metadata.get(namedNode('http://example.com/pred1'))?.value).toBe('my-value');
|
||||
expect(metadata.get(namedNode('http://example.com/pred2'))?.value).toBe('other-value');
|
||||
});
|
||||
});
|
||||
39
test/unit/http/output/metadata/CookieMetadataWriter.test.ts
Normal file
39
test/unit/http/output/metadata/CookieMetadataWriter.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { DataFactory } from 'n3';
|
||||
import { createResponse } from 'node-mocks-http';
|
||||
import { CookieMetadataWriter } from '../../../../../src/http/output/metadata/CookieMetadataWriter';
|
||||
import { RepresentationMetadata } from '../../../../../src/http/representation/RepresentationMetadata';
|
||||
import type { HttpResponse } from '../../../../../src/server/HttpResponse';
|
||||
import namedNode = DataFactory.namedNode;
|
||||
import literal = DataFactory.literal;
|
||||
|
||||
describe('A CookieMetadataWriter', (): void => {
|
||||
const writer = new CookieMetadataWriter({
|
||||
'http://example.com/pred1': { name: 'custom1' },
|
||||
'http://example.com/pred2': { name: 'custom2', expirationUri: 'http://example.com/pred2expiration' },
|
||||
});
|
||||
let metadata: RepresentationMetadata;
|
||||
let response: HttpResponse;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
metadata = new RepresentationMetadata();
|
||||
response = createResponse() as HttpResponse;
|
||||
});
|
||||
|
||||
it('adds no headers if there is no relevant metadata.', async(): Promise<void> => {
|
||||
await expect(writer.handle({ response, metadata })).resolves.toBeUndefined();
|
||||
expect(response.getHeaders()).toEqual({});
|
||||
});
|
||||
|
||||
it('adds the relevant set-cookie headers.', async(): Promise<void> => {
|
||||
const date = new Date('2015-10-21T07:28:00.000Z');
|
||||
metadata.add(namedNode('http://example.com/pred1'), literal('my-value'));
|
||||
metadata.add(namedNode('http://example.com/pred2'), literal('other-value'));
|
||||
metadata.add(namedNode('http://example.com/pred2expiration'), literal(date.toISOString()));
|
||||
metadata.add(namedNode('http://example.com/unknown'), literal('unknown-value'));
|
||||
await expect(writer.handle({ response, metadata })).resolves.toBeUndefined();
|
||||
expect(response.getHeader('set-cookie')).toEqual([
|
||||
'custom1=my-value; Path=/; SameSite=Lax',
|
||||
'custom2=other-value; Path=/; Expires=Wed, 21 Oct 2015 07:28:00 GMT; SameSite=Lax',
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user