From: Ardis Lu Date: Sat, 15 Aug 2026 06:15:02 +0000 (-0700) Subject: Add tests for nonstandard encrypt or decrypt behavior X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=2c551a84774f749120ebe0ec5839fc2d6262b50a;p=envpass Add tests for nonstandard encrypt or decrypt behavior --- diff --git a/test/index.test.js b/test/index.test.js index fa89fa8..3105c79 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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 = '';