Skip to content

Commit 11081b0

Browse files
authored
redact for all lines, add e2e test (#1912)
1 parent 63fe227 commit 11081b0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/cli-repl/src/mongosh-repl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ class MongoshNodeRepl implements EvaluationListener {
451451
// repl.history is an array of previous commands. We need to hijack the
452452
// value we just typed, and shift it off the history array if the info is
453453
// sensitive.
454-
repl.on('flushHistory', () => {
454+
repl.on('line', () => {
455455
if (this.redactHistory !== 'keep') {
456456
const history: string[] = (repl as any).history;
457457
changeHistory(

packages/e2e-tests/test/e2e.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,19 @@ describe('e2e', function () {
14861486

14871487
expect((await fs.stat(historyPath)).mode & 0o077).to.equal(0);
14881488
});
1489+
1490+
it('redacts secrets', async function () {
1491+
await shell.executeLine('db.auth("myusername", "mypassword")');
1492+
await shell.executeLine('a = 42');
1493+
await shell.executeLine('foo = "bar"');
1494+
shell.writeInput('.exit\n');
1495+
await shell.waitForExit();
1496+
1497+
const contents = await fs.readFile(historyPath, 'utf8');
1498+
expect(contents).to.not.match(/mypassword/);
1499+
expect(contents).to.match(/^a = 42$/m);
1500+
expect(contents).to.match(/^foo = "bar"$/m);
1501+
});
14891502
});
14901503

14911504
describe('mongoshrc', function () {

0 commit comments

Comments
 (0)