Skip to content

Commit

Permalink
Merge 6a13986 into ac8423d
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenVerborgh committed Oct 30, 2020
2 parents ac8423d + 6a13986 commit 96bb210
Show file tree
Hide file tree
Showing 19 changed files with 23 additions and 46 deletions.
4 changes: 0 additions & 4 deletions src/authentication/UnsecureWebIdExtractor.ts
Expand Up @@ -6,10 +6,6 @@ import { CredentialsExtractor } from './CredentialsExtractor';
* Credentials extractor which simply interprets the contents of the Authorization header as a webID.
*/
export class UnsecureWebIdExtractor extends CredentialsExtractor {
public async canHandle(): Promise<void> {
// Supports all requests
}

public async handle(input: HttpRequest): Promise<Credentials> {
return { webID: input.headers.authorization };
}
Expand Down
4 changes: 0 additions & 4 deletions src/authorization/AllowEverythingAuthorizer.ts
Expand Up @@ -4,10 +4,6 @@ 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
}
Expand Down
4 changes: 0 additions & 4 deletions src/authorization/WebAclAuthorizer.ts
Expand Up @@ -35,10 +35,6 @@ export class WebAclAuthorizer extends Authorizer {
this.resourceStore = resourceStore;
}

public async canHandle(): Promise<void> {
// Can handle everything
}

/**
* Checks if an agent is allowed to execute the requested actions.
* Will throw an error if this is not the case.
Expand Down
4 changes: 0 additions & 4 deletions src/ldp/http/AcceptPreferenceParser.ts
Expand Up @@ -19,10 +19,6 @@ export class AcceptPreferenceParser extends PreferenceParser {
super();
}

public async canHandle(): Promise<void> {
// Supports all HttpRequests
}

public async handle(input: HttpRequest): Promise<RepresentationPreferences> {
const result: RepresentationPreferences = {};
const headers:
Expand Down
4 changes: 0 additions & 4 deletions src/ldp/http/BasicRequestParser.ts
Expand Up @@ -31,10 +31,6 @@ export class BasicRequestParser extends RequestParser {
Object.assign(this, args);
}

public async canHandle(): Promise<void> {
// Can handle all requests
}

public async handle(request: HttpRequest): Promise<Operation> {
const { method } = request;
if (!method) {
Expand Down
4 changes: 0 additions & 4 deletions src/ldp/http/BasicTargetExtractor.ts
Expand Up @@ -13,10 +13,6 @@ import { TargetExtractor } from './TargetExtractor';
export class BasicTargetExtractor extends TargetExtractor {
protected readonly logger = getLoggerFor(this);

public async canHandle(): Promise<void> {
// Can handle all URLs
}

public async handle(request: HttpRequest): Promise<ResourceIdentifier> {
if (!request.url) {
this.logger.error('The request has no URL');
Expand Down
4 changes: 0 additions & 4 deletions src/ldp/http/RawBodyParser.ts
Expand Up @@ -10,10 +10,6 @@ import { BodyParser } from './BodyParser';
export class RawBodyParser extends BodyParser {
protected readonly logger = getLoggerFor(this);

public async canHandle(): Promise<void> {
// All content-types are supported
}

// Note that the only reason this is a union is in case the body is empty.
// If this check gets moved away from the BodyParsers this union could be removed
public async handle({ request, metadata }: BodyParserArgs): Promise<Representation | undefined> {
Expand Down
4 changes: 0 additions & 4 deletions src/ldp/http/metadata/BasicMetadataExtractor.ts
Expand Up @@ -14,10 +14,6 @@ export class BasicMetadataExtractor extends MetadataExtractor {
this.parsers = parsers;
}

public async canHandle(): Promise<void> {
// Can handle all requests
}

public async handle(request: HttpRequest):
Promise<RepresentationMetadata> {
const metadata = new RepresentationMetadata();
Expand Down
5 changes: 4 additions & 1 deletion src/util/AsyncHandler.ts
Expand Up @@ -9,7 +9,10 @@ export abstract class AsyncHandler<TInput, TOutput = void> {
*
* @returns A promise resolving if this input can be handled, rejecting with an Error if not.
*/
public abstract canHandle(input: TInput): Promise<void>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public async canHandle(input: TInput): Promise<void> {
// Support any input by default
}

