mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Remove overused "Simple" prefix
This commit is contained in:
parent
6b8d57667b
commit
199d657097
@ -3,18 +3,18 @@
|
||||
"@graph": [
|
||||
{
|
||||
"@id": "urn:solid-server:default:AclManager",
|
||||
"@type": "SimpleExtensionAclManager"
|
||||
"@type": "UrlBasedAclManager"
|
||||
},
|
||||
{
|
||||
"@id": "urn:solid-server:default:AclAuthorizer",
|
||||
"@type": "SimpleAclAuthorizer",
|
||||
"SimpleAclAuthorizer:_aclManager": {
|
||||
"@type": "WebAclAuthorizer",
|
||||
"WebAclAuthorizer:_aclManager": {
|
||||
"@id": "urn:solid-server:default:AclManager"
|
||||
},
|
||||
"SimpleAclAuthorizer:_containerManager": {
|
||||
"WebAclAuthorizer:_containerManager": {
|
||||
"@id": "urn:solid-server:default:UrlContainerManager"
|
||||
},
|
||||
"SimpleAclAuthorizer:_resourceStore": {
|
||||
"WebAclAuthorizer:_resourceStore": {
|
||||
"@id": "urn:solid-server:default:ResourceStore_Patching"
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
"@id": "urn:solid-server:default:OperationHandler"
|
||||
},
|
||||
"AuthenticatedLdpHandler:_responseWriter": {
|
||||
"@type": "SimpleResponseWriter"
|
||||
"@type": "BasicResponseWriter"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -3,7 +3,7 @@
|
||||
"@graph": [
|
||||
{
|
||||
"@id": "urn:solid-server:default:CredentialsExtractor",
|
||||
"@type": "SimpleCredentialsExtractor"
|
||||
"@type": "UnsecureWebIdExtractor"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -6,32 +6,32 @@
|
||||
"@type": "CompositeAsyncHandler",
|
||||
"CompositeAsyncHandler:_handlers": [
|
||||
{
|
||||
"@type": "SimpleDeleteOperationHandler",
|
||||
"SimpleDeleteOperationHandler:_store": {
|
||||
"@type": "DeleteOperationHandler",
|
||||
"DeleteOperationHandler:_store": {
|
||||
"@id": "urn:solid-server:default:ResourceStore_Patching"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "SimpleGetOperationHandler",
|
||||
"SimpleGetOperationHandler:_store": {
|
||||
"@type": "GetOperationHandler",
|
||||
"GetOperationHandler:_store": {
|
||||
"@id": "urn:solid-server:default:ResourceStore_Patching"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "SimplePatchOperationHandler",
|
||||
"SimplePatchOperationHandler:_store": {
|
||||
"@type": "PatchOperationHandler",
|
||||
"PatchOperationHandler:_store": {
|
||||
"@id": "urn:solid-server:default:ResourceStore_Patching"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "SimplePostOperationHandler",
|
||||
"SimplePostOperationHandler:_store": {
|
||||
"@type": "PostOperationHandler",
|
||||
"PostOperationHandler:_store": {
|
||||
"@id": "urn:solid-server:default:ResourceStore_Patching"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "SimplePutOperationHandler",
|
||||
"SimplePutOperationHandler:_store": {
|
||||
"@type": "PutOperationHandler",
|
||||
"PutOperationHandler:_store": {
|
||||
"@id": "urn:solid-server:default:ResourceStore_Patching"
|
||||
}
|
||||
}
|
||||
|
@ -3,21 +3,21 @@
|
||||
"@graph": [
|
||||
{
|
||||
"@id": "urn:solid-server:default:RequestParser",
|
||||
"@type": "SimpleRequestParser",
|
||||
"SimpleRequestParser:_targetExtractor": {
|
||||
"@type": "SimpleTargetExtractor"
|
||||
"@type": "BasicRequestParser",
|
||||
"BasicRequestParser:_targetExtractor": {
|
||||
"@type": "BasicTargetExtractor"
|
||||
},
|
||||
"SimpleRequestParser:_preferenceParser": {
|
||||
"BasicRequestParser:_preferenceParser": {
|
||||
"@type": "AcceptPreferenceParser"
|
||||
},
|
||||
"SimpleRequestParser:_bodyParser": {
|
||||
"BasicRequestParser:_bodyParser": {
|
||||
"@type": "CompositeAsyncHandler",
|
||||
"CompositeAsyncHandler:_handlers": [
|
||||
{
|
||||
"@type": "SimpleSparqlUpdateBodyParser"
|
||||
"@type": "SparqlUpdateBodyParser"
|
||||
},
|
||||
{
|
||||
"@type": "SimpleBodyParser"
|
||||
"@type": "RawBodyParser"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -3,8 +3,8 @@
|
||||
"@graph": [
|
||||
{
|
||||
"@id": "urn:solid-server:default:ResourceStore",
|
||||
"@type": "SimpleResourceStore",
|
||||
"SimpleResourceStore:_runtimeConfig": {
|
||||
"@type": "InMemoryResourceStore",
|
||||
"InMemoryResourceStore:_runtimeConfig": {
|
||||
"@id": "urn:solid-server:default:RuntimeConfig"
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,11 @@
|
||||
},
|
||||
"PatchingStore:_patcher": {
|
||||
"@id": "urn:solid-server:default:PatchHandler",
|
||||
"@type": "SimpleSparqlUpdatePatchHandler",
|
||||
"SimpleSparqlUpdatePatchHandler:_source": {
|
||||
"@type": "SparqlUpdatePatchHandler",
|
||||
"SparqlUpdatePatchHandler:_source": {
|
||||
"@id": "urn:solid-server:default:ResourceStore_Converting"
|
||||
},
|
||||
"SimpleSparqlUpdatePatchHandler:_locker": {
|
||||
"SparqlUpdatePatchHandler:_locker": {
|
||||
"@id": "urn:solid-server:default:ResourceLocker"
|
||||
}
|
||||
}
|
||||
|
32
index.ts
32
index.ts
@ -1,14 +1,14 @@
|
||||
// Authentication
|
||||
export * from './src/authentication/Credentials';
|
||||
export * from './src/authentication/CredentialsExtractor';
|
||||
export * from './src/authentication/SimpleCredentialsExtractor';
|
||||
export * from './src/authentication/UnsecureWebIdExtractor';
|
||||
|
||||
// Authorization
|
||||
export * from './src/authorization/AllowEverythingAuthorizer';
|
||||
export * from './src/authorization/AclManager';
|
||||
export * from './src/authorization/Authorizer';
|
||||
export * from './src/authorization/SimpleAclAuthorizer';
|
||||
export * from './src/authorization/SimpleAuthorizer';
|
||||
export * from './src/authorization/SimpleExtensionAclManager';
|
||||
export * from './src/authorization/UrlBasedAclManager';
|
||||
export * from './src/authorization/WebAclAuthorizer';
|
||||
|
||||
// Init
|
||||
export * from './src/init/CliRunner';
|
||||
@ -17,28 +17,28 @@ export * from './src/init/Setup';
|
||||
|
||||
// LDP/HTTP
|
||||
export * from './src/ldp/http/AcceptPreferenceParser';
|
||||
export * from './src/ldp/http/BasicRequestParser';
|
||||
export * from './src/ldp/http/BasicResponseWriter';
|
||||
export * from './src/ldp/http/BasicTargetExtractor';
|
||||
export * from './src/ldp/http/BodyParser';
|
||||
export * from './src/ldp/http/Patch';
|
||||
export * from './src/ldp/http/PreferenceParser';
|
||||
export * from './src/ldp/http/RawBodyParser';
|
||||
export * from './src/ldp/http/RequestParser';
|
||||
export * from './src/ldp/http/ResponseWriter';
|
||||
export * from './src/ldp/http/SimpleBodyParser';
|
||||
export * from './src/ldp/http/SimpleRequestParser';
|
||||
export * from './src/ldp/http/SimpleResponseWriter';
|
||||
export * from './src/ldp/http/SimpleSparqlUpdateBodyParser';
|
||||
export * from './src/ldp/http/SimpleTargetExtractor';
|
||||
export * from './src/ldp/http/SparqlUpdateBodyParser';
|
||||
export * from './src/ldp/http/SparqlUpdatePatch';
|
||||
export * from './src/ldp/http/TargetExtractor';
|
||||
|
||||
// LDP/Operations
|
||||
export * from './src/ldp/operations/DeleteOperationHandler';
|
||||
export * from './src/ldp/operations/GetOperationHandler';
|
||||
export * from './src/ldp/operations/Operation';
|
||||
export * from './src/ldp/operations/OperationHandler';
|
||||
export * from './src/ldp/operations/PatchOperationHandler';
|
||||
export * from './src/ldp/operations/PostOperationHandler';
|
||||
export * from './src/ldp/operations/PutOperationHandler';
|
||||
export * from './src/ldp/operations/ResponseDescription';
|
||||
export * from './src/ldp/operations/SimpleDeleteOperationHandler';
|
||||
export * from './src/ldp/operations/SimpleGetOperationHandler';
|
||||
export * from './src/ldp/operations/SimplePatchOperationHandler';
|
||||
export * from './src/ldp/operations/SimplePostOperationHandler';
|
||||
export * from './src/ldp/operations/SimplePutOperationHandler';
|
||||
|
||||
// LDP/Permissions
|
||||
export * from './src/ldp/permissions/PermissionSet';
|
||||
@ -75,12 +75,13 @@ export * from './src/storage/conversion/TypedRepresentationConverter';
|
||||
|
||||
// Storage/Patch
|
||||
export * from './src/storage/patch/PatchHandler';
|
||||
export * from './src/storage/patch/SimpleSparqlUpdatePatchHandler';
|
||||
export * from './src/storage/patch/SparqlUpdatePatchHandler';
|
||||
|
||||
// Storage
|
||||
export * from './src/storage/AtomicResourceStore';
|
||||
export * from './src/storage/Conditions';
|
||||
export * from './src/storage/ContainerManager';
|
||||
export * from './src/storage/InMemoryResourceStore';
|
||||
export * from './src/storage/Lock';
|
||||
export * from './src/storage/LockingResourceStore';
|
||||
export * from './src/storage/PassthroughStore';
|
||||
@ -90,7 +91,6 @@ export * from './src/storage/ResourceLocker';
|
||||
export * from './src/storage/ResourceMapper';
|
||||
export * from './src/storage/ResourceStore';
|
||||
export * from './src/storage/SingleThreadedResourceLocker';
|
||||
export * from './src/storage/SimpleResourceStore';
|
||||
export * from './src/storage/UrlContainerManager';
|
||||
|
||||
// Util/Errors
|
||||
|
@ -5,15 +5,12 @@ import { CredentialsExtractor } from './CredentialsExtractor';
|
||||
/**
|
||||
* Credentials extractor which simply interprets the contents of the Authorization header as a webID.
|
||||
*/
|
||||
export class SimpleCredentialsExtractor extends CredentialsExtractor {
|
||||
export class UnsecureWebIdExtractor extends CredentialsExtractor {
|
||||
public async canHandle(): Promise<void> {
|
||||
// Supports all requests
|
||||
}
|
||||
|
||||
public async handle(input: HttpRequest): Promise<Credentials> {
|
||||
if (input.headers.authorization) {
|
||||
return { webID: input.headers.authorization };
|
||||
}
|
||||
return {};
|
||||
return { webID: input.headers.authorization };
|
||||
}
|
||||
}
|
14
src/authorization/AllowEverythingAuthorizer.ts
Normal file
14
src/authorization/AllowEverythingAuthorizer.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { Authorizer } from './Authorizer';
|
||||
|
||||
/**
|
||||
* Authorizer which allows all access independent of the identifier and requested permissions.
|
||||
*/
|
||||
export class AllowEverythingAuthorizer extends Authorizer {
|
||||
public async canHandle(): Promise<void> {
|
||||
// Can handle all requests
|
||||
}
|
||||
|
||||
public async handle(): Promise<void> {
|
||||
// Allows all actions
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
import { UnsupportedHttpError } from '../util/errors/UnsupportedHttpError';
|
||||
import { Authorizer, AuthorizerArgs } from './Authorizer';
|
||||
|
||||
/**
|
||||
* Authorizer which allows all access independent of the identifier and requested permissions.
|
||||
*/
|
||||
export class SimpleAuthorizer extends Authorizer {
|
||||
public async canHandle(input: AuthorizerArgs): Promise<void> {
|
||||
if (!input.identifier || !input.permissions) {
|
||||
throw new UnsupportedHttpError('Authorizer requires an identifier and permissions.');
|
||||
}
|
||||
}
|
||||
|
||||
public async handle(): Promise<void> {
|
||||
// Allows all actions
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ import { AclManager } from './AclManager';
|
||||
* It is potentially possible that an agent wants to generate the acl file before generating the actual file.
|
||||
* (Unless this is not allowed by the spec, need to verify).
|
||||
*/
|
||||
export class SimpleExtensionAclManager implements AclManager {
|
||||
export class UrlBasedAclManager implements AclManager {
|
||||
public async getAcl(id: ResourceIdentifier): Promise<ResourceIdentifier> {
|
||||
return await this.isAcl(id) ? id : { path: `${id.path}.acl` };
|
||||
}
|
@ -18,7 +18,7 @@ import { Authorizer, AuthorizerArgs } from './Authorizer';
|
||||
* `acl:mode`, `acl:agentClass`, `acl:agent`, `acl:default` and `acl:accessTo`.
|
||||
* Does not support `acl:agentGroup`, `acl:origin` and `acl:trustedApp` yet.
|
||||
*/
|
||||
export class SimpleAclAuthorizer extends Authorizer {
|
||||
export class WebAclAuthorizer extends Authorizer {
|
||||
private readonly aclManager: AclManager;
|
||||
private readonly containerManager: ContainerManager;
|
||||
private readonly resourceStore: ResourceStore;
|
@ -6,7 +6,7 @@ import { RequestParser } from './RequestParser';
|
||||
import { TargetExtractor } from './TargetExtractor';
|
||||
|
||||
/**
|
||||
* Input parsers required for a {@link SimpleRequestParser}.
|
||||
* Input parsers required for a {@link BasicRequestParser}.
|
||||
*/
|
||||
export interface SimpleRequestParserArgs {
|
||||
targetExtractor: TargetExtractor;
|
||||
@ -18,7 +18,7 @@ export interface SimpleRequestParserArgs {
|
||||
* Creates an {@link Operation} from an incoming {@link HttpRequest} by aggregating the results
|
||||
* of a {@link TargetExtractor}, {@link PreferenceParser}, and {@link BodyParser}.
|
||||
*/
|
||||
export class SimpleRequestParser extends RequestParser {
|
||||
export class BasicRequestParser extends RequestParser {
|
||||
private readonly targetExtractor!: TargetExtractor;
|
||||
private readonly preferenceParser!: PreferenceParser;
|
||||
private readonly bodyParser!: BodyParser;
|
@ -7,8 +7,9 @@ import { ResponseWriter } from './ResponseWriter';
|
||||
|
||||
/**
|
||||
* Writes to an {@link HttpResponse} based on the incoming {@link ResponseDescription} or error.
|
||||
* Still needs a way to write correct status codes for successful operations.
|
||||
*/
|
||||
export class SimpleResponseWriter extends ResponseWriter {
|
||||
export class BasicResponseWriter extends ResponseWriter {
|
||||
public async canHandle(input: { response: HttpResponse; result: ResponseDescription | Error }): Promise<void> {
|
||||
if (!(input.result instanceof Error)) {
|
||||
const dataType = input.result.body?.dataType;
|
@ -6,13 +6,17 @@ import { TargetExtractor } from './TargetExtractor';
|
||||
|
||||
/**
|
||||
* Extracts an identifier from an incoming {@link HttpRequest}.
|
||||
* Simply takes the input URl without any parsing/cleaning.
|
||||
* Uses URL library for basic parsing.
|
||||
* TODO: input requires more extensive cleaning/parsing based on headers (see #22).
|
||||
*/
|
||||
export class SimpleTargetExtractor extends TargetExtractor {
|
||||
export class BasicTargetExtractor extends TargetExtractor {
|
||||
public async canHandle(input: HttpRequest): Promise<void> {
|
||||
if (!input.url) {
|
||||
throw new Error('Missing URL.');
|
||||
}
|
||||
if (!input.headers.host) {
|
||||
throw new Error('Missing host.');
|
||||
}
|
||||
}
|
||||
|
||||
public async handle(input: HttpRequest): Promise<ResourceIdentifier> {
|
@ -8,11 +8,11 @@ import { BodyParser } from './BodyParser';
|
||||
/**
|
||||
* Converts incoming {@link HttpRequest} to a Representation without any further parsing.
|
||||
* Naively parses the mediatype from the content-type header.
|
||||
* Metadata is not generated (yet).
|
||||
* Some other metadata is also generated, but this should probably be done in an external handler.
|
||||
*/
|
||||
export class SimpleBodyParser extends BodyParser {
|
||||
export class RawBodyParser extends BodyParser {
|
||||
public async canHandle(): Promise<void> {
|
||||
// Default BodyParser supports all content-types
|
||||
// All content-types are supported
|
||||
}
|
||||
|
||||
// Note that the only reason this is a union is in case the body is empty.
|
@ -11,9 +11,9 @@ import { SparqlUpdatePatch } from './SparqlUpdatePatch';
|
||||
/**
|
||||
* {@link BodyParser} that supports `application/sparql-update` content.
|
||||
* Will convert the incoming update string to algebra in a {@link SparqlUpdatePatch}.
|
||||
* Simple since metadata parsing is not yet implemented.
|
||||
* Still needs access to a handler for parsing metadata.
|
||||
*/
|
||||
export class SimpleSparqlUpdateBodyParser extends BodyParser {
|
||||
export class SparqlUpdateBodyParser extends BodyParser {
|
||||
public async canHandle(input: HttpRequest): Promise<void> {
|
||||
const contentType = input.headers['content-type'];
|
||||
|
@ -8,7 +8,7 @@ import { ResponseDescription } from './ResponseDescription';
|
||||
* Handles DELETE {@link Operation}s.
|
||||
* Calls the deleteResource function from a {@link ResourceStore}.
|
||||
*/
|
||||
export class SimpleDeleteOperationHandler extends OperationHandler {
|
||||
export class DeleteOperationHandler extends OperationHandler {
|
||||
private readonly store: ResourceStore;
|
||||
|
||||
public constructor(store: ResourceStore) {
|
@ -8,7 +8,7 @@ import { ResponseDescription } from './ResponseDescription';
|
||||
* Handles GET {@link Operation}s.
|
||||
* Calls the getRepresentation function from a {@link ResourceStore}.
|
||||
*/
|
||||
export class SimpleGetOperationHandler extends OperationHandler {
|
||||
export class GetOperationHandler extends OperationHandler {
|
||||
private readonly store: ResourceStore;
|
||||
|
||||
public constructor(store: ResourceStore) {
|
@ -5,7 +5,7 @@ import { Operation } from './Operation';
|
||||
import { OperationHandler } from './OperationHandler';
|
||||
import { ResponseDescription } from './ResponseDescription';
|
||||
|
||||
export class SimplePatchOperationHandler extends OperationHandler {
|
||||
export class PatchOperationHandler extends OperationHandler {
|
||||
private readonly store: ResourceStore;
|
||||
|
||||
public constructor(store: ResourceStore) {
|
@ -8,7 +8,7 @@ import { ResponseDescription } from './ResponseDescription';
|
||||
* Handles POST {@link Operation}s.
|
||||
* Calls the addResource function from a {@link ResourceStore}.
|
||||
*/
|
||||
export class SimplePostOperationHandler extends OperationHandler {
|
||||
export class PostOperationHandler extends OperationHandler {
|
||||
private readonly store: ResourceStore;
|
||||
|
||||
public constructor(store: ResourceStore) {
|
@ -8,7 +8,7 @@ import { ResponseDescription } from './ResponseDescription';
|
||||
* Handles PUT {@link Operation}s.
|
||||
* Calls the setRepresentation function from a {@link ResourceStore}.
|
||||
*/
|
||||
export class SimplePutOperationHandler extends OperationHandler {
|
||||
export class PutOperationHandler extends OperationHandler {
|
||||
private readonly store: ResourceStore;
|
||||
|
||||
public constructor(store: ResourceStore) {
|
@ -10,9 +10,9 @@ import { ResourceStore } from './ResourceStore';
|
||||
|
||||
/**
|
||||
* Resource store storing its data in an in-memory map.
|
||||
* All requests will throw an {@link NotFoundHttpError} if unknown identifiers get passed.
|
||||
* Current Solid functionality support is quite basic: containers are not really supported for example.
|
||||
*/
|
||||
export class SimpleResourceStore implements ResourceStore {
|
||||
export class InMemoryResourceStore implements ResourceStore {
|
||||
private readonly store: { [id: string]: Representation };
|
||||
private readonly runtimeConfig: RuntimeConfig;
|
||||
private index = 0;
|
@ -17,7 +17,7 @@ import { PatchHandler } from './PatchHandler';
|
||||
* PatchHandler that supports specific types of SPARQL updates.
|
||||
* Currently all DELETE/INSERT types are supported that have empty where bodies and no variables.
|
||||
*/
|
||||
export class SimpleSparqlUpdatePatchHandler extends PatchHandler {
|
||||
export class SparqlUpdatePatchHandler extends PatchHandler {
|
||||
private readonly source: ResourceStore;
|
||||
private readonly locker: ResourceLocker;
|
||||
|
@ -2,57 +2,57 @@ import * as url from 'url';
|
||||
import { namedNode, quad } from '@rdfjs/data-model';
|
||||
import { Parser } from 'n3';
|
||||
import { MockResponse } from 'node-mocks-http';
|
||||
import { SimpleCredentialsExtractor } from '../../src/authentication/SimpleCredentialsExtractor';
|
||||
import { SimpleAuthorizer } from '../../src/authorization/SimpleAuthorizer';
|
||||
import { UnsecureWebIdExtractor } from '../../src/authentication/UnsecureWebIdExtractor';
|
||||
import { AllowEverythingAuthorizer } from '../../src/authorization/AllowEverythingAuthorizer';
|
||||
import { RuntimeConfig } from '../../src/init/RuntimeConfig';
|
||||
import { AuthenticatedLdpHandler } from '../../src/ldp/AuthenticatedLdpHandler';
|
||||
import { AcceptPreferenceParser } from '../../src/ldp/http/AcceptPreferenceParser';
|
||||
import { BasicRequestParser } from '../../src/ldp/http/BasicRequestParser';
|
||||
import { BasicResponseWriter } from '../../src/ldp/http/BasicResponseWriter';
|
||||
import { BasicTargetExtractor } from '../../src/ldp/http/BasicTargetExtractor';
|
||||
import { BodyParser } from '../../src/ldp/http/BodyParser';
|
||||
import { SimpleBodyParser } from '../../src/ldp/http/SimpleBodyParser';
|
||||
import { SimpleRequestParser } from '../../src/ldp/http/SimpleRequestParser';
|
||||
import { SimpleResponseWriter } from '../../src/ldp/http/SimpleResponseWriter';
|
||||
import { SimpleSparqlUpdateBodyParser } from '../../src/ldp/http/SimpleSparqlUpdateBodyParser';
|
||||
import { SimpleTargetExtractor } from '../../src/ldp/http/SimpleTargetExtractor';
|
||||
import { RawBodyParser } from '../../src/ldp/http/RawBodyParser';
|
||||
import { SparqlUpdateBodyParser } from '../../src/ldp/http/SparqlUpdateBodyParser';
|
||||
import { DeleteOperationHandler } from '../../src/ldp/operations/DeleteOperationHandler';
|
||||
import { GetOperationHandler } from '../../src/ldp/operations/GetOperationHandler';
|
||||
import { Operation } from '../../src/ldp/operations/Operation';
|
||||
import { PatchOperationHandler } from '../../src/ldp/operations/PatchOperationHandler';
|
||||
import { PostOperationHandler } from '../../src/ldp/operations/PostOperationHandler';
|
||||
import { ResponseDescription } from '../../src/ldp/operations/ResponseDescription';
|
||||
import { SimpleDeleteOperationHandler } from '../../src/ldp/operations/SimpleDeleteOperationHandler';
|
||||
import { SimpleGetOperationHandler } from '../../src/ldp/operations/SimpleGetOperationHandler';
|
||||
import { SimplePatchOperationHandler } from '../../src/ldp/operations/SimplePatchOperationHandler';
|
||||
import { SimplePostOperationHandler } from '../../src/ldp/operations/SimplePostOperationHandler';
|
||||
import { BasePermissionsExtractor } from '../../src/ldp/permissions/BasePermissionsExtractor';
|
||||
import { SparqlPatchPermissionsExtractor } from '../../src/ldp/permissions/SparqlPatchPermissionsExtractor';
|
||||
import { Representation } from '../../src/ldp/representation/Representation';
|
||||
import { HttpRequest } from '../../src/server/HttpRequest';
|
||||
import { QuadToTurtleConverter } from '../../src/storage/conversion/QuadToTurtleConverter';
|
||||
import { TurtleToQuadConverter } from '../../src/storage/conversion/TurtleToQuadConverter';
|
||||
import { SimpleSparqlUpdatePatchHandler } from '../../src/storage/patch/SimpleSparqlUpdatePatchHandler';
|
||||
import { InMemoryResourceStore } from '../../src/storage/InMemoryResourceStore';
|
||||
import { SparqlUpdatePatchHandler } from '../../src/storage/patch/SparqlUpdatePatchHandler';
|
||||
import { PatchingStore } from '../../src/storage/PatchingStore';
|
||||
import { RepresentationConvertingStore } from '../../src/storage/RepresentationConvertingStore';
|
||||
import { SimpleResourceStore } from '../../src/storage/SimpleResourceStore';
|
||||
import { SingleThreadedResourceLocker } from '../../src/storage/SingleThreadedResourceLocker';
|
||||
import { CompositeAsyncHandler } from '../../src/util/CompositeAsyncHandler';
|
||||
import { call } from '../util/Util';
|
||||
|
||||
describe('An integrated AuthenticatedLdpHandler', (): void => {
|
||||
describe('with simple handlers', (): void => {
|
||||
const requestParser = new SimpleRequestParser({
|
||||
targetExtractor: new SimpleTargetExtractor(),
|
||||
const requestParser = new BasicRequestParser({
|
||||
targetExtractor: new BasicTargetExtractor(),
|
||||
preferenceParser: new AcceptPreferenceParser(),
|
||||
bodyParser: new SimpleBodyParser(),
|
||||
bodyParser: new RawBodyParser(),
|
||||
});
|
||||
|
||||
const credentialsExtractor = new SimpleCredentialsExtractor();
|
||||
const credentialsExtractor = new UnsecureWebIdExtractor();
|
||||
const permissionsExtractor = new BasePermissionsExtractor();
|
||||
const authorizer = new SimpleAuthorizer();
|
||||
const authorizer = new AllowEverythingAuthorizer();
|
||||
|
||||
const store = new SimpleResourceStore(new RuntimeConfig({ base: 'http://test.com/' }));
|
||||
const store = new InMemoryResourceStore(new RuntimeConfig({ base: 'http://test.com/' }));
|
||||
const operationHandler = new CompositeAsyncHandler<Operation, ResponseDescription>([
|
||||
new SimpleGetOperationHandler(store),
|
||||
new SimplePostOperationHandler(store),
|
||||
new SimpleDeleteOperationHandler(store),
|
||||
new GetOperationHandler(store),
|
||||
new PostOperationHandler(store),
|
||||
new DeleteOperationHandler(store),
|
||||
]);
|
||||
|
||||
const responseWriter = new SimpleResponseWriter();
|
||||
const responseWriter = new BasicResponseWriter();
|
||||
|
||||
const handler = new AuthenticatedLdpHandler({
|
||||
requestParser,
|
||||
@ -100,40 +100,40 @@ describe('An integrated AuthenticatedLdpHandler', (): void => {
|
||||
|
||||
describe('with simple PATCH handlers', (): void => {
|
||||
const bodyParser: BodyParser = new CompositeAsyncHandler<HttpRequest, Representation | undefined>([
|
||||
new SimpleSparqlUpdateBodyParser(),
|
||||
new SimpleBodyParser(),
|
||||
new SparqlUpdateBodyParser(),
|
||||
new RawBodyParser(),
|
||||
]);
|
||||
const requestParser = new SimpleRequestParser({
|
||||
targetExtractor: new SimpleTargetExtractor(),
|
||||
const requestParser = new BasicRequestParser({
|
||||
targetExtractor: new BasicTargetExtractor(),
|
||||
preferenceParser: new AcceptPreferenceParser(),
|
||||
bodyParser,
|
||||
});
|
||||
|
||||
const credentialsExtractor = new SimpleCredentialsExtractor();
|
||||
const credentialsExtractor = new UnsecureWebIdExtractor();
|
||||
const permissionsExtractor = new CompositeAsyncHandler([
|
||||
new BasePermissionsExtractor(),
|
||||
new SparqlPatchPermissionsExtractor(),
|
||||
]);
|
||||
const authorizer = new SimpleAuthorizer();
|
||||
const authorizer = new AllowEverythingAuthorizer();
|
||||
|
||||
const store = new SimpleResourceStore(new RuntimeConfig({ base: 'http://test.com/' }));
|
||||
const store = new InMemoryResourceStore(new RuntimeConfig({ base: 'http://test.com/' }));
|
||||
const converter = new CompositeAsyncHandler([
|
||||
new QuadToTurtleConverter(),
|
||||
new TurtleToQuadConverter(),
|
||||
]);
|
||||
const convertingStore = new RepresentationConvertingStore(store, converter);
|
||||
const locker = new SingleThreadedResourceLocker();
|
||||
const patcher = new SimpleSparqlUpdatePatchHandler(convertingStore, locker);
|
||||
const patcher = new SparqlUpdatePatchHandler(convertingStore, locker);
|
||||
const patchingStore = new PatchingStore(convertingStore, patcher);
|
||||
|
||||
const operationHandler = new CompositeAsyncHandler<Operation, ResponseDescription>([
|
||||
new SimpleGetOperationHandler(patchingStore),
|
||||
new SimplePostOperationHandler(patchingStore),
|
||||
new SimpleDeleteOperationHandler(patchingStore),
|
||||
new SimplePatchOperationHandler(patchingStore),
|
||||
new GetOperationHandler(patchingStore),
|
||||
new PostOperationHandler(patchingStore),
|
||||
new DeleteOperationHandler(patchingStore),
|
||||
new PatchOperationHandler(patchingStore),
|
||||
]);
|
||||
|
||||
const responseWriter = new SimpleResponseWriter();
|
||||
const responseWriter = new BasicResponseWriter();
|
||||
|
||||
const handler = new AuthenticatedLdpHandler({
|
||||
requestParser,
|
||||
|
@ -1,29 +1,29 @@
|
||||
import { MockResponse } from 'node-mocks-http';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { SimpleCredentialsExtractor } from '../../src/authentication/SimpleCredentialsExtractor';
|
||||
import { SimpleAclAuthorizer } from '../../src/authorization/SimpleAclAuthorizer';
|
||||
import { SimpleExtensionAclManager } from '../../src/authorization/SimpleExtensionAclManager';
|
||||
import { UnsecureWebIdExtractor } from '../../src/authentication/UnsecureWebIdExtractor';
|
||||
import { UrlBasedAclManager } from '../../src/authorization/UrlBasedAclManager';
|
||||
import { WebAclAuthorizer } from '../../src/authorization/WebAclAuthorizer';
|
||||
import { RuntimeConfig } from '../../src/init/RuntimeConfig';
|
||||
import { AuthenticatedLdpHandler } from '../../src/ldp/AuthenticatedLdpHandler';
|
||||
import { AcceptPreferenceParser } from '../../src/ldp/http/AcceptPreferenceParser';
|
||||
import { BasicRequestParser } from '../../src/ldp/http/BasicRequestParser';
|
||||
import { BasicResponseWriter } from '../../src/ldp/http/BasicResponseWriter';
|
||||
import { BasicTargetExtractor } from '../../src/ldp/http/BasicTargetExtractor';
|
||||
import { BodyParser } from '../../src/ldp/http/BodyParser';
|
||||
import { SimpleBodyParser } from '../../src/ldp/http/SimpleBodyParser';
|
||||
import { SimpleRequestParser } from '../../src/ldp/http/SimpleRequestParser';
|
||||
import { SimpleResponseWriter } from '../../src/ldp/http/SimpleResponseWriter';
|
||||
import { SimpleTargetExtractor } from '../../src/ldp/http/SimpleTargetExtractor';
|
||||
import { RawBodyParser } from '../../src/ldp/http/RawBodyParser';
|
||||
import { DeleteOperationHandler } from '../../src/ldp/operations/DeleteOperationHandler';
|
||||
import { GetOperationHandler } from '../../src/ldp/operations/GetOperationHandler';
|
||||
import { Operation } from '../../src/ldp/operations/Operation';
|
||||
import { PostOperationHandler } from '../../src/ldp/operations/PostOperationHandler';
|
||||
import { PutOperationHandler } from '../../src/ldp/operations/PutOperationHandler';
|
||||
import { ResponseDescription } from '../../src/ldp/operations/ResponseDescription';
|
||||
import { SimpleDeleteOperationHandler } from '../../src/ldp/operations/SimpleDeleteOperationHandler';
|
||||
import { SimpleGetOperationHandler } from '../../src/ldp/operations/SimpleGetOperationHandler';
|
||||
import { SimplePostOperationHandler } from '../../src/ldp/operations/SimplePostOperationHandler';
|
||||
import { SimplePutOperationHandler } from '../../src/ldp/operations/SimplePutOperationHandler';
|
||||
import { BasePermissionsExtractor } from '../../src/ldp/permissions/BasePermissionsExtractor';
|
||||
import { PermissionSet } from '../../src/ldp/permissions/PermissionSet';
|
||||
import { QuadToTurtleConverter } from '../../src/storage/conversion/QuadToTurtleConverter';
|
||||
import { TurtleToQuadConverter } from '../../src/storage/conversion/TurtleToQuadConverter';
|
||||
import { InMemoryResourceStore } from '../../src/storage/InMemoryResourceStore';
|
||||
import { RepresentationConvertingStore } from '../../src/storage/RepresentationConvertingStore';
|
||||
import { ResourceStore } from '../../src/storage/ResourceStore';
|
||||
import { SimpleResourceStore } from '../../src/storage/SimpleResourceStore';
|
||||
import { UrlContainerManager } from '../../src/storage/UrlContainerManager';
|
||||
import { CompositeAsyncHandler } from '../../src/util/CompositeAsyncHandler';
|
||||
import { DATA_TYPE_BINARY } from '../../src/util/ContentTypes';
|
||||
@ -74,36 +74,36 @@ const setAcl = async(store: ResourceStore, id: string, permissions: PermissionSe
|
||||
};
|
||||
|
||||
describe('A server with authorization', (): void => {
|
||||
const bodyParser: BodyParser = new SimpleBodyParser();
|
||||
const requestParser = new SimpleRequestParser({
|
||||
targetExtractor: new SimpleTargetExtractor(),
|
||||
const bodyParser: BodyParser = new RawBodyParser();
|
||||
const requestParser = new BasicRequestParser({
|
||||
targetExtractor: new BasicTargetExtractor(),
|
||||
preferenceParser: new AcceptPreferenceParser(),
|
||||
bodyParser,
|
||||
});
|
||||
|
||||
const store = new SimpleResourceStore(new RuntimeConfig({ base: 'http://test.com/' }));
|
||||
const store = new InMemoryResourceStore(new RuntimeConfig({ base: 'http://test.com/' }));
|
||||
const converter = new CompositeAsyncHandler([
|
||||
new QuadToTurtleConverter(),
|
||||
new TurtleToQuadConverter(),
|
||||
]);
|
||||
const convertingStore = new RepresentationConvertingStore(store, converter);
|
||||
|
||||
const credentialsExtractor = new SimpleCredentialsExtractor();
|
||||
const credentialsExtractor = new UnsecureWebIdExtractor();
|
||||
const permissionsExtractor = new BasePermissionsExtractor();
|
||||
const authorizer = new SimpleAclAuthorizer(
|
||||
new SimpleExtensionAclManager(),
|
||||
const authorizer = new WebAclAuthorizer(
|
||||
new UrlBasedAclManager(),
|
||||
new UrlContainerManager(new RuntimeConfig({ base: 'http://test.com/' })),
|
||||
convertingStore,
|
||||
);
|
||||
|
||||
const operationHandler = new CompositeAsyncHandler<Operation, ResponseDescription>([
|
||||
new SimpleGetOperationHandler(convertingStore),
|
||||
new SimplePostOperationHandler(convertingStore),
|
||||
new SimpleDeleteOperationHandler(convertingStore),
|
||||
new SimplePutOperationHandler(convertingStore),
|
||||
new GetOperationHandler(convertingStore),
|
||||
new PostOperationHandler(convertingStore),
|
||||
new DeleteOperationHandler(convertingStore),
|
||||
new PutOperationHandler(convertingStore),
|
||||
]);
|
||||
|
||||
const responseWriter = new SimpleResponseWriter();
|
||||
const responseWriter = new BasicResponseWriter();
|
||||
|
||||
const handler = new AuthenticatedLdpHandler({
|
||||
requestParser,
|
||||
|
@ -2,17 +2,17 @@ import { Readable } from 'stream';
|
||||
import arrayifyStream from 'arrayify-stream';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { AcceptPreferenceParser } from '../../src/ldp/http/AcceptPreferenceParser';
|
||||
import { SimpleBodyParser } from '../../src/ldp/http/SimpleBodyParser';
|
||||
import { SimpleRequestParser } from '../../src/ldp/http/SimpleRequestParser';
|
||||
import { SimpleTargetExtractor } from '../../src/ldp/http/SimpleTargetExtractor';
|
||||
import { BasicRequestParser } from '../../src/ldp/http/BasicRequestParser';
|
||||
import { BasicTargetExtractor } from '../../src/ldp/http/BasicTargetExtractor';
|
||||
import { RawBodyParser } from '../../src/ldp/http/RawBodyParser';
|
||||
import { HttpRequest } from '../../src/server/HttpRequest';
|
||||
import { DATA_TYPE_BINARY } from '../../src/util/ContentTypes';
|
||||
|
||||
describe('A SimpleRequestParser with simple input parsers', (): void => {
|
||||
const targetExtractor = new SimpleTargetExtractor();
|
||||
const bodyParser = new SimpleBodyParser();
|
||||
const targetExtractor = new BasicTargetExtractor();
|
||||
const bodyParser = new RawBodyParser();
|
||||
const preferenceParser = new AcceptPreferenceParser();
|
||||
const requestParser = new SimpleRequestParser({ targetExtractor, bodyParser, preferenceParser });
|
||||
const requestParser = new BasicRequestParser({ targetExtractor, bodyParser, preferenceParser });
|
||||
|
||||
it('can parse an incoming request.', async(): Promise<void> => {
|
||||
const request = streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.com/o>.' ]) as HttpRequest;
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { SimpleCredentialsExtractor } from '../../../src/authentication/SimpleCredentialsExtractor';
|
||||
import { UnsecureWebIdExtractor } from '../../../src/authentication/UnsecureWebIdExtractor';
|
||||
import { HttpRequest } from '../../../src/server/HttpRequest';
|
||||
|
||||
describe('A SimpleCredentialsExtractor', (): void => {
|
||||
const extractor = new SimpleCredentialsExtractor();
|
||||
describe('An UnsecureWebIdExtractor', (): void => {
|
||||
const extractor = new UnsecureWebIdExtractor();
|
||||
|
||||
it('can handle all input.', async(): Promise<void> => {
|
||||
await expect(extractor.canHandle()).resolves.toBeUndefined();
|
13
test/unit/authorization/AllowEverythingAuthorizer.test.ts
Normal file
13
test/unit/authorization/AllowEverythingAuthorizer.test.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { AllowEverythingAuthorizer } from '../../../src/authorization/AllowEverythingAuthorizer';
|
||||
|
||||
describe('An AllowEverythingAuthorizer', (): void => {
|
||||
const authorizer = new AllowEverythingAuthorizer();
|
||||
|
||||
it('can handle everything.', async(): Promise<void> => {
|
||||
await expect(authorizer.canHandle()).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('always returns undefined.', async(): Promise<void> => {
|
||||
await expect(authorizer.handle()).resolves.toBeUndefined();
|
||||
});
|
||||
});
|
@ -1,17 +0,0 @@
|
||||
import { AuthorizerArgs } from '../../../src/authorization/Authorizer';
|
||||
import { SimpleAuthorizer } from '../../../src/authorization/SimpleAuthorizer';
|
||||
import { UnsupportedHttpError } from '../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A SimpleAuthorizer', (): void => {
|
||||
const authorizer = new SimpleAuthorizer();
|
||||
|
||||
it('requires input to have an identifier and permissions.', async(): Promise<void> => {
|
||||
await expect(authorizer.canHandle({ identifier: {}, permissions: {}} as AuthorizerArgs)).resolves.toBeUndefined();
|
||||
await expect(authorizer.canHandle({ identifier: {}} as AuthorizerArgs)).rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(authorizer.canHandle({ permissions: {}} as AuthorizerArgs)).rejects.toThrow(UnsupportedHttpError);
|
||||
});
|
||||
|
||||
it('always returns undefined.', async(): Promise<void> => {
|
||||
await expect(authorizer.handle()).resolves.toBeUndefined();
|
||||
});
|
||||
});
|
@ -1,7 +1,7 @@
|
||||
import { SimpleExtensionAclManager } from '../../../src/authorization/SimpleExtensionAclManager';
|
||||
import { UrlBasedAclManager } from '../../../src/authorization/UrlBasedAclManager';
|
||||
|
||||
describe('A SimpleExtensionAclManager', (): void => {
|
||||
const manager = new SimpleExtensionAclManager();
|
||||
describe('An UrlBasedAclManager', (): void => {
|
||||
const manager = new UrlBasedAclManager();
|
||||
|
||||
it('generates acl URLs by adding an .acl extension.', async(): Promise<void> => {
|
||||
await expect(manager.getAcl({ path: '/foo/bar' })).resolves.toEqual({ path: '/foo/bar.acl' });
|
@ -2,7 +2,7 @@ import { namedNode, quad } from '@rdfjs/data-model';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { Credentials } from '../../../src/authentication/Credentials';
|
||||
import { AclManager } from '../../../src/authorization/AclManager';
|
||||
import { SimpleAclAuthorizer } from '../../../src/authorization/SimpleAclAuthorizer';
|
||||
import { WebAclAuthorizer } from '../../../src/authorization/WebAclAuthorizer';
|
||||
import { PermissionSet } from '../../../src/ldp/permissions/PermissionSet';
|
||||
import { Representation } from '../../../src/ldp/representation/Representation';
|
||||
import { ResourceIdentifier } from '../../../src/ldp/representation/ResourceIdentifier';
|
||||
@ -16,8 +16,8 @@ const nn = namedNode;
|
||||
|
||||
const acl = 'http://www.w3.org/ns/auth/acl#';
|
||||
|
||||
describe('A SimpleAclAuthorizer', (): void => {
|
||||
let authorizer: SimpleAclAuthorizer;
|
||||
describe('A WebAclAuthorizer', (): void => {
|
||||
let authorizer: WebAclAuthorizer;
|
||||
const aclManager: AclManager = {
|
||||
getAcl: async(id: ResourceIdentifier): Promise<ResourceIdentifier> =>
|
||||
id.path.endsWith('.acl') ? id : { path: `${id.path}.acl` },
|
||||
@ -42,7 +42,7 @@ describe('A SimpleAclAuthorizer', (): void => {
|
||||
});
|
||||
|
||||
it('handles all inputs.', async(): Promise<void> => {
|
||||
authorizer = new SimpleAclAuthorizer(aclManager, containerManager, null as any);
|
||||
authorizer = new WebAclAuthorizer(aclManager, containerManager, null as any);
|
||||
await expect(authorizer.canHandle()).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
@ -54,7 +54,7 @@ describe('A SimpleAclAuthorizer', (): void => {
|
||||
quad(nn('auth'), nn(`${acl}mode`), nn(`${acl}Read`)),
|
||||
]) } as Representation),
|
||||
} as unknown as ResourceStore;
|
||||
authorizer = new SimpleAclAuthorizer(aclManager, containerManager, store);
|
||||
authorizer = new WebAclAuthorizer(aclManager, containerManager, store);
|
||||
await expect(authorizer.handle({ identifier, permissions, credentials })).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
@ -73,7 +73,7 @@ describe('A SimpleAclAuthorizer', (): void => {
|
||||
} as Representation;
|
||||
},
|
||||
} as unknown as ResourceStore;
|
||||
authorizer = new SimpleAclAuthorizer(aclManager, containerManager, store);
|
||||
authorizer = new WebAclAuthorizer(aclManager, containerManager, store);
|
||||
await expect(authorizer.handle({ identifier, permissions, credentials })).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
@ -85,7 +85,7 @@ describe('A SimpleAclAuthorizer', (): void => {
|
||||
quad(nn('auth'), nn(`${acl}mode`), nn(`${acl}Read`)),
|
||||
]) } as Representation),
|
||||
} as unknown as ResourceStore;
|
||||
authorizer = new SimpleAclAuthorizer(aclManager, containerManager, store);
|
||||
authorizer = new WebAclAuthorizer(aclManager, containerManager, store);
|
||||
credentials.webID = 'http://test.com/user';
|
||||
await expect(authorizer.handle({ identifier, permissions, credentials })).resolves.toBeUndefined();
|
||||
});
|
||||
@ -98,7 +98,7 @@ describe('A SimpleAclAuthorizer', (): void => {
|
||||
quad(nn('auth'), nn(`${acl}mode`), nn(`${acl}Read`)),
|
||||
]) } as Representation),
|
||||
} as unknown as ResourceStore;
|
||||
authorizer = new SimpleAclAuthorizer(aclManager, containerManager, store);
|
||||
authorizer = new WebAclAuthorizer(aclManager, containerManager, store);
|
||||
await expect(authorizer.handle({ identifier, permissions, credentials })).rejects.toThrow(UnauthorizedHttpError);
|
||||
});
|
||||
|
||||
@ -111,7 +111,7 @@ describe('A SimpleAclAuthorizer', (): void => {
|
||||
quad(nn('auth'), nn(`${acl}mode`), nn(`${acl}Read`)),
|
||||
]) } as Representation),
|
||||
} as unknown as ResourceStore;
|
||||
authorizer = new SimpleAclAuthorizer(aclManager, containerManager, store);
|
||||
authorizer = new WebAclAuthorizer(aclManager, containerManager, store);
|
||||
await expect(authorizer.handle({ identifier, permissions, credentials })).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
@ -124,7 +124,7 @@ describe('A SimpleAclAuthorizer', (): void => {
|
||||
quad(nn('auth'), nn(`${acl}mode`), nn(`${acl}Read`)),
|
||||
]) } as Representation),
|
||||
} as unknown as ResourceStore;
|
||||
authorizer = new SimpleAclAuthorizer(aclManager, containerManager, store);
|
||||
authorizer = new WebAclAuthorizer(aclManager, containerManager, store);
|
||||
await expect(authorizer.handle({ identifier, permissions, credentials })).rejects.toThrow(ForbiddenHttpError);
|
||||
});
|
||||
|
||||
@ -139,7 +139,7 @@ describe('A SimpleAclAuthorizer', (): void => {
|
||||
]) } as Representation),
|
||||
} as unknown as ResourceStore;
|
||||
identifier = await aclManager.getAcl(identifier);
|
||||
authorizer = new SimpleAclAuthorizer(aclManager, containerManager, store);
|
||||
authorizer = new WebAclAuthorizer(aclManager, containerManager, store);
|
||||
await expect(authorizer.handle({ identifier, permissions, credentials })).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
@ -154,7 +154,7 @@ describe('A SimpleAclAuthorizer', (): void => {
|
||||
]) } as Representation),
|
||||
} as unknown as ResourceStore;
|
||||
identifier = await aclManager.getAcl(identifier);
|
||||
authorizer = new SimpleAclAuthorizer(aclManager, containerManager, store);
|
||||
authorizer = new WebAclAuthorizer(aclManager, containerManager, store);
|
||||
await expect(authorizer.handle({ identifier, permissions, credentials })).rejects.toThrow(ForbiddenHttpError);
|
||||
});
|
||||
|
||||
@ -164,7 +164,7 @@ describe('A SimpleAclAuthorizer', (): void => {
|
||||
throw new Error('TEST!');
|
||||
},
|
||||
} as unknown as ResourceStore;
|
||||
authorizer = new SimpleAclAuthorizer(aclManager, containerManager, store);
|
||||
authorizer = new WebAclAuthorizer(aclManager, containerManager, store);
|
||||
await expect(authorizer.handle({ identifier, permissions, credentials })).rejects.toThrow('TEST!');
|
||||
});
|
||||
});
|
@ -1,20 +1,20 @@
|
||||
import { BasicRequestParser } from '../../../../src/ldp/http/BasicRequestParser';
|
||||
import { BodyParser } from '../../../../src/ldp/http/BodyParser';
|
||||
import { PreferenceParser } from '../../../../src/ldp/http/PreferenceParser';
|
||||
import { SimpleRequestParser } from '../../../../src/ldp/http/SimpleRequestParser';
|
||||
import { TargetExtractor } from '../../../../src/ldp/http/TargetExtractor';
|
||||
import { StaticAsyncHandler } from '../../../util/StaticAsyncHandler';
|
||||
|
||||
describe('A SimpleRequestParser', (): void => {
|
||||
describe('A BasicRequestParser', (): void => {
|
||||
let targetExtractor: TargetExtractor;
|
||||
let bodyParser: BodyParser;
|
||||
let preferenceParser: PreferenceParser;
|
||||
let requestParser: SimpleRequestParser;
|
||||
let requestParser: BasicRequestParser;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
targetExtractor = new StaticAsyncHandler(true, 'target' as any);
|
||||
bodyParser = new StaticAsyncHandler(true, 'body' as any);
|
||||
preferenceParser = new StaticAsyncHandler(true, 'preference' as any);
|
||||
requestParser = new SimpleRequestParser({ targetExtractor, bodyParser, preferenceParser });
|
||||
requestParser = new BasicRequestParser({ targetExtractor, bodyParser, preferenceParser });
|
||||
});
|
||||
|
||||
it('can handle input with both a URL and a method.', async(): Promise<void> => {
|
@ -2,13 +2,13 @@ import { EventEmitter } from 'events';
|
||||
import { createResponse, MockResponse } from 'node-mocks-http';
|
||||
import { Quad } from 'rdf-js';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { SimpleResponseWriter } from '../../../../src/ldp/http/SimpleResponseWriter';
|
||||
import { BasicResponseWriter } from '../../../../src/ldp/http/BasicResponseWriter';
|
||||
import { ResponseDescription } from '../../../../src/ldp/operations/ResponseDescription';
|
||||
import { DATA_TYPE_BINARY, DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A SimpleResponseWriter', (): void => {
|
||||
const writer = new SimpleResponseWriter();
|
||||
describe('A BasicResponseWriter', (): void => {
|
||||
const writer = new BasicResponseWriter();
|
||||
let response: MockResponse<any>;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
27
test/unit/ldp/http/BasicTargetExtractor.test.ts
Normal file
27
test/unit/ldp/http/BasicTargetExtractor.test.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { BasicTargetExtractor } from '../../../../src/ldp/http/BasicTargetExtractor';
|
||||
|
||||
describe('A BasicTargetExtractor', (): void => {
|
||||
const extractor = new BasicTargetExtractor();
|
||||
|
||||
it('can handle input with an URL and host.', async(): Promise<void> => {
|
||||
await expect(extractor.canHandle({ url: 'url', headers: { host: 'test.com' }} as any)).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('rejects input without URL.', async(): Promise<void> => {
|
||||
await expect(extractor.canHandle({ headers: { host: 'test.com' }} as any)).rejects.toThrow('Missing URL.');
|
||||
});
|
||||
|
||||
it('rejects input without host.', async(): Promise<void> => {
|
||||
await expect(extractor.canHandle({ url: 'url', headers: {}} as any)).rejects.toThrow('Missing host.');
|
||||
});
|
||||
|
||||
it('returns the input URL.', async(): Promise<void> => {
|
||||
await expect(extractor.handle({ url: 'url', headers: { host: 'test.com' }} as any)).resolves.toEqual({ path: 'http://test.com/url' });
|
||||
});
|
||||
|
||||
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' });
|
||||
});
|
||||
});
|
@ -1,13 +1,13 @@
|
||||
import arrayifyStream from 'arrayify-stream';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { SimpleBodyParser } from '../../../../src/ldp/http/SimpleBodyParser';
|
||||
import { RawBodyParser } from '../../../../src/ldp/http/RawBodyParser';
|
||||
import { HttpRequest } from '../../../../src/server/HttpRequest';
|
||||
import { DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import 'jest-rdf';
|
||||
|
||||
describe('A SimpleBodyparser', (): void => {
|
||||
const bodyParser = new SimpleBodyParser();
|
||||
describe('A RawBodyparser', (): void => {
|
||||
const bodyParser = new RawBodyParser();
|
||||
|
||||
it('accepts all input.', async(): Promise<void> => {
|
||||
await expect(bodyParser.canHandle()).resolves.toBeUndefined();
|
@ -1,23 +0,0 @@
|
||||
import { SimpleTargetExtractor } from '../../../../src/ldp/http/SimpleTargetExtractor';
|
||||
|
||||
describe('A SimpleTargetExtractor', (): void => {
|
||||
const extractor = new SimpleTargetExtractor();
|
||||
|
||||
it('can handle input with an URL.', async(): Promise<void> => {
|
||||
await expect(extractor.canHandle({ url: 'url' } as any)).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('rejects input without URL.', async(): Promise<void> => {
|
||||
await expect(extractor.canHandle({ } as any)).rejects.toThrow('Missing URL.');
|
||||
});
|
||||
|
||||
it('returns the input URL.', async(): Promise<void> => {
|
||||
await expect(extractor.handle({ url: 'url', headers: { host: 'test.com' }} as any)).resolves.toEqual({ path: 'http://test.com/url' });
|
||||
});
|
||||
|
||||
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' });
|
||||
});
|
||||
});
|
@ -2,14 +2,14 @@ import { namedNode, quad } from '@rdfjs/data-model';
|
||||
import arrayifyStream from 'arrayify-stream';
|
||||
import { Algebra } from 'sparqlalgebrajs';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { SimpleSparqlUpdateBodyParser } from '../../../../src/ldp/http/SimpleSparqlUpdateBodyParser';
|
||||
import { SparqlUpdateBodyParser } from '../../../../src/ldp/http/SparqlUpdateBodyParser';
|
||||
import { HttpRequest } from '../../../../src/server/HttpRequest';
|
||||
import { DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { UnsupportedMediaTypeHttpError } from '../../../../src/util/errors/UnsupportedMediaTypeHttpError';
|
||||
|
||||
describe('A SimpleSparqlUpdateBodyParser', (): void => {
|
||||
const bodyParser = new SimpleSparqlUpdateBodyParser();
|
||||
describe('A SparqlUpdateBodyParser', (): void => {
|
||||
const bodyParser = new SparqlUpdateBodyParser();
|
||||
|
||||
it('only accepts application/sparql-update content.', async(): Promise<void> => {
|
||||
await expect(bodyParser.canHandle({ headers: {}} as HttpRequest)).rejects.toThrow(UnsupportedMediaTypeHttpError);
|
@ -1,11 +1,11 @@
|
||||
import { DeleteOperationHandler } from '../../../../src/ldp/operations/DeleteOperationHandler';
|
||||
import { Operation } from '../../../../src/ldp/operations/Operation';
|
||||
import { SimpleDeleteOperationHandler } from '../../../../src/ldp/operations/SimpleDeleteOperationHandler';
|
||||
import { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A SimpleDeleteOperationHandler', (): void => {
|
||||
describe('A DeleteOperationHandler', (): void => {
|
||||
const store = {} as unknown as ResourceStore;
|
||||
const handler = new SimpleDeleteOperationHandler(store);
|
||||
const handler = new DeleteOperationHandler(store);
|
||||
beforeEach(async(): Promise<void> => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
store.deleteResource = jest.fn(async(): Promise<void> => {});
|
@ -1,15 +1,15 @@
|
||||
import { GetOperationHandler } from '../../../../src/ldp/operations/GetOperationHandler';
|
||||
import { Operation } from '../../../../src/ldp/operations/Operation';
|
||||
import { SimpleGetOperationHandler } from '../../../../src/ldp/operations/SimpleGetOperationHandler';
|
||||
import { Representation } from '../../../../src/ldp/representation/Representation';
|
||||
import { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A SimpleGetOperationHandler', (): void => {
|
||||
describe('A GetOperationHandler', (): void => {
|
||||
const store = {
|
||||
getRepresentation: async(): Promise<Representation> => ({ dataType: DATA_TYPE_QUAD } as Representation),
|
||||
} as unknown as ResourceStore;
|
||||
const handler = new SimpleGetOperationHandler(store);
|
||||
const handler = new GetOperationHandler(store);
|
||||
|
||||
it('only supports GET operations.', async(): Promise<void> => {
|
||||
await expect(handler.canHandle({ method: 'GET' } as Operation)).resolves.toBeUndefined();
|
@ -1,16 +1,16 @@
|
||||
import { Operation } from '../../../../src/ldp/operations/Operation';
|
||||
import { SimplePatchOperationHandler } from '../../../../src/ldp/operations/SimplePatchOperationHandler';
|
||||
import { PatchOperationHandler } from '../../../../src/ldp/operations/PatchOperationHandler';
|
||||
import { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A SimplePatchOperationHandler', (): void => {
|
||||
describe('A PatchOperationHandler', (): void => {
|
||||
const store = {} as unknown as ResourceStore;
|
||||
const handler = new SimplePatchOperationHandler(store);
|
||||
const handler = new PatchOperationHandler(store);
|
||||
beforeEach(async(): Promise<void> => {
|
||||
store.modifyResource = jest.fn(async(): Promise<void> => undefined);
|
||||
});
|
||||
|
||||
it('only supports GET operations.', async(): Promise<void> => {
|
||||
it('only supports PATCH operations.', async(): Promise<void> => {
|
||||
await expect(handler.canHandle({ method: 'PATCH' } as Operation)).resolves.toBeUndefined();
|
||||
await expect(handler.canHandle({ method: 'GET' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
});
|
@ -1,14 +1,14 @@
|
||||
import { Operation } from '../../../../src/ldp/operations/Operation';
|
||||
import { SimplePostOperationHandler } from '../../../../src/ldp/operations/SimplePostOperationHandler';
|
||||
import { PostOperationHandler } from '../../../../src/ldp/operations/PostOperationHandler';
|
||||
import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A SimplePostOperationHandler', (): void => {
|
||||
describe('A PostOperationHandler', (): void => {
|
||||
const store = {
|
||||
addResource: async(): Promise<ResourceIdentifier> => ({ path: 'newPath' } as ResourceIdentifier),
|
||||
} as unknown as ResourceStore;
|
||||
const handler = new SimplePostOperationHandler(store);
|
||||
const handler = new PostOperationHandler(store);
|
||||
|
||||
it('only supports POST operations with a body.', async(): Promise<void> => {
|
||||
await expect(handler.canHandle({ method: 'POST', body: { dataType: 'test' }} as Operation))
|
@ -1,11 +1,11 @@
|
||||
import { Operation } from '../../../../src/ldp/operations/Operation';
|
||||
import { SimplePutOperationHandler } from '../../../../src/ldp/operations/SimplePutOperationHandler';
|
||||
import { PutOperationHandler } from '../../../../src/ldp/operations/PutOperationHandler';
|
||||
import { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A SimplePutOperationHandler', (): void => {
|
||||
describe('A PutOperationHandler', (): void => {
|
||||
const store = {} as unknown as ResourceStore;
|
||||
const handler = new SimplePutOperationHandler(store);
|
||||
const handler = new PutOperationHandler(store);
|
||||
beforeEach(async(): Promise<void> => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
store.setRepresentation = jest.fn(async(): Promise<void> => {});
|
@ -4,19 +4,19 @@ import streamifyArray from 'streamify-array';
|
||||
import { RuntimeConfig } from '../../../src/init/RuntimeConfig';
|
||||
import { BinaryRepresentation } from '../../../src/ldp/representation/BinaryRepresentation';
|
||||
import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata';
|
||||
import { SimpleResourceStore } from '../../../src/storage/SimpleResourceStore';
|
||||
import { InMemoryResourceStore } from '../../../src/storage/InMemoryResourceStore';
|
||||
import { DATA_TYPE_BINARY } from '../../../src/util/ContentTypes';
|
||||
import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError';
|
||||
|
||||
const base = 'http://test.com/';
|
||||
|
||||
describe('A SimpleResourceStore', (): void => {
|
||||
let store: SimpleResourceStore;
|
||||
describe('A InMemoryResourceStore', (): void => {
|
||||
let store: InMemoryResourceStore;
|
||||
let representation: BinaryRepresentation;
|
||||
const dataString = '<http://test.com/s> <http://test.com/p> <http://test.com/o>.';
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
store = new SimpleResourceStore(new RuntimeConfig({ base }));
|
||||
store = new InMemoryResourceStore(new RuntimeConfig({ base }));
|
||||
|
||||
representation = {
|
||||
data: streamifyArray([ dataString ]),
|
@ -5,14 +5,14 @@ import { translate } from 'sparqlalgebrajs';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { SparqlUpdatePatch } from '../../../../src/ldp/http/SparqlUpdatePatch';
|
||||
import { Lock } from '../../../../src/storage/Lock';
|
||||
import { SimpleSparqlUpdatePatchHandler } from '../../../../src/storage/patch/SimpleSparqlUpdatePatchHandler';
|
||||
import { SparqlUpdatePatchHandler } from '../../../../src/storage/patch/SparqlUpdatePatchHandler';
|
||||
import { ResourceLocker } from '../../../../src/storage/ResourceLocker';
|
||||
import { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A SimpleSparqlUpdatePatchHandler', (): void => {
|
||||
let handler: SimpleSparqlUpdatePatchHandler;
|
||||
describe('A SparqlUpdatePatchHandler', (): void => {
|
||||
let handler: SparqlUpdatePatchHandler;
|
||||
let locker: ResourceLocker;
|
||||
let lock: Lock;
|
||||
let release: () => Promise<void>;
|
||||
@ -59,7 +59,7 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => {
|
||||
}),
|
||||
};
|
||||
|
||||
handler = new SimpleSparqlUpdatePatchHandler(source, locker);
|
||||
handler = new SparqlUpdatePatchHandler(source, locker);
|
||||
});
|
||||
|
||||
const basicChecks = async(quads: Quad[]): Promise<void> => {
|
Loading…
x
Reference in New Issue
Block a user