mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
test: Use Components.js in AuthenticatedLdpHandler.
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
import type {
|
||||
HttpHandler,
|
||||
ResourceStore,
|
||||
} from '../../src/index';
|
||||
import {
|
||||
AllowEverythingAuthorizer,
|
||||
AuthenticatedLdpHandler,
|
||||
EmptyCredentialsExtractor,
|
||||
MethodPermissionsExtractor,
|
||||
} from '../../src/index';
|
||||
import type { ServerConfig } from './ServerConfig';
|
||||
import { getOperationHandler, getInMemoryResourceStore, getBasicRequestParser, getResponseWriter } from './Util';
|
||||
|
||||
/**
|
||||
* BasicConfig works with
|
||||
* - an AllowEverythingAuthorizer (no acl)
|
||||
* - an InMemoryResourceStore
|
||||
* - GET, POST & DELETE operation handlers
|
||||
*/
|
||||
|
||||
export class BasicConfig implements ServerConfig {
|
||||
public store: ResourceStore;
|
||||
|
||||
public constructor() {
|
||||
this.store = getInMemoryResourceStore();
|
||||
}
|
||||
|
||||
public getHttpHandler(): HttpHandler {
|
||||
const requestParser = getBasicRequestParser();
|
||||
|
||||
const credentialsExtractor = new EmptyCredentialsExtractor();
|
||||
const permissionsExtractor = new MethodPermissionsExtractor();
|
||||
const authorizer = new AllowEverythingAuthorizer();
|
||||
|
||||
const operationHandler = getOperationHandler(this.store);
|
||||
|
||||
const responseWriter = getResponseWriter();
|
||||
|
||||
const handler = new AuthenticatedLdpHandler({
|
||||
requestParser,
|
||||
credentialsExtractor,
|
||||
permissionsExtractor,
|
||||
authorizer,
|
||||
operationHandler,
|
||||
responseWriter,
|
||||
});
|
||||
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
import type {
|
||||
HttpHandler,
|
||||
ResourceStore,
|
||||
} from '../../src/index';
|
||||
import {
|
||||
AllowEverythingAuthorizer,
|
||||
AuthenticatedLdpHandler,
|
||||
EmptyCredentialsExtractor,
|
||||
MethodPermissionsExtractor,
|
||||
QuadToRdfConverter,
|
||||
RawBodyParser,
|
||||
RdfToQuadConverter,
|
||||
SparqlUpdateBodyParser,
|
||||
SparqlPatchPermissionsExtractor,
|
||||
WaterfallHandler,
|
||||
} from '../../src/index';
|
||||
|
||||
import type { ServerConfig } from './ServerConfig';
|
||||
import {
|
||||
getInMemoryResourceStore,
|
||||
getOperationHandler,
|
||||
getConvertingStore,
|
||||
getPatchingStore,
|
||||
getBasicRequestParser,
|
||||
getResponseWriter,
|
||||
} from './Util';
|
||||
|
||||
/**
|
||||
* BasicHandlersConfig works with
|
||||
* - an AllowEverythingAuthorizer (no acl)
|
||||
* - an InMemoryResourceStore wrapped in a converting store & wrapped in a patching store
|
||||
* - GET, POST, PUT, PATCH & DELETE operation handlers
|
||||
*/
|
||||
|
||||
export class BasicHandlersConfig implements ServerConfig {
|
||||
public store: ResourceStore;
|
||||
|
||||
public constructor() {
|
||||
const convertingStore = getConvertingStore(
|
||||
getInMemoryResourceStore(),
|
||||
[ new QuadToRdfConverter(), new RdfToQuadConverter() ],
|
||||
);
|
||||
this.store = getPatchingStore(convertingStore);
|
||||
}
|
||||
|
||||
public getHttpHandler(): HttpHandler {
|
||||
const requestParser = getBasicRequestParser([
|
||||
new SparqlUpdateBodyParser(),
|
||||
new RawBodyParser(),
|
||||
]);
|
||||
|
||||
const credentialsExtractor = new EmptyCredentialsExtractor();
|
||||
const permissionsExtractor = new WaterfallHandler([
|
||||
new MethodPermissionsExtractor(),
|
||||
new SparqlPatchPermissionsExtractor(),
|
||||
]);
|
||||
const authorizer = new AllowEverythingAuthorizer();
|
||||
|
||||
const operationHandler = getOperationHandler(this.store);
|
||||
|
||||
const responseWriter = getResponseWriter();
|
||||
|
||||
const handler = new AuthenticatedLdpHandler({
|
||||
requestParser,
|
||||
credentialsExtractor,
|
||||
permissionsExtractor,
|
||||
authorizer,
|
||||
operationHandler,
|
||||
responseWriter,
|
||||
});
|
||||
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
@@ -3,24 +3,23 @@ import * as url from 'url';
|
||||
import { namedNode, quad } from '@rdfjs/data-model';
|
||||
import { Parser } from 'n3';
|
||||
import type { MockResponse } from 'node-mocks-http';
|
||||
import { RootContainerInitializer } from '../../src/init/RootContainerInitializer';
|
||||
import type { HttpHandler } from '../../src/server/HttpHandler';
|
||||
import { LDP } from '../../src/util/UriConstants';
|
||||
import { BasicConfig } from '../configs/BasicConfig';
|
||||
import { BasicHandlersConfig } from '../configs/BasicHandlersConfig';
|
||||
import { BASE } from '../configs/Util';
|
||||
import { BASE, instantiateFromConfig } from '../configs/Util';
|
||||
import { call } from '../util/Util';
|
||||
|
||||
describe('An integrated AuthenticatedLdpHandler', (): void => {
|
||||
let handler: HttpHandler;
|
||||
|
||||
beforeAll(async(): Promise<void> => {
|
||||
handler = await instantiateFromConfig(
|
||||
'urn:solid-server:default:LdpHandler', 'auth-allow-all.json', {
|
||||
'urn:solid-server:default:variable:baseUrl': BASE,
|
||||
},
|
||||
) as HttpHandler;
|
||||
});
|
||||
|
||||
describe('with simple handlers', (): void => {
|
||||
const config = new BasicConfig();
|
||||
const handler = config.getHttpHandler();
|
||||
|
||||
beforeAll(async(): Promise<void> => {
|
||||
// Initialize store
|
||||
const initializer = new RootContainerInitializer(BASE, config.store);
|
||||
await initializer.handleSafe();
|
||||
});
|
||||
|
||||
it('can add, read and delete data based on incoming requests.', async(): Promise<void> => {
|
||||
// POST
|
||||
let requestUrl = new URL('http://test.com/');
|
||||
@@ -70,15 +69,6 @@ describe('An integrated AuthenticatedLdpHandler', (): void => {
|
||||
});
|
||||
|
||||
describe('with simple PATCH handlers', (): void => {
|
||||
const config = new BasicHandlersConfig();
|
||||
const handler = config.getHttpHandler();
|
||||
|
||||
beforeAll(async(): Promise<void> => {
|
||||
// Initialize store
|
||||
const initializer = new RootContainerInitializer(BASE, config.store);
|
||||
await initializer.handleSafe();
|
||||
});
|
||||
|
||||
it('can handle simple SPARQL updates.', async(): Promise<void> => {
|
||||
// POST
|
||||
let requestUrl = new URL('http://test.com/');
|
||||
@@ -142,15 +132,6 @@ describe('An integrated AuthenticatedLdpHandler', (): void => {
|
||||
});
|
||||
|
||||
describe('with simple PUT handlers', (): void => {
|
||||
const config = new BasicHandlersConfig();
|
||||
const handler = config.getHttpHandler();
|
||||
|
||||
beforeAll(async(): Promise<void> => {
|
||||
// Initialize store
|
||||
const initializer = new RootContainerInitializer(BASE, config.store);
|
||||
await initializer.handleSafe();
|
||||
});
|
||||
|
||||
it('should overwrite the content on PUT request.', async(): Promise<void> => {
|
||||
// POST
|
||||
let requestUrl = new URL('http://test.com/');
|
||||
|
||||
Reference in New Issue
Block a user