Skip to content

Commit

Permalink
Fix @app/orchestration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wcalderipe committed Jan 18, 2024
1 parent f3f3367 commit c448aab
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 110 deletions.
14 changes: 7 additions & 7 deletions apps/orchestration/src/policy-engine/__test__/e2e/facade.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import {
REQUEST_HEADER_ORG_ID
} from '@app/orchestration/orchestration.constant'
import { AuthorizationRequest, SupportedAction } from '@app/orchestration/policy-engine/core/type/domain.type'
import { AuthorizationRequestRepository } from '@app/orchestration/policy-engine/http/persistence/repository/authorization-request.repository'
import { SignatureDto } from '@app/orchestration/policy-engine/http/rest/dto/signature.dto'
import { AuthorizationRequestRepository } from '@app/orchestration/policy-engine/persistence/repository/authorization-request.repository'
import { PolicyEngineModule } from '@app/orchestration/policy-engine/policy-engine.module'
import { PersistenceModule } from '@app/orchestration/shared/module/persistence/persistence.module'
import { TestPrismaService } from '@app/orchestration/shared/module/persistence/service/test-prisma.service'
import { QueueModule } from '@app/orchestration/shared/module/queue/queue.module'
import { TransactionType } from '@narval/authz-shared'
import { TransactionType, hashRequest } from '@narval/authz-shared'
import { getQueueToken } from '@nestjs/bull'
import { HttpStatus, INestApplication } from '@nestjs/common'
import { ConfigModule } from '@nestjs/config'
import { Test, TestingModule } from '@nestjs/testing'
import { AuthorizationRequestStatus, Organization } from '@prisma/client/orchestration'
import { Queue } from 'bull'
import request from 'supertest'
import { hashMessage, stringToHex } from 'viem'
import { stringToHex } from 'viem'

const EVALUATIONS_ENDPOINT = '/policy-engine/evaluations'

