-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdecrypt.spec.js
66 lines (51 loc) · 1.73 KB
/
decrypt.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* eslint-env mocha */
'use strict'
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const bufferStream = require('pull-buffer-stream')
const pull = require('pull-stream/pull')
const collect = require('pull-stream/sinks/collect')
const {
createMfs,
createShardedDirectory
} = require('./helpers')
const randomBytes = require('./helpers/random-bytes')
const {
encrypt,
decrypt,
generateRandomIV,
generateRandomKey
} = require('../src/core/utils/crypto/symmetric')
describe('decrypt', () => {
let mfs, algorithm = "aes-256-cbc", key = generateRandomKey(), iv = generateRandomIV()
let smallFile = Buffer.from("small message from vasa")
before(async () => {
mfs = await createMfs()
})
let method = {
name: 'decrypt',
read: function () {
return mfs.read.apply(mfs, arguments)
},
collect: (buffer) => buffer
};
describe(`read & ${method.name}`, () => {
it('reads a small file', async () => {
const filePath = '/small-file.txt'
await mfs.write(filePath, smallFile, {
create: true,
crypto: {"algorithm": algorithm, "key": key, "iv": iv}
})
const result = await method.read(filePath, {
crypto: {"algorithm": algorithm, "key": key}
})
let json = JSON.stringify(result);
let bufferOriginal = Buffer.from(JSON.parse(json).data);
expect(bufferOriginal.toString('utf8'))
.equal("small message from vasa","decrypted data doesn't match the original data")
const buffer = await method.collect(result)
//expect(buffer).to.deep.equal(smallFile)
})
})
});