From 74415cf49bc4e61ff52164ee958058b931734578 Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Tue, 1 Dec 2020 23:35:11 +0100 Subject: [PATCH] fix: Align webId capitalization. --- src/authentication/Credentials.ts | 2 +- src/authentication/DPoPWebIdExtractor.ts | 6 +++--- src/authentication/UnsecureWebIdExtractor.ts | 8 ++++---- src/authorization/WebAclAuthorizer.ts | 8 ++++---- src/ldp/AuthenticatedLdpHandler.ts | 2 +- .../authentication/DPoPWebIdExtractor.test.ts | 2 +- .../UnsecureWebIdExtractor.test.ts | 2 +- test/unit/authorization/WebAclAuthorizer.test.ts | 16 ++++++++-------- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/authentication/Credentials.ts b/src/authentication/Credentials.ts index bae6d0ba9..af40670a7 100644 --- a/src/authentication/Credentials.ts +++ b/src/authentication/Credentials.ts @@ -2,5 +2,5 @@ * Credentials identifying an entity accessing or owning data. */ export interface Credentials { - webID?: string; + webId?: string; } diff --git a/src/authentication/DPoPWebIdExtractor.ts b/src/authentication/DPoPWebIdExtractor.ts index 8b412e8a4..e495ee842 100644 --- a/src/authentication/DPoPWebIdExtractor.ts +++ b/src/authentication/DPoPWebIdExtractor.ts @@ -33,9 +33,9 @@ export class DPoPWebIdExtractor extends CredentialsExtractor { } const resource = await this.targetExtractor.handleSafe(request); try { - const webID = await verify(authorization as string, dpop as string, method as any, resource.path); - this.logger.info(`Verified WebID via DPoP token: ${webID}`); - return { webID }; + const webId = await verify(authorization as string, dpop as string, method as any, resource.path); + this.logger.info(`Verified WebID via DPoP token: ${webId}`); + return { webId }; } catch (error: unknown) { const message = `Error verifying WebID via DPoP token: ${(error as Error).message}`; this.logger.warn(message); diff --git a/src/authentication/UnsecureWebIdExtractor.ts b/src/authentication/UnsecureWebIdExtractor.ts index 6905128ec..a7e935d4e 100644 --- a/src/authentication/UnsecureWebIdExtractor.ts +++ b/src/authentication/UnsecureWebIdExtractor.ts @@ -5,7 +5,7 @@ import type { Credentials } from './Credentials'; import { CredentialsExtractor } from './CredentialsExtractor'; /** - * Credentials extractor which simply interprets the contents of the Authorization header as a webID. + * Credentials extractor which simply interprets the contents of the Authorization header as a WebID. */ export class UnsecureWebIdExtractor extends CredentialsExtractor { protected readonly logger = getLoggerFor(this); @@ -18,8 +18,8 @@ export class UnsecureWebIdExtractor extends CredentialsExtractor { } public async handle({ headers }: HttpRequest): Promise { - const webID = /^WebID\s+(.*)/u.exec(headers.authorization as string)![1]; - this.logger.info(`Agent unsecurely claims to be ${webID}`); - return { webID }; + const webId = /^WebID\s+(.*)/u.exec(headers.authorization as string)![1]; + this.logger.info(`Agent unsecurely claims to be ${webId}`); + return { webId }; } } diff --git a/src/authorization/WebAclAuthorizer.ts b/src/authorization/WebAclAuthorizer.ts index c6efdddaa..62da50f13 100644 --- a/src/authorization/WebAclAuthorizer.ts +++ b/src/authorization/WebAclAuthorizer.ts @@ -63,9 +63,9 @@ export class WebAclAuthorizer extends Authorizer { const modeString = ACL[this.capitalize(mode) as 'Write' | 'Read' | 'Append' | 'Control']; const auths = store.getQuads(null, ACL.mode, modeString, null).map((quad: Quad): Term => quad.subject); if (!auths.some((term): boolean => this.hasAccess(agent, term, store))) { - const isLoggedIn = typeof agent.webID === 'string'; + const isLoggedIn = typeof agent.webId === 'string'; if (isLoggedIn) { - this.logger.warn(`Agent ${agent.webID} has no ${mode} permissions`); + this.logger.warn(`Agent ${agent.webId} has no ${mode} permissions`); throw new ForbiddenHttpError(); } else { this.logger.warn(`Unauthenticated agent has no ${mode} permissions`); @@ -96,13 +96,13 @@ export class WebAclAuthorizer extends Authorizer { if (store.countQuads(auth, ACL.agentClass, FOAF.Agent, null) > 0) { return true; } - if (typeof agent.webID !== 'string') { + if (typeof agent.webId !== 'string') { return false; } if (store.countQuads(auth, ACL.agentClass, FOAF.AuthenticatedAgent, null) > 0) { return true; } - return store.countQuads(auth, ACL.agent, agent.webID, null) > 0; + return store.countQuads(auth, ACL.agent, agent.webId, null) > 0; } /** diff --git a/src/ldp/AuthenticatedLdpHandler.ts b/src/ldp/AuthenticatedLdpHandler.ts index c13694975..a304fc1c9 100644 --- a/src/ldp/AuthenticatedLdpHandler.ts +++ b/src/ldp/AuthenticatedLdpHandler.ts @@ -118,7 +118,7 @@ export class AuthenticatedLdpHandler extends HttpHandler { this.logger.verbose(`Parsed ${operation.method} operation on ${operation.target.path}`); const credentials: Credentials = await this.credentialsExtractor.handleSafe(request); - this.logger.verbose(`Extracted credentials: ${credentials.webID}`); + this.logger.verbose(`Extracted credentials: ${credentials.webId}`); const permissions: PermissionSet = await this.permissionsExtractor.handleSafe(operation); const { read, write, append } = permissions; diff --git a/test/unit/authentication/DPoPWebIdExtractor.test.ts b/test/unit/authentication/DPoPWebIdExtractor.test.ts index b50f53c62..5dc21bb5a 100644 --- a/test/unit/authentication/DPoPWebIdExtractor.test.ts +++ b/test/unit/authentication/DPoPWebIdExtractor.test.ts @@ -83,7 +83,7 @@ describe('A DPoPWebIdExtractor', (): void => { it('returns the extracted WebID.', async(): Promise => { const result = webIdExtractor.handleSafe(request); - await expect(result).resolves.toEqual({ webID: 'http://alice.example/card#me' }); + await expect(result).resolves.toEqual({ webId: 'http://alice.example/card#me' }); }); }); diff --git a/test/unit/authentication/UnsecureWebIdExtractor.test.ts b/test/unit/authentication/UnsecureWebIdExtractor.test.ts index 15505fc2d..8fd249b54 100644 --- a/test/unit/authentication/UnsecureWebIdExtractor.test.ts +++ b/test/unit/authentication/UnsecureWebIdExtractor.test.ts @@ -22,6 +22,6 @@ describe('An UnsecureWebIdExtractor', (): void => { it('returns the authorization header as WebID if there is one.', async(): Promise => { const headers = { authorization: 'WebID http://alice.example/card#me' }; const result = extractor.handleSafe({ headers } as HttpRequest); - await expect(result).resolves.toEqual({ webID: 'http://alice.example/card#me' }); + await expect(result).resolves.toEqual({ webId: 'http://alice.example/card#me' }); }); }); diff --git a/test/unit/authorization/WebAclAuthorizer.test.ts b/test/unit/authorization/WebAclAuthorizer.test.ts index fb9354cff..56b2ecd32 100644 --- a/test/unit/authorization/WebAclAuthorizer.test.ts +++ b/test/unit/authorization/WebAclAuthorizer.test.ts @@ -84,7 +84,7 @@ describe('A WebAclAuthorizer', (): void => { ]) } as Representation), } as unknown as ResourceStore; authorizer = new WebAclAuthorizer(aclManager, store); - credentials.webID = 'http://test.com/user'; + credentials.webId = 'http://test.com/user'; await expect(authorizer.handle({ identifier, permissions, credentials })).resolves.toBeUndefined(); }); @@ -101,10 +101,10 @@ describe('A WebAclAuthorizer', (): void => { }); it('allows access to specific agents if the acl files identifies them.', async(): Promise => { - credentials.webID = 'http://test.com/user'; + credentials.webId = 'http://test.com/user'; const store = { getRepresentation: async(): Promise => ({ data: streamifyArray([ - quad(nn('auth'), nn(`${acl}agent`), nn(credentials.webID!)), + quad(nn('auth'), nn(`${acl}agent`), nn(credentials.webId!)), quad(nn('auth'), nn(`${acl}accessTo`), nn(identifier.path)), quad(nn('auth'), nn(`${acl}mode`), nn(`${acl}Read`)), ]) } as Representation), @@ -114,7 +114,7 @@ describe('A WebAclAuthorizer', (): void => { }); it('errors if a specific agents wants to access files not assigned to them.', async(): Promise => { - credentials.webID = 'http://test.com/user'; + credentials.webId = 'http://test.com/user'; const store = { getRepresentation: async(): Promise => ({ data: streamifyArray([ quad(nn('auth'), nn(`${acl}agent`), nn('http://test.com/differentUser')), @@ -127,11 +127,11 @@ describe('A WebAclAuthorizer', (): void => { }); it('allows access to the acl file if control is allowed.', async(): Promise => { - credentials.webID = 'http://test.com/user'; + credentials.webId = 'http://test.com/user'; identifier.path = 'http://test.com/foo'; const store = { getRepresentation: async(): Promise => ({ data: streamifyArray([ - quad(nn('auth'), nn(`${acl}agent`), nn(credentials.webID!)), + quad(nn('auth'), nn(`${acl}agent`), nn(credentials.webId!)), quad(nn('auth'), nn(`${acl}accessTo`), nn(identifier.path)), quad(nn('auth'), nn(`${acl}mode`), nn(`${acl}Control`)), ]) } as Representation), @@ -142,11 +142,11 @@ describe('A WebAclAuthorizer', (): void => { }); it('errors if an agent tries to edit the acl file without control permissions.', async(): Promise => { - credentials.webID = 'http://test.com/user'; + credentials.webId = 'http://test.com/user'; identifier.path = 'http://test.com/foo'; const store = { getRepresentation: async(): Promise => ({ data: streamifyArray([ - quad(nn('auth'), nn(`${acl}agent`), nn(credentials.webID!)), + quad(nn('auth'), nn(`${acl}agent`), nn(credentials.webId!)), quad(nn('auth'), nn(`${acl}accessTo`), nn(identifier.path)), quad(nn('auth'), nn(`${acl}mode`), nn(`${acl}Read`)), ]) } as Representation),