Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel committed Feb 8, 2024
1 parent 26fdc7a commit 8ff00bd
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 184 deletions.
182 changes: 89 additions & 93 deletions apps/authz/src/app/__test__/e2e/admin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ describe('Admin Endpoints', () => {
})
})

describe.only('POST /policies', () => {
describe('POST /policies', () => {
it('sets the organization policies', async () => {
const payload = {
authentication: {
Expand Down Expand Up @@ -468,56 +468,56 @@ describe('Admin Endpoints', () => {
{
criterion: 'checkResourceIntegrity',
args: null
},
{
criterion: 'checkNonceExists',
args: null
},
{
criterion: 'checkAction',
args: ['signTransaction']
},
{
criterion: 'checkPrincipalId',
args: ['matt@narval.xyz']
},
{
criterion: 'checkWalletId',
args: ['eip155:eoa:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b']
},
{
criterion: 'checkIntentType',
args: ['transferNative']
},
{
criterion: 'checkIntentToken',
args: ['eip155:137/slip44:966']
},
{
criterion: 'checkIntentAmount',
args: {
currency: '*',
operator: 'lte',
value: '1000000000000000000'
}
},
{
criterion: 'checkApprovals',
args: [
{
approvalCount: 2,
countPrincipal: false,
approvalEntityType: 'Narval::User',
entityIds: ['aa@narval.xyz', 'bb@narval.xyz']
},
{
approvalCount: 1,
countPrincipal: false,
approvalEntityType: 'Narval::UserRole',
entityIds: ['admin']
}
]
}
// {
// criterion: 'checkNonceExists',
// args: null
// },
// {
// criterion: 'checkAction',
// args: ['signTransaction']
// },
// {
// criterion: 'checkPrincipalId',
// args: ['matt@narval.xyz']
// },
// {
// criterion: 'checkWalletId',
// args: ['eip155:eoa:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b']
// },
// {
// criterion: 'checkIntentType',
// args: ['transferNative']
// },
// {
// criterion: 'checkIntentToken',
// args: ['eip155:137/slip44:966']
// },
// {
// criterion: 'checkIntentAmount',
// args: {
// currency: '*',
// operator: 'lte',
// value: '1000000000000000000'
// }
// },
// {
// criterion: 'checkApprovals',
// args: [
// {
// approvalCount: 2,
// countPrincipal: false,
// approvalEntityType: 'Narval::User',
// entityIds: ['aa@narval.xyz', 'bb@narval.xyz']
// },
// {
// approvalCount: 1,
// countPrincipal: false,
// approvalEntityType: 'Narval::UserRole',
// entityIds: ['admin']
// }
// ]
// }
]
},
{
Expand All @@ -527,45 +527,45 @@ describe('Admin Endpoints', () => {
{
criterion: 'checkResourceIntegrity',
args: null
},
{
criterion: 'checkNonceExists',
args: null
},
{
criterion: 'checkAction',
args: ['signTransaction']
},
{
criterion: 'checkPrincipalId',
args: ['matt@narval.xyz']
},
{
criterion: 'checkWalletId',
args: ['eip155:eoa:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b']
},
{
criterion: 'checkIntentType',
args: ['transferNative']
},
{
criterion: 'checkIntentToken',
args: ['eip155:137/slip44:966']
},
{
criterion: 'checkSpendingLimit',
args: {
limit: '1000000000000000000',
timeWindow: {
type: 'rolling',
value: 43200
},
filters: {
tokens: ['eip155:137/slip44:966'],
users: ['matt@narval.xyz']
}
}
}
// {
// criterion: 'checkNonceExists',
// args: null
// },
// {
// criterion: 'checkAction',
// args: ['signTransaction']
// },
// {
// criterion: 'checkPrincipalId',
// args: ['matt@narval.xyz']
// },
// {
// criterion: 'checkWalletId',
// args: ['eip155:eoa:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b']
// },
// {
// criterion: 'checkIntentType',
// args: ['transferNative']
// },
// {
// criterion: 'checkIntentToken',
// args: ['eip155:137/slip44:966']
// },
// {
// criterion: 'checkSpendingLimit',
// args: {
// limit: '1000000000000000000',
// timeWindow: {
// type: 'rolling',
// value: 43200
// },
// filters: {
// tokens: ['eip155:137/slip44:966'],
// users: ['matt@narval.xyz']
// }
// }
// }
]
}
]
Expand All @@ -577,11 +577,7 @@ describe('Admin Endpoints', () => {
.set(REQUEST_HEADER_ORG_ID, org.uid)
.send(payload)

console.dir(body, { depth: null })

// expect(body).toMatchObject({
// tokens: payload.request.tokens
// })
expect(body.policyRules).toMatchObject(payload.request.data)
expect(status).toEqual(HttpStatus.CREATED)
})
})
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { ApiProperty } from '@nestjs/swagger'
import { IsDefined, Matches, ValidationOptions } from 'class-validator'

export function IsAccountId(validationOptions?: ValidationOptions) {
const regex = new RegExp('^eip155:d+/w+$')
const regex = /^(eip155:(\d+|eoa):\w+)$/

return applyDecorators(
IsDefined(),
Matches(regex, validationOptions),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { ApiProperty } from '@nestjs/swagger'
import { IsDefined, Matches, ValidationOptions } from 'class-validator'

export function IsAssetId(validationOptions?: ValidationOptions) {
const regex = new RegExp('^(eip155:d+/(erc1155|erc20|erc721):w+/w+|eip155:d+/slip44:d+)$')
const regex =
/^(eip155:\d+\/(erc1155|erc20|erc721):\w+)$|^(eip155:\d+\/(erc1155|erc20|erc721):\w+\/\w+)$|^(eip155:\d+\/slip44:\d+)$/

return applyDecorators(
IsDefined(),
Matches(regex, validationOptions),
Expand Down
14 changes: 7 additions & 7 deletions packages/authz-shared/src/lib/type/policy-builder.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ export class SpendingLimitTimeWindow {

export class SpendingLimitFilters {
@IsNotEmptyArrayString()
@IsAccountId({ each: true })
@IsAssetId({ each: true })
@IsOptional()
tokens?: AccountId[]
tokens?: AssetId[]

@IsNotEmptyArrayString()
@IsOptional()
Expand Down Expand Up @@ -364,8 +364,8 @@ class IntentTokenCriterion extends BaseCriterion {
criterion: typeof Criterion.CHECK_INTENT_TOKEN

@IsNotEmptyArrayString()
@IsAccountId({ each: true })
args: AccountId[]
@IsAssetId({ each: true })
args: AssetId[]
}

class IntentSpenderCriterion extends BaseCriterion {
Expand Down Expand Up @@ -598,7 +598,7 @@ export class Policy {
@IsArray()
@ValidateNested({ each: true })
@Transform(({ value }) => {
return value.map(({ criterion }: PolicyCriterion) => {
return value.map((criterion: PolicyCriterion) => {
return instantiateCriterion(criterion)
})
})
Expand All @@ -615,8 +615,8 @@ export class Policy {
then: Then
}

const instantiateCriterion = (criterion: Criterion) => {
switch (criterion) {
const instantiateCriterion = (criterion: PolicyCriterion) => {
switch (criterion.criterion) {
case Criterion.CHECK_ACTION:
return plainToInstance(ActionCriterion, criterion)
case Criterion.CHECK_RESOURCE_INTEGRITY:
Expand Down
2 changes: 1 addition & 1 deletion packages/authz-shared/src/lib/util/caip.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export enum AssetType {
/**
* @see https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md
*/
export type AccountId = `${Namespace}:${number}/${string}`
export type AccountId = `${Namespace}:${number | 'eoa'}/${string}`

export type Account = {
chainId: number
Expand Down

0 comments on commit 8ff00bd

Please sign in to comment.