Expand Down Expand Up @@ -102,7 +102,7 @@ describe('Policy Engine Cluster Facade', () => {
const payload = {
action: SupportedAction.SIGN_MESSAGE,
request: signMessageRequest,
hash: hashMessage(JSON.stringify(signMessageRequest)),
hash: hashRequest(signMessageRequest),
authentication,
approvals
}
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('Policy Engine Cluster Facade', () => {
}
const payload = {
action: SupportedAction.SIGN_TRANSACTION,
hash: hashMessage(JSON.stringify(signTransactionRequest)),
hash: hashRequest(signTransactionRequest),
request: signTransactionRequest,
authentication,
approvals
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('Policy Engine Cluster Facade', () => {
}
const payload = {
action: SupportedAction.SIGN_TRANSACTION,
hash: hashMessage(JSON.stringify(signTransactionRequest)),
hash: hashRequest(signTransactionRequest),
request: signTransactionRequest,
authentication,
approvals
Expand Down Expand Up @@ -212,7 +212,7 @@ describe('Policy Engine Cluster Facade', () => {
status: AuthorizationRequestStatus.PERMITTED,
action: SupportedAction.SIGN_MESSAGE,
request: signMessageRequest,
hash: hashMessage(JSON.stringify(signMessageRequest)),
hash: hashRequest(signMessageRequest),
idempotencyKey: '8dcbb7ad-82a2-4eca-b2f0-b1415c1d4a17',
createdAt: new Date(),
updatedAt: new Date(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
AuthorizationRequestStatus,
CreateAuthorizationRequest
} from '@app/orchestration/policy-engine/core/type/domain.type'
import { AuthorizationRequestRepository } from '@app/orchestration/policy-engine/http/persistence/repository/authorization-request.repository'
import { AuthorizationRequestRepository } from '@app/orchestration/policy-engine/persistence/repository/authorization-request.repository'
import { AuthorizationRequestProcessingProducer } from '@app/orchestration/policy-engine/queue/producer/authorization-request-processing.producer'
import { ApplicationException } from '@app/orchestration/shared/exception/application.exception'
import { HttpService } from '@nestjs/axios'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RequestHash } from '@app/orchestration/policy-engine/http/rest/dto/validator/request-hash.validator'
import { hashRequest } from '@narval/authz-shared'
import { ValidationArguments } from 'class-validator'

describe(RequestHash.name, () => {
Expand All @@ -11,7 +12,7 @@ describe(RequestHash.name, () => {
describe('validate', () => {
it('returns true if the given hash matches the hash of the request object', () => {
const request = { foo: 'bar' }
const hash = RequestHash.hash(request)
const hash = hashRequest(request)
const args: ValidationArguments = {
targetName: 'AuthorizationRequestDto',
object: { request },
Expand Down Expand Up @@ -70,7 +71,7 @@ describe(RequestHash.name, () => {

const message = validator.defaultMessage(args)

expect(message).toEqual(`${property} is not a valid EIP-191 hash format`)
expect(message).toEqual(`${property} is not a valid hexadecimal SHA256 hash`)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { stringify } from '@app/orchestration/shared/lib/json'
import { hashRequest } from '@narval/authz-shared'
import { ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface } from 'class-validator'
import { hashMessage } from 'viem'

@ValidatorConstraint({ async: false })
export class RequestHash implements ValidatorConstraintInterface {
validate(givenHash: string, args: ValidationArguments) {
if ('request' in args.object) {
const hash = RequestHash.hash(args.object.request)
const hash = hashRequest(args.object.request)

return givenHash === hash
}
Expand All @@ -15,10 +14,6 @@ export class RequestHash implements ValidatorConstraintInterface {
}

defaultMessage(args: ValidationArguments) {
return `${args.property} is not a valid EIP-191 hash format`
}

static hash(request: unknown): string {
return hashMessage(stringify(request))
return `${args.property} is not a valid hexadecimal SHA256 hash`
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TransactionType } from '@app/orchestration/policy-engine/core/type/domain.type'
import { TransactionType } from '@narval/authz-shared'
import { isAddress, isHex } from 'viem'
import { z } from 'zod'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
AuthorizationRequestStatus,
SupportedAction
} from '@app/orchestration/policy-engine/core/type/domain.type'
import { AuthorizationRequestRepository } from '@app/orchestration/policy-engine/http/persistence/repository/authorization-request.repository'
import { AuthorizationRequestRepository } from '@app/orchestration/policy-engine/persistence/repository/authorization-request.repository'
import { AuthorizationRequestProcessingConsumer } from '@app/orchestration/policy-engine/queue/consumer/authorization-request-processing.consumer'
import { AuthorizationRequestProcessingProducer } from '@app/orchestration/policy-engine/queue/producer/authorization-request-processing.producer'
import { PersistenceModule } from '@app/orchestration/shared/module/persistence/persistence.module'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
AuthorizationRequestStatus,
SupportedAction
} from '@app/orchestration/policy-engine/core/type/domain.type'
import { AuthorizationRequestRepository } from '@app/orchestration/policy-engine/http/persistence/repository/authorization-request.repository'
import { AuthorizationRequestRepository } from '@app/orchestration/policy-engine/persistence/repository/authorization-request.repository'
import {
AuthorizationRequestProcessingProducer,
DEFAULT_JOB_OPTIONS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
AuthorizationRequestProcessingJob,
AuthorizationRequestStatus
} from '@app/orchestration/policy-engine/core/type/domain.type'
import { AuthorizationRequestRepository } from '@app/orchestration/policy-engine/http/persistence/repository/authorization-request.repository'
import { AuthorizationRequestRepository } from '@app/orchestration/policy-engine/persistence/repository/authorization-request.repository'
import { InjectQueue } from '@nestjs/bull'
import { Injectable, Logger } from '@nestjs/common'
import { BackoffOptions, Job, Queue } from 'bull'
Expand Down
30 changes: 0 additions & 30 deletions apps/orchestration/src/shared/lib/__test__/unit/json.spec.ts

This file was deleted.

58 changes: 0 additions & 58 deletions apps/orchestration/src/shared/lib/json.ts

This file was deleted.

0 comments on commit c448aab

Please sign in to comment.