From a3e5f804ad821f6979e8735b0569b1209986fedc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 10 Oct 2022 11:12:23 +0200 Subject: Encrypt OTP secret --- server/tests/helpers/crypto.ts | 33 +++++++++++++++++++++++++++++++++ server/tests/helpers/index.ts | 3 ++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 server/tests/helpers/crypto.ts (limited to 'server/tests/helpers') diff --git a/server/tests/helpers/crypto.ts b/server/tests/helpers/crypto.ts new file mode 100644 index 000000000..b508c715b --- /dev/null +++ b/server/tests/helpers/crypto.ts @@ -0,0 +1,33 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import { expect } from 'chai' +import { decrypt, encrypt } from '@server/helpers/peertube-crypto' + +describe('Encrypt/Descrypt', function () { + + it('Should encrypt and decrypt the string', async function () { + const secret = 'my_secret' + const str = 'my super string' + + const encrypted = await encrypt(str, secret) + const decrypted = await decrypt(encrypted, secret) + + expect(str).to.equal(decrypted) + }) + + it('Should not decrypt without the same secret', async function () { + const str = 'my super string' + + const encrypted = await encrypt(str, 'my_secret') + + let error = false + + try { + await decrypt(encrypted, 'my_sicret') + } catch (err) { + error = true + } + + expect(error).to.be.true + }) +}) diff --git a/server/tests/helpers/index.ts b/server/tests/helpers/index.ts index 951208842..42d644c40 100644 --- a/server/tests/helpers/index.ts +++ b/server/tests/helpers/index.ts @@ -1,6 +1,7 @@ -import './image' +import './crypto' import './core-utils' import './dns' +import './dns' import './comment-model' import './markdown' import './request' -- cgit v1.2.3