Skip to content

Commit 8151459

Browse files
author
Simon Hofmann
committed
(#11) Updated E2E tests
1 parent ca881d4 commit 8151459

File tree

1 file changed

+131
-9
lines changed

1 file changed

+131
-9
lines changed

index.spec.ts

+131-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import {secret} from "./index";
2-
import {Algorithm} from "./lib/algorithm.enum";
1+
import {Algorithm, secret} from "./index";
32

4-
describe("secret", () => {
3+
describe("AES/CBC with IV", () => {
54
it("should return the initial input when passing encrypt to decrypt", async () => {
65
// GIVEN
76
const key = "C9HikSYQW/K+ZvRphxEuSw==";
87
const input = "Can you keep a secret?";
98

109
// WHEN
11-
const encrypted = await secret.encrypt(input, key);
12-
const output = await secret.decrypt(encrypted, key);
10+
const encrypted = await secret.encrypt(input, key, Algorithm.AES128CBC);
11+
const output = await secret.decrypt(encrypted, key, Algorithm.AES128CBC);
1312

1413
// THEN
1514
expect(output).toBe(input);
@@ -21,8 +20,8 @@ describe("secret", () => {
2120
const input = "Can you keep a secret?";
2221

2322
// WHEN
24-
const encrypted = await secret.encrypt(input, key);
25-
const output = await secret.decrypt(encrypted, key);
23+
const encrypted = await secret.encrypt(input, key, Algorithm.AES128CBC);
24+
const output = await secret.decrypt(encrypted, key, Algorithm.AES128CBC);
2625

2726
// THEN
2827
expect(output).toBe(input);
@@ -34,8 +33,131 @@ describe("secret", () => {
3433
const input = "Can you keep a secret?";
3534

3635
// WHEN
37-
const encrypted = await secret.encrypt(input, key);
38-
const output = await secret.decrypt(encrypted, key);
36+
const encrypted = await secret.encrypt(input, key, Algorithm.AES256CBC);
37+
const output = await secret.decrypt(encrypted, key, Algorithm.AES256CBC);
38+
39+
// THEN
40+
expect(output).toBe(input);
41+
});
42+
});
43+
44+
describe("AES/CBC without IV", () => {
45+
it("should return the initial input when passing encrypt to decrypt", async () => {
46+
// GIVEN
47+
const key = "C9HikSYQW/K+ZvRphxEuSw==";
48+
const input = "Can you keep a secret?";
49+
50+
// WHEN
51+
const encrypted = await secret.encrypt(input, key, Algorithm.AES128CBC, false);
52+
const output = await secret.decrypt(encrypted, key, Algorithm.AES128CBC, false);
53+
54+
// THEN
55+
expect(output).toBe(input);
56+
});
57+
58+
it("should return the initial input when passing encrypt to decrypt with generated key for AES128CBC", async () => {
59+
// GIVEN
60+
const key = await secret.generateKey(Algorithm.AES128CBC);
61+
const input = "Can you keep a secret?";
62+
63+
// WHEN
64+
const encrypted = await secret.encrypt(input, key, Algorithm.AES128CBC, false);
65+
const output = await secret.decrypt(encrypted, key, Algorithm.AES128CBC, false);
66+
67+
// THEN
68+
expect(output).toBe(input);
69+
});
70+
71+
it("should return the initial input when passing encrypt to decrypt with generated key for AES256CBC", async () => {
72+
// GIVEN
73+
const key = await secret.generateKey(Algorithm.AES256CBC);
74+
const input = "Can you keep a secret?";
75+
76+
// WHEN
77+
const encrypted = await secret.encrypt(input, key, Algorithm.AES256CBC, false);
78+
const output = await secret.decrypt(encrypted, key, Algorithm.AES256CBC, false);
79+
80+
// THEN
81+
expect(output).toBe(input);
82+
});
83+
});
84+
85+
describe("AES/ECB with IV", () => {
86+
it("should return the initial input when passing encrypt to decrypt", async () => {
87+
// GIVEN
88+
const key = "C9HikSYQW/K+ZvRphxEuSw==";
89+
const input = "Can you keep a secret?";
90+
91+
// WHEN
92+
const encrypted = await secret.encrypt(input, key, Algorithm.AES128ECB);
93+
const output = await secret.decrypt(encrypted, key, Algorithm.AES128ECB);
94+
95+
// THEN
96+
expect(output).toBe(input);
97+
});
98+
99+
it("should return the initial input when passing encrypt to decrypt with generated key for AES128ECB", async () => {
100+
// GIVEN
101+
const key = await secret.generateKey(Algorithm.AES128ECB);
102+
const input = "Can you keep a secret?";
103+
104+
// WHEN
105+
const encrypted = await secret.encrypt(input, key, Algorithm.AES128ECB);
106+
const output = await secret.decrypt(encrypted, key, Algorithm.AES128ECB);
107+
108+
// THEN
109+
expect(output).toBe(input);
110+
});
111+
112+
it("should return the initial input when passing encrypt to decrypt with generated key for AES256ECB", async () => {
113+
// GIVEN
114+
const key = await secret.generateKey(Algorithm.AES256ECB);
115+
const input = "Can you keep a secret?";
116+
117+
// WHEN
118+
const encrypted = await secret.encrypt(input, key, Algorithm.AES256ECB);
119+
const output = await secret.decrypt(encrypted, key, Algorithm.AES256ECB);
120+
121+
// THEN
122+
expect(output).toBe(input);
123+
});
124+
});
125+
126+
describe("AES/ECB without IV", () => {
127+
it("should return the initial input when passing encrypt to decrypt", async () => {
128+
// GIVEN
129+
const key = "C9HikSYQW/K+ZvRphxEuSw==";
130+
const input = "Can you keep a secret?";
131+
132+
// WHEN
133+
const encrypted = await secret.encrypt(input, key, Algorithm.AES128ECB, false);
134+
const output = await secret.decrypt(encrypted, key, Algorithm.AES128ECB, false);
135+
136+
// THEN
137+
expect(output).toBe(input);
138+
});
139+
140+
it("should return the initial input when passing encrypt to decrypt with generated key for AES128ECB", async () => {
141+
// GIVEN
142+
const key = await secret.generateKey(Algorithm.AES128ECB);
143+
const input = "Can you keep a secret?";
144+
145+
// WHEN
146+
const encrypted = await secret.encrypt(input, key, Algorithm.AES128ECB, false);
147+
const output = await secret.decrypt(encrypted, key, Algorithm.AES128ECB, false);
148+
149+
// THEN
150+
expect(output).toBe(input);
151+
});
152+
153+
it("should return the initial input when passing encrypt to decrypt with generated key for AES256ECB", async () => {
154+
// GIVEN
155+
const key = await secret.generateKey(Algorithm.AES256ECB);
156+
const input = "Can you keep a secret?";
157+
158+
// WHEN
159+
const encrypted = await secret.encrypt(input, key, Algorithm.AES256ECB, false);
160+
const output = await secret.decrypt(encrypted, key, Algorithm.AES256ECB, false);
39161

40162
// THEN
41163
expect(output).toBe(input);

0 commit comments

Comments
 (0)