diff --git a/config/presets/acl.json b/config/presets/acl.json index 2b8560bc7..0ed6b46e8 100644 --- a/config/presets/acl.json +++ b/config/presets/acl.json @@ -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" } } diff --git a/config/presets/ldp.json b/config/presets/ldp.json index 2c4987d05..0471a27dd 100644 --- a/config/presets/ldp.json +++ b/config/presets/ldp.json @@ -20,7 +20,7 @@ "@id": "urn:solid-server:default:OperationHandler" }, "AuthenticatedLdpHandler:_responseWriter": { - "@type": "SimpleResponseWriter" + "@type": "BasicResponseWriter" } } ] diff --git a/config/presets/ldp/credentials-extractor.json b/config/presets/ldp/credentials-extractor.json index 7fc0543d5..7d6b53850 100644 --- a/config/presets/ldp/credentials-extractor.json +++ b/config/presets/ldp/credentials-extractor.json @@ -3,7 +3,7 @@ "@graph": [ { "@id": "urn:solid-server:default:CredentialsExtractor", - "@type": "SimpleCredentialsExtractor" + "@type": "UnsecureWebIdExtractor" } ] } diff --git a/config/presets/ldp/operation-handler.json b/config/presets/ldp/operation-handler.json index db5bb2747..6ca76e7a1 100644 --- a/config/presets/ldp/operation-handler.json +++ b/config/presets/ldp/operation-handler.json @@ -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" } } diff --git a/config/presets/ldp/request-parser.json b/config/presets/ldp/request-parser.json index c4fccad11..f3422cc13 100644 --- a/config/presets/ldp/request-parser.json +++ b/config/presets/ldp/request-parser.json @@ -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" } ] } diff --git a/config/presets/storage.json b/config/presets/storage.json index 8e1f3a61e..3b00ef80e 100644 --- a/config/presets/storage.json +++ b/config/presets/storage.json @@ -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" } } diff --git a/config/presets/storage_wrapper.json b/config/presets/storage_wrapper.json index d545df89a..0cd962c7a 100644 --- a/config/presets/storage_wrapper.json +++ b/config/presets/storage_wrapper.json @@ -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" } } diff --git a/index.ts b/index.ts index 5a2972888..99c5d0d45 100644 --- a/index.ts +++ b/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 diff --git a/src/authentication/SimpleCredentialsExtractor.ts b/src/authentication/UnsecureWebIdExtractor.ts similarity index 69% rename from src/authentication/SimpleCredentialsExtractor.ts rename to src/authentication/UnsecureWebIdExtractor.ts index 757ccca5f..415956a0d 100644 --- a/src/authentication/SimpleCredentialsExtractor.ts +++ b/src/authentication/UnsecureWebIdExtractor.ts @@ -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 { // Supports all requests } public async handle(input: HttpRequest): Promise { - if (input.headers.authorization) { - return { webID: input.headers.authorization }; - } - return {}; + return { webID: input.headers.authorization }; } } diff --git a/src/authorization/AllowEverythingAuthorizer.ts b/src/authorization/AllowEverythingAuthorizer.ts new file mode 100644 index 000000000..222ac5178 --- /dev/null +++ b/src/authorization/AllowEverythingAuthorizer.ts @@ -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 { + // Can handle all requests + } + + public async handle(): Promise { + // Allows all actions + } +} diff --git a/src/authorization/SimpleAuthorizer.ts b/src/authorization/SimpleAuthorizer.ts deleted file mode 100644 index 6ca25b1ab..000000000 --- a/src/authorization/SimpleAuthorizer.ts +++ /dev/null @@ -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 { - if (!input.identifier || !input.permissions) { - throw new UnsupportedHttpError('Authorizer requires an identifier and permissions.'); - } - } - - public async handle(): Promise { - // Allows all actions - } -} diff --git a/src/authorization/SimpleExtensionAclManager.ts b/src/authorization/UrlBasedAclManager.ts similarity index 94% rename from src/authorization/SimpleExtensionAclManager.ts rename to src/authorization/UrlBasedAclManager.ts index dfcf4114b..a5f5849a6 100644 --- a/src/authorization/SimpleExtensionAclManager.ts +++ b/src/authorization/UrlBasedAclManager.ts @@ -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 { return await this.isAcl(id) ? id : { path: `${id.path}.acl` }; } diff --git a/src/authorization/SimpleAclAuthorizer.ts b/src/authorization/WebAclAuthorizer.ts similarity index 99% rename from src/authorization/SimpleAclAuthorizer.ts rename to src/authorization/WebAclAuthorizer.ts index d97a5c0da..fe53a4d78 100644 --- a/src/authorization/SimpleAclAuthorizer.ts +++ b/src/authorization/WebAclAuthorizer.ts @@ -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; diff --git a/src/ldp/http/SimpleRequestParser.ts b/src/ldp/http/BasicRequestParser.ts similarity index 92% rename from src/ldp/http/SimpleRequestParser.ts rename to src/ldp/http/BasicRequestParser.ts index a7b1add5d..d7df9ffce 100644 --- a/src/ldp/http/SimpleRequestParser.ts +++ b/src/ldp/http/BasicRequestParser.ts @@ -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; diff --git a/src/ldp/http/SimpleResponseWriter.ts b/src/ldp/http/BasicResponseWriter.ts similarity index 93% rename from src/ldp/http/SimpleResponseWriter.ts rename to src/ldp/http/BasicResponseWriter.ts index 78e621aa5..e8e5c5739 100644 --- a/src/ldp/http/SimpleResponseWriter.ts +++ b/src/ldp/http/BasicResponseWriter.ts @@ -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 { if (!(input.result instanceof Error)) { const dataType = input.result.body?.dataType; diff --git a/src/ldp/http/SimpleTargetExtractor.ts b/src/ldp/http/BasicTargetExtractor.ts similarity index 75% rename from src/ldp/http/SimpleTargetExtractor.ts rename to src/ldp/http/BasicTargetExtractor.ts index fe1c6b021..499bc09ab 100644 --- a/src/ldp/http/SimpleTargetExtractor.ts +++ b/src/ldp/http/BasicTargetExtractor.ts @@ -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 { if (!input.url) { throw new Error('Missing URL.'); } + if (!input.headers.host) { + throw new Error('Missing host.'); + } } public async handle(input: HttpRequest): Promise { diff --git a/src/ldp/http/SimpleBodyParser.ts b/src/ldp/http/RawBodyParser.ts similarity index 92% rename from src/ldp/http/SimpleBodyParser.ts rename to src/ldp/http/RawBodyParser.ts index 8c7b2ad3c..76f9132c4 100644 --- a/src/ldp/http/SimpleBodyParser.ts +++ b/src/ldp/http/RawBodyParser.ts @@ -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 { - // 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. diff --git a/src/ldp/http/SimpleSparqlUpdateBodyParser.ts b/src/ldp/http/SparqlUpdateBodyParser.ts similarity index 94% rename from src/ldp/http/SimpleSparqlUpdateBodyParser.ts rename to src/ldp/http/SparqlUpdateBodyParser.ts index 472bf0694..c2f915fde 100644 --- a/src/ldp/http/SimpleSparqlUpdateBodyParser.ts +++ b/src/ldp/http/SparqlUpdateBodyParser.ts @@ -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 { const contentType = input.headers['content-type']; diff --git a/src/ldp/operations/SimpleDeleteOperationHandler.ts b/src/ldp/operations/DeleteOperationHandler.ts similarity index 92% rename from src/ldp/operations/SimpleDeleteOperationHandler.ts rename to src/ldp/operations/DeleteOperationHandler.ts index 6a270d3df..17bac170e 100644 --- a/src/ldp/operations/SimpleDeleteOperationHandler.ts +++ b/src/ldp/operations/DeleteOperationHandler.ts @@ -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) { diff --git a/src/ldp/operations/SimpleGetOperationHandler.ts b/src/ldp/operations/GetOperationHandler.ts similarity index 93% rename from src/ldp/operations/SimpleGetOperationHandler.ts rename to src/ldp/operations/GetOperationHandler.ts index 0b810d1dc..4c96c1a9b 100644 --- a/src/ldp/operations/SimpleGetOperationHandler.ts +++ b/src/ldp/operations/GetOperationHandler.ts @@ -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) { diff --git a/src/ldp/operations/SimplePatchOperationHandler.ts b/src/ldp/operations/PatchOperationHandler.ts similarity index 92% rename from src/ldp/operations/SimplePatchOperationHandler.ts rename to src/ldp/operations/PatchOperationHandler.ts index 56823e601..e510f31ba 100644 --- a/src/ldp/operations/SimplePatchOperationHandler.ts +++ b/src/ldp/operations/PatchOperationHandler.ts @@ -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) { diff --git a/src/ldp/operations/SimplePostOperationHandler.ts b/src/ldp/operations/PostOperationHandler.ts similarity index 93% rename from src/ldp/operations/SimplePostOperationHandler.ts rename to src/ldp/operations/PostOperationHandler.ts index a484370f2..dc71415e6 100644 --- a/src/ldp/operations/SimplePostOperationHandler.ts +++ b/src/ldp/operations/PostOperationHandler.ts @@ -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) { diff --git a/src/ldp/operations/SimplePutOperationHandler.ts b/src/ldp/operations/PutOperationHandler.ts similarity index 94% rename from src/ldp/operations/SimplePutOperationHandler.ts rename to src/ldp/operations/PutOperationHandler.ts index 28821cfcd..841939234 100644 --- a/src/ldp/operations/SimplePutOperationHandler.ts +++ b/src/ldp/operations/PutOperationHandler.ts @@ -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) { diff --git a/src/storage/SimpleResourceStore.ts b/src/storage/InMemoryResourceStore.ts similarity index 96% rename from src/storage/SimpleResourceStore.ts rename to src/storage/InMemoryResourceStore.ts index 739cf3a5b..6934757f1 100644 --- a/src/storage/SimpleResourceStore.ts +++ b/src/storage/InMemoryResourceStore.ts @@ -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; diff --git a/src/storage/patch/SimpleSparqlUpdatePatchHandler.ts b/src/storage/patch/SparqlUpdatePatchHandler.ts similarity index 98% rename from src/storage/patch/SimpleSparqlUpdatePatchHandler.ts rename to src/storage/patch/SparqlUpdatePatchHandler.ts index c3e82a776..e66629b01 100644 --- a/src/storage/patch/SimpleSparqlUpdatePatchHandler.ts +++ b/src/storage/patch/SparqlUpdatePatchHandler.ts @@ -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; diff --git a/test/integration/AuthenticatedLdpHandler.test.ts b/test/integration/AuthenticatedLdpHandler.test.ts index 984d9cc5f..b2fe38815 100644 --- a/test/integration/AuthenticatedLdpHandler.test.ts +++ b/test/integration/AuthenticatedLdpHandler.test.ts @@ -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([ - 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([ - 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([ - 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, diff --git a/test/integration/Authorization.test.ts b/test/integration/Authorization.test.ts index 73badc941..8c6aff81b 100644 --- a/test/integration/Authorization.test.ts +++ b/test/integration/Authorization.test.ts @@ -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([ - 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, diff --git a/test/integration/RequestParser.test.ts b/test/integration/RequestParser.test.ts index 86867adc1..abcf4c40c 100644 --- a/test/integration/RequestParser.test.ts +++ b/test/integration/RequestParser.test.ts @@ -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 => { const request = streamifyArray([ ' .' ]) as HttpRequest; diff --git a/test/unit/authentication/SimpleCredentialsExtractor.test.ts b/test/unit/authentication/UnsecureWebIdExtractor.ts similarity index 74% rename from test/unit/authentication/SimpleCredentialsExtractor.test.ts rename to test/unit/authentication/UnsecureWebIdExtractor.ts index 3d97d4170..9461f71b9 100644 --- a/test/unit/authentication/SimpleCredentialsExtractor.test.ts +++ b/test/unit/authentication/UnsecureWebIdExtractor.ts @@ -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 => { await expect(extractor.canHandle()).resolves.toBeUndefined(); diff --git a/test/unit/authorization/AllowEverythingAuthorizer.test.ts b/test/unit/authorization/AllowEverythingAuthorizer.test.ts new file mode 100644 index 000000000..6f3de0dc8 --- /dev/null +++ b/test/unit/authorization/AllowEverythingAuthorizer.test.ts @@ -0,0 +1,13 @@ +import { AllowEverythingAuthorizer } from '../../../src/authorization/AllowEverythingAuthorizer'; + +describe('An AllowEverythingAuthorizer', (): void => { + const authorizer = new AllowEverythingAuthorizer(); + + it('can handle everything.', async(): Promise => { + await expect(authorizer.canHandle()).resolves.toBeUndefined(); + }); + + it('always returns undefined.', async(): Promise => { + await expect(authorizer.handle()).resolves.toBeUndefined(); + }); +}); diff --git a/test/unit/authorization/SimpleAuthorizer.test.ts b/test/unit/authorization/SimpleAuthorizer.test.ts deleted file mode 100644 index a8344f776..000000000 --- a/test/unit/authorization/SimpleAuthorizer.test.ts +++ /dev/null @@ -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 => { - 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 => { - await expect(authorizer.handle()).resolves.toBeUndefined(); - }); -}); diff --git a/test/unit/authorization/SimpleExtensionAclManager.test.ts b/test/unit/authorization/UrlBasedAclManager.test.ts similarity index 80% rename from test/unit/authorization/SimpleExtensionAclManager.test.ts rename to test/unit/authorization/UrlBasedAclManager.test.ts index 7604968e3..11b666f93 100644 --- a/test/unit/authorization/SimpleExtensionAclManager.test.ts +++ b/test/unit/authorization/UrlBasedAclManager.test.ts @@ -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 => { await expect(manager.getAcl({ path: '/foo/bar' })).resolves.toEqual({ path: '/foo/bar.acl' }); diff --git a/test/unit/authorization/SimpleAclAuthorizer.test.ts b/test/unit/authorization/WebAclAuthorizer.test.ts similarity index 88% rename from test/unit/authorization/SimpleAclAuthorizer.test.ts rename to test/unit/authorization/WebAclAuthorizer.test.ts index d5e0cc967..dbe2b2386 100644 --- a/test/unit/authorization/SimpleAclAuthorizer.test.ts +++ b/test/unit/authorization/WebAclAuthorizer.test.ts @@ -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 => id.path.endsWith('.acl') ? id : { path: `${id.path}.acl` }, @@ -42,7 +42,7 @@ describe('A SimpleAclAuthorizer', (): void => { }); it('handles all inputs.', async(): Promise => { - 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!'); }); }); diff --git a/test/unit/ldp/http/SimpleRequestParser.test.ts b/test/unit/ldp/http/BasicRequestParser.test.ts similarity index 84% rename from test/unit/ldp/http/SimpleRequestParser.test.ts rename to test/unit/ldp/http/BasicRequestParser.test.ts index b69578717..49678640a 100644 --- a/test/unit/ldp/http/SimpleRequestParser.test.ts +++ b/test/unit/ldp/http/BasicRequestParser.test.ts @@ -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 => { 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 => { diff --git a/test/unit/ldp/http/SimpleResponseWriter.test.ts b/test/unit/ldp/http/BasicResponseWriter.test.ts similarity index 95% rename from test/unit/ldp/http/SimpleResponseWriter.test.ts rename to test/unit/ldp/http/BasicResponseWriter.test.ts index c66767902..e6c63f79c 100644 --- a/test/unit/ldp/http/SimpleResponseWriter.test.ts +++ b/test/unit/ldp/http/BasicResponseWriter.test.ts @@ -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; beforeEach(async(): Promise => { diff --git a/test/unit/ldp/http/BasicTargetExtractor.test.ts b/test/unit/ldp/http/BasicTargetExtractor.test.ts new file mode 100644 index 000000000..5a73e9cfe --- /dev/null +++ b/test/unit/ldp/http/BasicTargetExtractor.test.ts @@ -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 => { + await expect(extractor.canHandle({ url: 'url', headers: { host: 'test.com' }} as any)).resolves.toBeUndefined(); + }); + + it('rejects input without URL.', async(): Promise => { + await expect(extractor.canHandle({ headers: { host: 'test.com' }} as any)).rejects.toThrow('Missing URL.'); + }); + + it('rejects input without host.', async(): Promise => { + await expect(extractor.canHandle({ url: 'url', headers: {}} as any)).rejects.toThrow('Missing host.'); + }); + + it('returns the input URL.', async(): Promise => { + 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 => { + await expect(extractor.handle( + { url: 'url', headers: { host: 'test.com' }, connection: { encrypted: true } as any } as any, + )).resolves.toEqual({ path: 'https://test.com/url' }); + }); +}); diff --git a/test/unit/ldp/http/SimpleBodyParser.test.ts b/test/unit/ldp/http/RawBodyParser.test.ts similarity index 94% rename from test/unit/ldp/http/SimpleBodyParser.test.ts rename to test/unit/ldp/http/RawBodyParser.test.ts index e70ee6b23..0dbaf96de 100644 --- a/test/unit/ldp/http/SimpleBodyParser.test.ts +++ b/test/unit/ldp/http/RawBodyParser.test.ts @@ -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 => { await expect(bodyParser.canHandle()).resolves.toBeUndefined(); diff --git a/test/unit/ldp/http/SimpleTargetExtractor.test.ts b/test/unit/ldp/http/SimpleTargetExtractor.test.ts deleted file mode 100644 index c74d7ff6b..000000000 --- a/test/unit/ldp/http/SimpleTargetExtractor.test.ts +++ /dev/null @@ -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 => { - await expect(extractor.canHandle({ url: 'url' } as any)).resolves.toBeUndefined(); - }); - - it('rejects input without URL.', async(): Promise => { - await expect(extractor.canHandle({ } as any)).rejects.toThrow('Missing URL.'); - }); - - it('returns the input URL.', async(): Promise => { - 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 => { - await expect(extractor.handle( - { url: 'url', headers: { host: 'test.com' }, connection: { encrypted: true } as any } as any, - )).resolves.toEqual({ path: 'https://test.com/url' }); - }); -}); diff --git a/test/unit/ldp/http/SimpleSparqlUpdateBodyParser.test.ts b/test/unit/ldp/http/SparqlUpdateBodyParser.test.ts similarity index 91% rename from test/unit/ldp/http/SimpleSparqlUpdateBodyParser.test.ts rename to test/unit/ldp/http/SparqlUpdateBodyParser.test.ts index 732d084cb..b4aac5534 100644 --- a/test/unit/ldp/http/SimpleSparqlUpdateBodyParser.test.ts +++ b/test/unit/ldp/http/SparqlUpdateBodyParser.test.ts @@ -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 => { await expect(bodyParser.canHandle({ headers: {}} as HttpRequest)).rejects.toThrow(UnsupportedMediaTypeHttpError); diff --git a/test/unit/ldp/operations/SimpleDeleteOperationHandler.test.ts b/test/unit/ldp/operations/DeleteOperationHandler.test.ts similarity index 83% rename from test/unit/ldp/operations/SimpleDeleteOperationHandler.test.ts rename to test/unit/ldp/operations/DeleteOperationHandler.test.ts index 44af63f2f..3dc3a7359 100644 --- a/test/unit/ldp/operations/SimpleDeleteOperationHandler.test.ts +++ b/test/unit/ldp/operations/DeleteOperationHandler.test.ts @@ -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 => { // eslint-disable-next-line @typescript-eslint/no-empty-function store.deleteResource = jest.fn(async(): Promise => {}); diff --git a/test/unit/ldp/operations/SimpleGetOperationHandler.test.ts b/test/unit/ldp/operations/GetOperationHandler.test.ts similarity index 83% rename from test/unit/ldp/operations/SimpleGetOperationHandler.test.ts rename to test/unit/ldp/operations/GetOperationHandler.test.ts index 4c2b46ead..3262b8fef 100644 --- a/test/unit/ldp/operations/SimpleGetOperationHandler.test.ts +++ b/test/unit/ldp/operations/GetOperationHandler.test.ts @@ -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 => ({ 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 => { await expect(handler.canHandle({ method: 'GET' } as Operation)).resolves.toBeUndefined(); diff --git a/test/unit/ldp/operations/SimplePatchOperationHandler.test.ts b/test/unit/ldp/operations/PatchOperationHandler.test.ts similarity index 78% rename from test/unit/ldp/operations/SimplePatchOperationHandler.test.ts rename to test/unit/ldp/operations/PatchOperationHandler.test.ts index 06e8d914c..abc75d19d 100644 --- a/test/unit/ldp/operations/SimplePatchOperationHandler.test.ts +++ b/test/unit/ldp/operations/PatchOperationHandler.test.ts @@ -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 => { store.modifyResource = jest.fn(async(): Promise => undefined); }); - it('only supports GET operations.', async(): Promise => { + it('only supports PATCH operations.', async(): Promise => { await expect(handler.canHandle({ method: 'PATCH' } as Operation)).resolves.toBeUndefined(); await expect(handler.canHandle({ method: 'GET' } as Operation)).rejects.toThrow(UnsupportedHttpError); }); diff --git a/test/unit/ldp/operations/SimplePostOperationHandler.test.ts b/test/unit/ldp/operations/PostOperationHandler.test.ts similarity index 84% rename from test/unit/ldp/operations/SimplePostOperationHandler.test.ts rename to test/unit/ldp/operations/PostOperationHandler.test.ts index 40492ee87..07b03dfc3 100644 --- a/test/unit/ldp/operations/SimplePostOperationHandler.test.ts +++ b/test/unit/ldp/operations/PostOperationHandler.test.ts @@ -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 => ({ 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 => { await expect(handler.canHandle({ method: 'POST', body: { dataType: 'test' }} as Operation)) diff --git a/test/unit/ldp/operations/SimplePutOperationHandler.test.ts b/test/unit/ldp/operations/PutOperationHandler.test.ts similarity index 86% rename from test/unit/ldp/operations/SimplePutOperationHandler.test.ts rename to test/unit/ldp/operations/PutOperationHandler.test.ts index 616454444..68ff8ef66 100644 --- a/test/unit/ldp/operations/SimplePutOperationHandler.test.ts +++ b/test/unit/ldp/operations/PutOperationHandler.test.ts @@ -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 => { // eslint-disable-next-line @typescript-eslint/no-empty-function store.setRepresentation = jest.fn(async(): Promise => {}); diff --git a/test/unit/storage/SimpleResourceStore.test.ts b/test/unit/storage/InMemoryResourceStore.test.ts similarity index 92% rename from test/unit/storage/SimpleResourceStore.test.ts rename to test/unit/storage/InMemoryResourceStore.test.ts index dd352a83f..f76b29d15 100644 --- a/test/unit/storage/SimpleResourceStore.test.ts +++ b/test/unit/storage/InMemoryResourceStore.test.ts @@ -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 = ' .'; beforeEach(async(): Promise => { - store = new SimpleResourceStore(new RuntimeConfig({ base })); + store = new InMemoryResourceStore(new RuntimeConfig({ base })); representation = { data: streamifyArray([ dataString ]), diff --git a/test/unit/storage/patch/SimpleSparqlUpdatePatchHandler.test.ts b/test/unit/storage/patch/SparqlUpdatePatchHandler.test.ts similarity index 96% rename from test/unit/storage/patch/SimpleSparqlUpdatePatchHandler.test.ts rename to test/unit/storage/patch/SparqlUpdatePatchHandler.test.ts index 9f8f84557..6a069c3f2 100644 --- a/test/unit/storage/patch/SimpleSparqlUpdatePatchHandler.test.ts +++ b/test/unit/storage/patch/SparqlUpdatePatchHandler.test.ts @@ -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; @@ -59,7 +59,7 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => { }), }; - handler = new SimpleSparqlUpdatePatchHandler(source, locker); + handler = new SparqlUpdatePatchHandler(source, locker); }); const basicChecks = async(quads: Quad[]): Promise => {