-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from narval-xyz/feature/nar-1545-app-setup-ke…
…ygen Feature/nar 1545 app setup keygen
- Loading branch information
Showing
25 changed files
with
7,734 additions
and
5,726 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
# IMPORTANT: The variables defined here will override other variables. | ||
# See `./apps/armory/jest.setup.ts`. | ||
|
||
NODE_ENV=test | ||
|
||
PORT=3005 | ||
|
||
ARMORY_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/armory_test?schema=public" | ||
|
||
REDIS_HOST=localhost | ||
REDIS_PORT=6379 | ||
|
||
PRICE_FEED_PRIVATE_KEY="0xc7a1b8ba040a238e36058fc5693f801d129aca9f10ed30d0133878f1b9147c01" | ||
HISTORICAL_TRANSFER_FEED_PRIVATE_KEY="0xf5c8f17cc09215c5038f6b8d5e557c0d98d341236307fe831efdcdd7faeef134" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
# IMPORTANT: The variables defined here will override other variables. | ||
# See `./apps/policy-engine/jest.setup.ts`. | ||
NODE_ENV=test | ||
|
||
PORT=3010 | ||
|
||
POLICY_ENGINE_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/engine-test?schema=public" | ||
|
||
ENGINE_UID="local-dev-engine-instance-1" | ||
|
||
MASTER_PASSWORD="unsafe-local-test-master-password" | ||
|
||
KEYRING_TYPE="raw" | ||
|
||
# MASTER_AWS_KMS_ARN="arn:aws:kms:us-east-2:728783560968:key/f6aa3ddb-47c3-4f31-977d-b93205bb23d1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
apps/policy-engine/src/encryption/core/__test__/unit/encryption.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { ConfigModule, ConfigService } from '@nestjs/config' | ||
import { Test } from '@nestjs/testing' | ||
import { mock } from 'jest-mock-extended' | ||
import nock from 'nock' | ||
import { load } from '../../../../policy-engine.config' | ||
import { EncryptionRepository } from '../../../persistence/repository/encryption.repository' | ||
import { EncryptionService } from '../../encryption.service' | ||
|
||
describe('EncryptionService', () => { | ||
let service: EncryptionService | ||
|
||
nock.enableNetConnect('kms.us-east-2.amazonaws.com:443') | ||
|
||
beforeEach(async () => { | ||
// These mocked config values matter; they're specifically tied to the mocked masterKey below | ||
// If you change these, the decryption won't work & tests will fail | ||
const configServiceMock = mock<ConfigService>({ | ||
get: jest.fn().mockImplementation((key: string) => { | ||
if (key === 'keyring') { | ||
return { | ||
type: 'raw', | ||
masterPassword: 'unsafe-local-dev-master-password' | ||
} | ||
} | ||
if (key === 'engine.id') { | ||
return 'local-dev-engine-instance-1' | ||
} | ||
}) | ||
}) | ||
|
||
const encryptionRepositoryMock = { | ||
getEngine: jest.fn().mockImplementation(() => | ||
Promise.resolve({ | ||
// unencryptedMasterKey: dfd9cc70f1ad02d19e0efa020d82f557022f59ca6bedbec1df38e8fd37ae3bb9 | ||
masterKey: | ||
'0205785d67737fa3bae8eb249cf8d3baed5942f1677d8c98b4cdeef55560a3bcf510bd008d00030003617070000d61726d6f72792d656e67696e6500156177732d63727970746f2d7075626c69632d6b657900444177336764324b6e58646f512f2b76745347367031444442384d65766d61434b324c7861426e65476a315531537777526b376b4d366868752f707a446f48724c77773d3d0007707572706f7365000f646174612d656e6372797074696f6e000100146e617276616c2e61726d6f72792e656e67696e65002561726d6f72792e656e67696e652e6b656b000000800000000c8a92a7c9deb43316f6c29e8d0030132d63c7337c9888a06b638966e83056a0575958b42588b7aed999b9659e6d4bc5bed4664d91fae0b14d48917e00cdbb02000010000749ed0ed3616b7990f9e73f5a42eb46dc182002612e33dcb8e3c7d4759184c46ce3f0893a87ac15257d53097ac5d74affffffff00000001000000000000000000000001000000205d7209b51db8cf8264b9065add71a8514dc26baa6987d8a0a3acb1c4a2503b0f3b7c974a35ed234c1b94668736cd8bfa00673065023100a5d8d192e9802649dab86af6e00ab6d7472533e85dfe1006cb8bd9ef2472d15096fa42e742d18cb92530c762c3bd44d40230350299b42feaa1149c6ad1b25add24c30b3bf1c08263b96df0d43e2ad3e19802872e792040f1faf3d0a73bca6fb067ca', | ||
id: 'test-engine-id' | ||
}) | ||
) | ||
} | ||
const moduleRef = await Test.createTestingModule({ | ||
imports: [ | ||
ConfigModule.forRoot({ | ||
load: [load], | ||
isGlobal: true | ||
}) | ||
], | ||
providers: [ | ||
EncryptionService, | ||
{ | ||
provide: EncryptionRepository, | ||
useValue: encryptionRepositoryMock | ||
}, | ||
{ | ||
provide: ConfigService, | ||
useValue: configServiceMock // use the mock ConfigService | ||
} | ||
] | ||
}).compile() | ||
|
||
service = moduleRef.get<EncryptionService>(EncryptionService) | ||
if (service.onApplicationBootstrap) { | ||
await service.onApplicationBootstrap() | ||
} | ||
}) | ||
|
||
it('should encrypt then decrypt successfully, with a string', async () => { | ||
const data = 'Hello World' | ||
const encrypted = await service.encrypt(data) | ||
const decrypted = await service.decrypt(encrypted) | ||
|
||
expect(decrypted.toString('utf-8')).toBe(data) | ||
}) | ||
|
||
it('should encrypt then decrypt successfully, with a buffer from a hexstring', async () => { | ||
const data = 'dfd9cc70f1ad02d19e0efa020d82f557022f59ca6bedbec1df38e8fd37ae3bb9' | ||
const encrypted = await service.encrypt(Buffer.from(data, 'hex')) | ||
const decrypted = await service.decrypt(encrypted) | ||
|
||
expect(decrypted.toString('hex')).toBe(data) | ||
}) | ||
}) |
Oops, something went wrong.