]> git.ardis.lu - envpass/commitdiff
Add tests for nonstandard encrypt or decrypt behavior
authorArdis Lu <ardisglu@gmail.com>
Sat, 15 Aug 2026 06:15:02 +0000 (23:15 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sat, 15 Aug 2026 06:15:02 +0000 (23:15 -0700)
test/index.test.js

index fa89fa880fcea198f31c9d2060d5f1a3dd0de20b..3105c79b872ff0059c26b2ef88ea31a412cd8537 100644 (file)
@@ -75,6 +75,24 @@ suite('e2e', () => {
     await fileEqual(envFile, env);
     deepStrictEqual(openMock.mock.calls.length, 0);
   });
+  test("encrypt encrypts again when alreadyEncryptedValue: 'encrypt'", async (t) => {
+    const { page } = await setupPlaywright(t);
+    const env = 'A=envpass:v1:AAA\nB=envpass:v1:BBB\nC=envpass:v1:CCC\n';
+    const envFile = await setupEnv(t, env);
+    mockOpen(t, page);
+    assertConsole(t, { debug: 0, info: 0, warn: 0, error: 0 });
+
+    await encrypt({ inFile: envFile, alreadyEncryptedValue: 'encrypt' });
+
+    await fileNotEqual(envFile, env);
+  });
+  test("encrypt throws when alreadyEncryptedValue: 'error'", async (t) => {
+    const env = 'A=envpass:v1:AAA\nB=envpass:v1:BBB\nC=envpass:v1:CCC\n';
+    const envFile = await setupEnv(t, env);
+    assertConsole(t, { debug: 0, info: 0, warn: 0, error: 0 });
+
+    await rejects(encrypt({ inFile: envFile, alreadyEncryptedValue: 'error' }), /Environment variable \".+\" is already encrypted\./);
+  });
   test('encrypt does nothing when env is empty', async (t) => {
     const openMock = t.mock.method(BROWSER, 'open');
     const env = '';
@@ -108,6 +126,12 @@ suite('e2e', () => {
     await fileEqual(envFile, STD_ENV);
     deepStrictEqual(openMock.mock.calls.length, 0);
   });
+  test("decrypt throws error when notEncryptedValue='error'", async (t) => {
+    const envFile = await setupEnv(t, STD_ENV);
+    assertConsole(t, { debug: 0, info: 0, warn: 0, error: 0 });
+
+    await rejects(decrypt({ inFile: envFile, notEncryptedValue: 'error' }), /Environment variable \".+\" is not encrypted\./);
+  });
   test('decrypt does nothing when env is empty', async (t) => {
     const openMock = t.mock.method(BROWSER, 'open');
     const env = '';
This page took 0.035825 seconds and 4 git commands to generate.