2019-06-20 00:20:09 +02:00
|
|
|
import { assert, expect, spy, use } from 'chai'
|
|
|
|
import * as spies from 'chai-spies'
|
2019-02-14 11:26:12 +01:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
import Account from '../../src/ocean/Account'
|
|
|
|
import { Ocean } from '../../src/ocean/Ocean'
|
|
|
|
import { OceanSecretStore } from '../../src/ocean/OceanSecretStore'
|
|
|
|
import config from '../config'
|
2019-02-14 11:26:12 +01:00
|
|
|
|
|
|
|
use(spies)
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('OceanSecretStore', () => {
|
2019-02-14 11:26:12 +01:00
|
|
|
let oceanSecretStore: OceanSecretStore
|
|
|
|
let accounts: Account[]
|
|
|
|
|
2019-04-01 12:40:45 +02:00
|
|
|
let ocean: Ocean
|
2019-06-20 00:20:09 +02:00
|
|
|
const did = 'a'.repeat(64)
|
2019-02-14 11:26:12 +01:00
|
|
|
|
|
|
|
before(async () => {
|
2019-04-01 12:40:45 +02:00
|
|
|
ocean = await Ocean.getInstance(config)
|
2019-03-21 02:56:58 +01:00
|
|
|
oceanSecretStore = ocean.secretStore
|
|
|
|
accounts = await ocean.accounts.list()
|
2019-02-14 11:26:12 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
spy.restore()
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#encrypt()', () => {
|
|
|
|
it('should encrypt a content', async () => {
|
|
|
|
const secretStoreEncryptSpy = spy.on(
|
|
|
|
ocean.brizo,
|
|
|
|
'encrypt',
|
|
|
|
() => 'encryptedResult'
|
|
|
|
)
|
2019-02-14 11:26:12 +01:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
const result = await oceanSecretStore.encrypt(
|
|
|
|
did,
|
|
|
|
'test',
|
|
|
|
accounts[0]
|
|
|
|
)
|
2019-02-14 11:26:12 +01:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
expect(secretStoreEncryptSpy).to.have.been.called.with(did, 'test')
|
2019-02-14 11:26:12 +01:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
assert.equal(result, 'encryptedResult', "Result doesn't match")
|
2019-02-14 11:26:12 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|