mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Create DenyAllAuthorizer
This commit is contained in:
parent
dee382849d
commit
d95db60fe1
11
src/authorization/DenyAllAuthorizer.ts
Normal file
11
src/authorization/DenyAllAuthorizer.ts
Normal 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();
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ export * from './authorization/AllowAllAuthorizer';
|
||||
export * from './authorization/Authorization';
|
||||
export * from './authorization/Authorizer';
|
||||
export * from './authorization/AuxiliaryAuthorizer';
|
||||
export * from './authorization/DenyAllAuthorizer';
|
||||
export * from './authorization/WebAclAuthorization';
|
||||
export * from './authorization/WebAclAuthorizer';
|
||||
|
||||
|
14
test/unit/authorization/DenyAllAuthorizer.test.ts
Normal file
14
test/unit/authorization/DenyAllAuthorizer.test.ts
Normal 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);
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user