From 666674327f009e9b1013218fc384f193b64c6997 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 14 Dec 2025 22:39:18 -0800 Subject: Adds unit tests --- tst/validate_identifier.test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tst/validate_identifier.test.ts (limited to 'tst/validate_identifier.test.ts') diff --git a/tst/validate_identifier.test.ts b/tst/validate_identifier.test.ts new file mode 100644 index 0000000..de5ac5e --- /dev/null +++ b/tst/validate_identifier.test.ts @@ -0,0 +1,28 @@ +import { validateIdentifier, validateExecutionEntries } from '../lib/index'; + +describe('process/validate_identifier', () => { + test('validateIdentifier accepts safe tokens', () => { + expect(validateIdentifier('abcDEF_0123-:.?/&= ')).toBe(true); + expect(validateIdentifier('path/to/file.txt')).toBe(true); + }); + + test('validateIdentifier rejects path traversal', () => { + expect(validateIdentifier('../etc/passwd')).toBe(false); + expect(validateIdentifier('ok..not')).toBe(false); + }); + + test('validateIdentifier rejects unsafe characters', () => { + expect(validateIdentifier('rm -rf /;')).toBe(false); + expect(validateIdentifier('$HOME')).toBe(false); + }); + + test('validateExecutionEntries returns right for safe env entries', () => { + const res = validateExecutionEntries({ FOO: 'bar', HELLO: 'world-123' }); + expect(res.right().get()).toEqual({ FOO: 'bar', HELLO: 'world-123' }); + }); + + test('validateExecutionEntries returns invalid entries', () => { + const res = validateExecutionEntries({ OK: 'good', BAD: '../nope' }); + expect(res.left().get()).toEqual([['BAD', '../nope']]); + }); +}); -- cgit v1.2.3-70-g09d2