summaryrefslogtreecommitdiff
path: root/tst/validate_identifier.test.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2025-12-14 22:39:18 -0800
committerElizabeth Hunt <me@liz.coffee>2025-12-14 22:39:18 -0800
commit666674327f009e9b1013218fc384f193b64c6997 (patch)
treeacebae7b425b469584eb0a5bec396899c2739501 /tst/validate_identifier.test.ts
parent594ce452693a71b501d3aff3f35ef3732c06c341 (diff)
downloadpengueno-666674327f009e9b1013218fc384f193b64c6997.tar.gz
pengueno-666674327f009e9b1013218fc384f193b64c6997.zip
Adds unit tests
Diffstat (limited to 'tst/validate_identifier.test.ts')
-rw-r--r--tst/validate_identifier.test.ts28
1 files changed, 28 insertions, 0 deletions
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']]);
+ });
+});