Skip to content

Commit 6ea96b4

Browse files
committed
chore: cleanup
1 parent 7e75778 commit 6ea96b4

File tree

2 files changed

+24
-47
lines changed

2 files changed

+24
-47
lines changed

packages/mongodb-redact/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function redact<T>(
4646
return message;
4747
}
4848

49+
export { shouldRedactCommand } from './should-redact-command';
4950
export { redactUriCredentials } from './redact-uri-credentials';
5051

5152
export default redact;

packages/mongodb-redact/src/should-redact-command.spec.ts

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,27 @@ import { expect } from 'chai';
22
import { shouldRedactCommand } from '.';
33

44
describe('shouldRedactCommand', function () {
5-
describe('shouldRedactCommand', function () {
6-
it('returns true for createUser commands', function () {
7-
expect(shouldRedactCommand('db.createUser({ user: "test" })')).to.be.true;
8-
});
9-
10-
it('returns true for auth commands', function () {
11-
expect(shouldRedactCommand('db.auth("user", "pass")')).to.be.true;
12-
});
13-
14-
it('returns true for updateUser commands', function () {
15-
expect(shouldRedactCommand('db.updateUser("user", { roles: [] })')).to.be
16-
.true;
17-
});
18-
19-
it('returns true for changeUserPassword commands', function () {
20-
expect(shouldRedactCommand('db.changeUserPassword("user", "newpass")')).to
21-
.be.true;
22-
});
23-
24-
it('returns true for connect commands', function () {
25-
expect(shouldRedactCommand('db = connect("mongodb://localhost")')).to.be
26-
.true;
27-
});
28-
29-
it('returns true for Mongo constructor', function () {
30-
expect(shouldRedactCommand('new Mongo("mongodb://localhost")')).to.be
31-
.true;
32-
});
33-
34-
it('returns false for non-sensitive commands', function () {
35-
expect(shouldRedactCommand('db.collection.find()')).to.be.false;
36-
});
37-
38-
it('returns false for partial words like "authentication"', function () {
39-
// The \b (word boundary) should prevent matching "auth" within "authentication"
40-
expect(shouldRedactCommand('db.collection.find({authentication: true})'))
41-
.to.be.false;
42-
});
43-
44-
it('returns false for getUsers command', function () {
45-
expect(shouldRedactCommand('db.getUsers()')).to.be.false;
46-
});
47-
48-
it('returns false for show commands', function () {
49-
expect(shouldRedactCommand('show dbs')).to.be.false;
50-
});
51-
});
5+
for (const command of [
6+
'db.createUser({ user: "test" })',
7+
'db.auth("user", "pass")',
8+
'db.updateUser("user", { roles: [] })',
9+
'db.changeUserPassword("user", "newpass")',
10+
'db = connect("mongodb://localhost")',
11+
'new Mongo("mongodb://localhost")',
12+
]) {
13+
it(`returns true for ${command}`, function () {
14+
expect(shouldRedactCommand(command)).to.be.true;
15+
});
16+
}
17+
18+
for (const command of [
19+
'db.collection.find()',
20+
'db.collection.find({authentication: true})',
21+
'db.getUsers()',
22+
'show dbs',
23+
]) {
24+
it(`returns false for ${command}`, function () {
25+
expect(shouldRedactCommand(command)).to.be.false;
26+
});
27+
}
5228
});

0 commit comments

Comments
 (0)