feat: Create DenyAllAuthorizer

This commit is contained in:
Joachim Van Herwegen 2021-07-27 10:20:32 +02:00
parent dee382849d
commit d95db60fe1
3 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,11 @@
import { ForbiddenHttpError } from '../util/errors/ForbiddenHttpError';
import { Authorizer } from './Authorizer';
/**
* An authorizer that rejects all requests.
*/
export class DenyAllAuthorizer extends Authorizer {
public async handle(): Promise<never> {
throw new ForbiddenHttpError();
}
}

View File

@ -12,6 +12,7 @@ export * from './authorization/AllowAllAuthorizer';
export * from './authorization/Authorization'; export * from './authorization/Authorization';
export * from './authorization/Authorizer'; export * from './authorization/Authorizer';
export * from './authorization/AuxiliaryAuthorizer'; export * from './authorization/AuxiliaryAuthorizer';
export * from './authorization/DenyAllAuthorizer';
export * from './authorization/WebAclAuthorization'; export * from './authorization/WebAclAuthorization';
export * from './authorization/WebAclAuthorizer'; export * from './authorization/WebAclAuthorizer';

View File

@ -0,0 +1,14 @@
import { DenyAllAuthorizer } from '../../../src/authorization/DenyAllAuthorizer';
import { ForbiddenHttpError } from '../../../src/util/errors/ForbiddenHttpError';
describe('A DenyAllAuthorizer', (): void => {
const authorizer = new DenyAllAuthorizer();
it('can handle all requests.', async(): Promise<void> => {
await expect(authorizer.canHandle({} as any)).resolves.toBeUndefined();
});
it('rejects all requests.', async(): Promise<void> => {
await expect(authorizer.handle()).rejects.toThrow(ForbiddenHttpError);
});
});