]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import { expect } from 'chai' | |
4 | import { decrypt, encrypt } from '@server/helpers/peertube-crypto' | |
5 | ||
6 | describe('Encrypt/Descrypt', function () { | |
7 | ||
8 | it('Should encrypt and decrypt the string', async function () { | |
9 | const secret = 'my_secret' | |
10 | const str = 'my super string' | |
11 | ||
12 | const encrypted = await encrypt(str, secret) | |
13 | const decrypted = await decrypt(encrypted, secret) | |
14 | ||
15 | expect(str).to.equal(decrypted) | |
16 | }) | |
17 | ||
18 | it('Should not decrypt without the same secret', async function () { | |
19 | const str = 'my super string' | |
20 | ||
21 | const encrypted = await encrypt(str, 'my_secret') | |
22 | ||
23 | let error = false | |
24 | ||
25 | try { | |
26 | await decrypt(encrypted, 'my_sicret') | |
27 | } catch (err) { | |
28 | error = true | |
29 | } | |
30 | ||
31 | expect(error).to.be.true | |
32 | }) | |
33 | }) |