fix: Align webId capitalization.

This commit is contained in:
Ruben Verborgh
2020-12-01 23:35:11 +01:00
parent 357546e90f
commit 74415cf49b
8 changed files with 23 additions and 23 deletions

View File

@@ -2,5 +2,5 @@
* Credentials identifying an entity accessing or owning data.
*/
export interface Credentials {
webID?: string;
webId?: string;
}

View File

@@ -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);

View File

@@ -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<Credentials> {
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 };
}
}

View File

@@ -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;
}
/**

View File

@@ -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;

View File

@@ -83,7 +83,7 @@ describe('A DPoPWebIdExtractor', (): void => {
it('returns the extracted WebID.', async(): Promise<void> => {
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' });
});
});

View File

@@ -22,6 +22,6 @@ describe('An UnsecureWebIdExtractor', (): void => {
it('returns the authorization header as WebID if there is one.', async(): Promise<void> => {
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' });
});
});

View File

@@ -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<void> => {
credentials.webID = 'http://test.com/user';
credentials.webId = 'http://test.com/user';
const store = {
getRepresentation: async(): Promise<Representation> => ({ 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<void> => {
credentials.webID = 'http://test.com/user';
credentials.webId = 'http://test.com/user';
const store = {
getRepresentation: async(): Promise<Representation> => ({ 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<void> => {
credentials.webID = 'http://test.com/user';
credentials.webId = 'http://test.com/user';
identifier.path = 'http://test.com/foo';
const store = {
getRepresentation: async(): Promise<Representation> => ({ 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<void> => {
credentials.webID = 'http://test.com/user';
credentials.webId = 'http://test.com/user';
identifier.path = 'http://test.com/foo';
const store = {
getRepresentation: async(): Promise<Representation> => ({ 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),