From ba8b3575b0ac70e58768a17ac77a5e74193b5924 Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Fri, 4 Sep 2020 22:48:43 +0200 Subject: [PATCH] refactor: Rename BasePermissionsExtractor to MethodPermissionsExtractor --- config/presets/ldp/permissions-extractor.json | 2 +- index.ts | 2 +- ...ermissionsExtractor.ts => MethodPermissionsExtractor.ts} | 2 +- test/integration/AuthenticatedLdpHandler.test.ts | 6 +++--- test/integration/Authorization.test.ts | 4 ++-- test/unit/ldp/permissions/BasePermissionsExtractor.test.ts | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) rename src/ldp/permissions/{BasePermissionsExtractor.ts => MethodPermissionsExtractor.ts} (94%) diff --git a/config/presets/ldp/permissions-extractor.json b/config/presets/ldp/permissions-extractor.json index 3356f0cf96..910bf7766d 100644 --- a/config/presets/ldp/permissions-extractor.json +++ b/config/presets/ldp/permissions-extractor.json @@ -6,7 +6,7 @@ "@type": "CompositeAsyncHandler", "CompositeAsyncHandler:_handlers": [ { - "@type": "BasePermissionsExtractor" + "@type": "MethodPermissionsExtractor" }, { "@type": "SparqlPatchPermissionsExtractor" diff --git a/index.ts b/index.ts index 4e74f2cd54..83bedcfbc1 100644 --- a/index.ts +++ b/index.ts @@ -43,7 +43,7 @@ export * from './src/ldp/operations/ResponseDescription'; // LDP/Permissions export * from './src/ldp/permissions/PermissionSet'; export * from './src/ldp/permissions/PermissionsExtractor'; -export * from './src/ldp/permissions/BasePermissionsExtractor'; +export * from './src/ldp/permissions/MethodPermissionsExtractor'; export * from './src/ldp/permissions/SparqlPatchPermissionsExtractor'; // LDP/Representation diff --git a/src/ldp/permissions/BasePermissionsExtractor.ts b/src/ldp/permissions/MethodPermissionsExtractor.ts similarity index 94% rename from src/ldp/permissions/BasePermissionsExtractor.ts rename to src/ldp/permissions/MethodPermissionsExtractor.ts index 944f254e3d..eed8925316 100644 --- a/src/ldp/permissions/BasePermissionsExtractor.ts +++ b/src/ldp/permissions/MethodPermissionsExtractor.ts @@ -7,7 +7,7 @@ import { PermissionsExtractor } from './PermissionsExtractor'; * Generates permissions for the base set of methods that always require the same permissions. * Specifically: GET, HEAD, POST, PUT and DELETE. */ -export class BasePermissionsExtractor extends PermissionsExtractor { +export class MethodPermissionsExtractor extends PermissionsExtractor { public async canHandle(input: Operation): Promise { if (!/^(?:HEAD|GET|POST|PUT|DELETE)$/u.test(input.method)) { throw new UnsupportedHttpError(`Unsupported method: ${input.method}`); diff --git a/test/integration/AuthenticatedLdpHandler.test.ts b/test/integration/AuthenticatedLdpHandler.test.ts index a07daf0a3f..993779c89f 100644 --- a/test/integration/AuthenticatedLdpHandler.test.ts +++ b/test/integration/AuthenticatedLdpHandler.test.ts @@ -19,7 +19,7 @@ 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 { BasePermissionsExtractor } from '../../src/ldp/permissions/BasePermissionsExtractor'; +import { MethodPermissionsExtractor } from '../../src/ldp/permissions/MethodPermissionsExtractor'; import { SparqlPatchPermissionsExtractor } from '../../src/ldp/permissions/SparqlPatchPermissionsExtractor'; import { Representation } from '../../src/ldp/representation/Representation'; import { HttpRequest } from '../../src/server/HttpRequest'; @@ -42,7 +42,7 @@ describe('An integrated AuthenticatedLdpHandler', (): void => { }); const credentialsExtractor = new UnsecureWebIdExtractor(); - const permissionsExtractor = new BasePermissionsExtractor(); + const permissionsExtractor = new MethodPermissionsExtractor(); const authorizer = new AllowEverythingAuthorizer(); const store = new InMemoryResourceStore(new RuntimeConfig({ base: 'http://test.com/' })); @@ -111,7 +111,7 @@ describe('An integrated AuthenticatedLdpHandler', (): void => { const credentialsExtractor = new UnsecureWebIdExtractor(); const permissionsExtractor = new CompositeAsyncHandler([ - new BasePermissionsExtractor(), + new MethodPermissionsExtractor(), new SparqlPatchPermissionsExtractor(), ]); const authorizer = new AllowEverythingAuthorizer(); diff --git a/test/integration/Authorization.test.ts b/test/integration/Authorization.test.ts index 6e764ecd84..02cdcfc30d 100644 --- a/test/integration/Authorization.test.ts +++ b/test/integration/Authorization.test.ts @@ -17,7 +17,7 @@ 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 { BasePermissionsExtractor } from '../../src/ldp/permissions/BasePermissionsExtractor'; +import { MethodPermissionsExtractor } from '../../src/ldp/permissions/MethodPermissionsExtractor'; import { PermissionSet } from '../../src/ldp/permissions/PermissionSet'; import { QuadToTurtleConverter } from '../../src/storage/conversion/QuadToTurtleConverter'; import { TurtleToQuadConverter } from '../../src/storage/conversion/TurtleToQuadConverter'; @@ -88,7 +88,7 @@ describe('A server with authorization', (): void => { const convertingStore = new RepresentationConvertingStore(store, converter); const credentialsExtractor = new UnsecureWebIdExtractor(); - const permissionsExtractor = new BasePermissionsExtractor(); + const permissionsExtractor = new MethodPermissionsExtractor(); const authorizer = new WebAclAuthorizer( new UrlBasedAclManager(), new UrlContainerManager(new RuntimeConfig({ base: 'http://test.com/' })), diff --git a/test/unit/ldp/permissions/BasePermissionsExtractor.test.ts b/test/unit/ldp/permissions/BasePermissionsExtractor.test.ts index 0380a959fa..3c49d8e7e6 100644 --- a/test/unit/ldp/permissions/BasePermissionsExtractor.test.ts +++ b/test/unit/ldp/permissions/BasePermissionsExtractor.test.ts @@ -1,9 +1,9 @@ import { Operation } from '../../../../src/ldp/operations/Operation'; -import { BasePermissionsExtractor } from '../../../../src/ldp/permissions/BasePermissionsExtractor'; +import { MethodPermissionsExtractor } from '../../../../src/ldp/permissions/MethodPermissionsExtractor'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; -describe('A BasePermissionsExtractor', (): void => { - const extractor = new BasePermissionsExtractor(); +describe('A MethodPermissionsExtractor', (): void => { + const extractor = new MethodPermissionsExtractor(); it('can handle HEAD/GET/POST/PUT/DELETE.', async(): Promise => { await expect(extractor.canHandle({ method: 'HEAD' } as Operation)).resolves.toBeUndefined();