Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch policy data and signature from data store #157

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 0 additions & 222 deletions apps/policy-engine/src/app/__test__/e2e/admin.spec.ts

This file was deleted.

5 changes: 1 addition & 4 deletions apps/policy-engine/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import { load } from '../policy-engine.config'
import { KeyValueModule } from '../shared/module/key-value/key-value.module'
import { AppController } from './app.controller'
import { AppService } from './app.service'
import { AdminService } from './core/service/admin.service'
import { EngineService } from './core/service/engine.service'
import { TenantService } from './core/service/tenant.service'
import { AdminController } from './http/rest/controller/admin.controller'
import { TenantController } from './http/rest/controller/tenant.controller'
import { OpaService } from './opa/opa.service'
import { EngineRepository } from './persistence/repository/engine.repository'
Expand All @@ -27,10 +25,9 @@ import { TenantRepository } from './persistence/repository/tenant.repository'
EncryptionModule,
KeyValueModule
],
controllers: [AppController, AdminController, TenantController],
controllers: [AppController, TenantController],
providers: [
AppService,
AdminService,
OpaService,
EngineRepository,
EngineService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { DataStoreConfiguration, EntityData, EntitySignature, FIXTURE } from '@narval/policy-engine-shared'
import {
Action,
Criterion,
EntityData,
EntitySignature,
FIXTURE,
PolicyData,
PolicySignature,
Then
} from '@narval/policy-engine-shared'
import { HttpModule } from '@nestjs/axios'
import { HttpStatus } from '@nestjs/common'
import { Test } from '@nestjs/testing'
Expand All @@ -14,15 +23,35 @@ describe(DataStoreService.name, () => {

const remoteDataStoreUrl = 'http://9.9.9.9:9000'

const entityDataStore: EntityData = {
const entityData: EntityData = {
entity: {
data: FIXTURE.ENTITIES
}
}

const entitySignatureStore: EntitySignature = {
const policyData: PolicyData = {
policy: {
data: [
{
then: Then.PERMIT,
name: 'test-policy',
when: [
{
criterion: Criterion.CHECK_ACTION,
args: [Action.SIGN_TRANSACTION]
}
]
}
]
}
}

const signatureStore: EntitySignature & PolicySignature = {
entity: {
signature: 'test-signature'
signature: 'test-entity-signature'
},
policy: {
signature: 'test-policy-signature'
}
}

Expand All @@ -37,20 +66,34 @@ describe(DataStoreService.name, () => {

describe('fetch', () => {
it('fetches data and signature from distinct stores', async () => {
nock(remoteDataStoreUrl).get('/').reply(HttpStatus.OK, entityDataStore)
nock(remoteDataStoreUrl).get('/entity').reply(HttpStatus.OK, entityData)
nock(remoteDataStoreUrl).get('/policy').reply(HttpStatus.OK, policyData)

await withTempJsonFile(JSON.stringify(entitySignatureStore), async (path) => {
await withTempJsonFile(JSON.stringify(signatureStore), async (path) => {
const url = `file://${path}`
const config: DataStoreConfiguration = {
dataUrl: remoteDataStoreUrl,
signatureUrl: url,
keys: []
const store = {
entity: {
dataUrl: `${remoteDataStoreUrl}/entity`,
signatureUrl: url,
keys: []
},
policy: {
dataUrl: `${remoteDataStoreUrl}/policy`,
signatureUrl: url,
keys: []
}
}

const { entity } = await service.fetch(config)
const { entity, policy } = await service.fetch(store)

expect(entity.data).toEqual(entityDataStore.entity.data)
expect(entity.signature).toEqual(entitySignatureStore.entity.signature)
expect(entity).toEqual({
data: entityData.entity.data,
signature: signatureStore.entity.signature
})
expect(policy).toEqual({
data: policyData.policy.data,
signature: signatureStore.policy.signature
})
})
})
})
Expand Down
14 changes: 0 additions & 14 deletions apps/policy-engine/src/app/core/service/admin.service.ts

This file was deleted.

Loading
Loading