Path: blob/main/components/gitpod-protocol/src/encryption/encryption-engine.spec.ts
2500 views
/**1* Copyright (c) 2020 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { suite, test } from "@testdeck/mocha";7import * as chai from "chai";8import * as path from "path";9import * as fs from "fs";1011import { EncryptionEngineImpl } from "./encryption-engine";1213const expect = chai.expect;1415@suite16class TestEncryptionEngineImpl {17// Created with openssl rand -rand /dev/urandom -out key -base64 3218protected get testkey() {19const keyFilePath = path.resolve(__dirname, "../../test/fixtures/encryption/testkey");20const keyBuffer = fs.readFileSync(keyFilePath);21return keyBuffer.toString().trim();22}2324@test basicSymmetry() {25const plaintext = "12345678901234567890";26const key = Buffer.from(this.testkey, "base64");2728const cut = new EncryptionEngineImpl();29const encryptedData = cut.encrypt(plaintext, key);30expect(encryptedData).to.be.not.undefined;3132const decryptedPlaintext = cut.decrypt(encryptedData, key);33expect(decryptedPlaintext).equals(plaintext);34}35}36export const t = new TestEncryptionEngineImpl();373839