test(security): add and refactor api security/idor coverage
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { ExecutionContext } from '@nestjs/common';
|
||||
import { ROLES_KEY } from '../auth/decorators/roles.decorator';
|
||||
|
||||
export type MockHttpContextOptions = {
|
||||
handler: Function;
|
||||
clazz: Function;
|
||||
user?: unknown;
|
||||
};
|
||||
|
||||
export type AdminHandler = [string, Function];
|
||||
|
||||
export function mockHttpContext(options: MockHttpContextOptions): ExecutionContext {
|
||||
return {
|
||||
getClass: () => options.clazz,
|
||||
getHandler: () => options.handler,
|
||||
switchToHttp: () => ({
|
||||
getRequest: () => ({ user: options.user }),
|
||||
getResponse: () => ({}),
|
||||
getNext: () => undefined,
|
||||
}),
|
||||
} as unknown as ExecutionContext;
|
||||
}
|
||||
|
||||
export function getRolesMetadata(handler: Function): string[] | undefined {
|
||||
return Reflect.getMetadata(ROLES_KEY, handler) as string[] | undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user