/**
* Handles the given input. This should only be done if the {@link canHandle} function returned `true`.
Expand Down
2 changes: 1 addition & 1 deletion test/unit/authentication/UnsecureWebIdExtractor.ts
Expand Up @@ -5,7 +5,7 @@ describe('An UnsecureWebIdExtractor', (): void => {
const extractor = new UnsecureWebIdExtractor();

it('can handle all input.', async(): Promise<void> => {
await expect(extractor.canHandle()).resolves.toBeUndefined();
await expect(extractor.canHandle({} as HttpRequest)).resolves.toBeUndefined();
});

it('returns undefined if there is no input.', async(): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/authorization/AllowEverythingAuthorizer.test.ts
Expand Up @@ -4,7 +4,7 @@ describe('An AllowEverythingAuthorizer', (): void => {
const authorizer = new AllowEverythingAuthorizer();

it('can handle everything.', async(): Promise<void> => {
await expect(authorizer.canHandle()).resolves.toBeUndefined();
await expect(authorizer.canHandle({} as any)).resolves.toBeUndefined();
});

it('always returns undefined.', async(): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/authorization/WebAclAuthorizer.test.ts
Expand Up @@ -43,7 +43,7 @@ describe('A WebAclAuthorizer', (): void => {

it('handles all inputs.', async(): Promise<void> => {
authorizer = new WebAclAuthorizer(aclManager, containerManager, null as any);
await expect(authorizer.canHandle()).resolves.toBeUndefined();
await expect(authorizer.canHandle({} as any)).resolves.toBeUndefined();
});

it('allows access if the acl file allows all agents.', async(): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ldp/http/AcceptPreferenceParser.test.ts
Expand Up @@ -5,7 +5,7 @@ describe('An AcceptPreferenceParser', (): void => {
const preferenceParser = new AcceptPreferenceParser();

it('can handle all input.', async(): Promise<void> => {
await expect(preferenceParser.canHandle()).resolves.toBeUndefined();
await expect(preferenceParser.canHandle({} as HttpRequest)).resolves.toBeUndefined();
});

it('returns an empty result if there is no relevant input.', async(): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ldp/http/BasicRequestParser.test.ts
Expand Up @@ -21,7 +21,7 @@ describe('A BasicRequestParser', (): void => {
});

it('can handle any input.', async(): Promise<void> => {
await expect(requestParser.canHandle()).resolves.toBeUndefined();
await expect(requestParser.canHandle({} as any)).resolves.toBeUndefined();
});

it('errors if there is no input.', async(): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ldp/http/BasicTargetExtractor.test.ts
Expand Up @@ -4,7 +4,7 @@ describe('A BasicTargetExtractor', (): void => {
const extractor = new BasicTargetExtractor();

it('can handle any input.', async(): Promise<void> => {
await expect(extractor.canHandle()).resolves.toBeUndefined();
await expect(extractor.canHandle({} as any)).resolves.toBeUndefined();
});

it('errors if there is no URL.', async(): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ldp/http/RawBodyParser.test.ts
Expand Up @@ -15,7 +15,7 @@ describe('A RawBodyparser', (): void => {
});

it('accepts all input.', async(): Promise<void> => {
await expect(bodyParser.canHandle()).resolves.toBeUndefined();
await expect(bodyParser.canHandle({} as any)).resolves.toBeUndefined();
});

it('returns empty output if there was no content length or transfer encoding.', async(): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ldp/http/metadata/BasicMetadataExtractor.test.ts
Expand Up @@ -28,7 +28,7 @@ describe(' A BasicMetadataExtractor', (): void => {
]);

it('can handle all requests.', async(): Promise<void> => {
await expect(handler.canHandle()).resolves.toBeUndefined();
await expect(handler.canHandle({} as any)).resolves.toBeUndefined();
});

it('will add metadata from the parsers.', async(): Promise<void> => {
Expand Down
4 changes: 0 additions & 4 deletions test/unit/server/ExpressHttpServer.test.ts
Expand Up @@ -12,10 +12,6 @@ const handle = async(input: { request: HttpRequest; response: HttpResponse }): P
};

class SimpleHttpHandler extends HttpHandler {
public async canHandle(): Promise<void> {
// Supports all HttpRequests
}

public async handle(input: { request: HttpRequest; response: HttpResponse }): Promise<void> {
return handle(input);
}
Expand Down
12 changes: 11 additions & 1 deletion test/unit/util/AsyncHandler.test.ts
@@ -1,7 +1,17 @@
import type { AsyncHandler } from '../../../src/util/AsyncHandler';
import { AsyncHandler } from '../../../src/util/AsyncHandler';
import { StaticAsyncHandler } from '../../util/StaticAsyncHandler';

describe('An AsyncHandler', (): void => {
it('supports any input by default.', async(): Promise<void> => {
class EmptyHandler<T> extends AsyncHandler<T, null> {
public async handle(): Promise<null> {
return null;
}
}
const handler = new EmptyHandler<string>();
await expect(handler.canHandle('test')).resolves.toBeUndefined();
});

it('calls canHandle and handle when handleSafe is called.', async(): Promise<void> => {
const handlerTrue: AsyncHandler<any, any> = new StaticAsyncHandler(true, null);
const canHandleFn = jest.fn(async(input: any): Promise<void> => input);
Expand Down

0 comments on commit 96bb210

Please sign in to comment.