diff --git a/apps/authz/src/app/__test__/e2e/admin.spec.ts b/apps/authz/src/app/__test__/e2e/admin.spec.ts index 564660014..c25fffe95 100644 --- a/apps/authz/src/app/__test__/e2e/admin.spec.ts +++ b/apps/authz/src/app/__test__/e2e/admin.spec.ts @@ -459,6 +459,7 @@ describe('Admin Endpoints', () => { ], request: { action: 'setPolicyRules', + nonce: 'random-nonce', data: [ { then: 'permit', @@ -466,7 +467,7 @@ describe('Admin Endpoints', () => { when: [ { criterion: 'checkAction', - args: ['fooo'] + args: ['signTransaction'] } ] } diff --git a/apps/authz/src/app/http/rest/dto/policy-rules/set-policy-rules-request.dto.ts b/apps/authz/src/app/http/rest/dto/policy-rules/set-policy-rules-request.dto.ts index 62a47f090..42d523437 100644 --- a/apps/authz/src/app/http/rest/dto/policy-rules/set-policy-rules-request.dto.ts +++ b/apps/authz/src/app/http/rest/dto/policy-rules/set-policy-rules-request.dto.ts @@ -27,6 +27,7 @@ export class SetPolicyRulesDto extends BaseActionDto { export class SetPolicyRulesRequestDto extends BaseAdminRequestPayloadDto { @IsDefined() @ValidateNested() + @Type(() => SetPolicyRulesDto) @ApiProperty() request: SetPolicyRulesDto } diff --git a/packages/authz-shared/src/lib/type/policy-builder.type.ts b/packages/authz-shared/src/lib/type/policy-builder.type.ts index 874712e44..63e945b26 100644 --- a/packages/authz-shared/src/lib/type/policy-builder.type.ts +++ b/packages/authz-shared/src/lib/type/policy-builder.type.ts @@ -14,7 +14,7 @@ import { import { Intents } from '@narval/transaction-request-intent' import { ApiExtraModels, ApiProperty, getSchemaPath } from '@nestjs/swagger' import { Type } from 'class-transformer' -import { IsDefined, IsEnum, IsIn, IsString } from 'class-validator' +import { IsDefined, IsEnum, IsIn, IsString, ValidateNested } from 'class-validator' export const Then = { PERMIT: 'permit', @@ -129,10 +129,8 @@ class ActionCriterion extends BaseCriterion { }) criterion: typeof Criterion.CHECK_ACTION - // TODO (@sam, 07/02/24): Check how to validate an array of enums. @IsDefined() - // @IsIn(Object.values(Action)) - @IsEnum(Object.values(Action), { + @IsEnum(Action, { each: true }) @ApiProperty({ @@ -387,27 +385,13 @@ export class Policy { @ApiProperty() name: string - // @ValidateNested({ each: true }) + @ValidateNested({ each: true }) // @Type(() => BaseCriterion, { // discriminator: { // property: 'criterion', // subTypes: [{ value: ActionCriterion, name: Criterion.CHECK_ACTION }] // } // }) - // @Type((opts) => { - // const foo = opts?.object.when.map((item: PolicyCriterion) => { - // switch (item.criterion) { - // case Criterion.CHECK_ACTION: - // return ActionCriterion - // default: - // return BaseCriterion - // } - // }) - - // console.log(foo) - - // return foo - // }) @Type(() => ActionCriterion) @ApiProperty({ oneOf: SUPPORTED_CRITERION.map((entity) => ({