Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-protocol/src/encryption/encryption-engine.spec.ts
2500 views
1
/**
2
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { suite, test } from "@testdeck/mocha";
8
import * as chai from "chai";
9
import * as path from "path";
10
import * as fs from "fs";
11
12
import { EncryptionEngineImpl } from "./encryption-engine";
13
14
const expect = chai.expect;
15
16
@suite
17
class TestEncryptionEngineImpl {
18
// Created with openssl rand -rand /dev/urandom -out key -base64 32
19
protected get testkey() {
20
const keyFilePath = path.resolve(__dirname, "../../test/fixtures/encryption/testkey");
21
const keyBuffer = fs.readFileSync(keyFilePath);
22
return keyBuffer.toString().trim();
23
}
24
25
@test basicSymmetry() {
26
const plaintext = "12345678901234567890";
27
const key = Buffer.from(this.testkey, "base64");
28
29
const cut = new EncryptionEngineImpl();
30
const encryptedData = cut.encrypt(plaintext, key);
31
expect(encryptedData).to.be.not.undefined;
32
33
const decryptedPlaintext = cut.decrypt(encryptedData, key);
34
expect(decryptedPlaintext).equals(plaintext);
35
}
36
}
37
export const t = new TestEncryptionEngineImpl();
38
39