Skip to content

Commit b508271

Browse files
committed
test(selectors): pin the placeholder collapse in parameterizeSensitiveString
Covers a value that contains the placeholder, a value that crosses a placeholder already in the string, a value found only inside placeholders, and a plain replace that is stable on a second pass.
1 parent 6cdfbc7 commit b508271

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { test } from 'vitest';
2+
import assert from 'node:assert/strict';
3+
import { parameterizeSensitiveString } from './parameterized-recorded-fill.ts';
4+
5+
test('a value that contains the placeholder collapses the whole string', () => {
6+
assert.equal(
7+
parameterizeSensitiveString(
8+
'could not type "abc[REDACTED]xyz"',
9+
'abc[REDACTED]xyz',
10+
'[REDACTED]',
11+
),
12+
'[REDACTED]',
13+
);
14+
assert.equal(
15+
parameterizeSensitiveString(
16+
'could not type "abc${PASSWORD}xyz"',
17+
'abc${PASSWORD}xyz',
18+
'${PASSWORD}',
19+
),
20+
'${PASSWORD}',
21+
);
22+
});
23+
24+
test('a value that crosses a placeholder already in the string collapses the whole string', () => {
25+
// `D]tail` starts inside the earlier `[REDACTED]` and ends after it, so no segment holds it.
26+
assert.equal(
27+
parameterizeSensitiveString('typed [REDACTED]tail', 'D]tail', '[REDACTED]'),
28+
'[REDACTED]',
29+
);
30+
});
31+
32+
test('a value found only inside placeholders leaves the string as it is', () => {
33+
assert.equal(
34+
parameterizeSensitiveString('value ${DOLLAR} kept', '$', '${DOLLAR}'),
35+
'value ${DOLLAR} kept',
36+
);
37+
assert.equal(
38+
parameterizeSensitiveString('typed ${PASSWORD}', 'PASSWORD', '${PASSWORD}'),
39+
'typed ${PASSWORD}',
40+
);
41+
});
42+
43+
test('an ordinary value is replaced in place and a second pass changes nothing', () => {
44+
const once = parameterizeSensitiveString(
45+
'could not type "s3cret" twice: s3cret',
46+
's3cret',
47+
'[REDACTED]',
48+
);
49+
assert.equal(once, 'could not type "[REDACTED]" twice: [REDACTED]');
50+
assert.equal(parameterizeSensitiveString(once, 's3cret', '[REDACTED]'), once);
51+
});

0 commit comments

Comments
 (0)