Skip to content

Commit cc78a52

Browse files
committed
Added more tests for apm
1 parent cf1cdea commit cc78a52

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

lib/apm.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ var basicTimestampGenerator = {
3333
}
3434
}
3535

36+
var senstiveCommands = ['authenticate', 'saslStart', 'saslContinue', 'getnonce',
37+
'createUser', 'updateUser', 'copydbgetnonce', 'copydbsaslstart', 'copydb'];
38+
3639
var Instrumentation = function(core, options, callback) {
3740
options = options || {};
3841

@@ -145,6 +148,12 @@ var Instrumentation = function(core, options, callback) {
145148
connectionId: connection
146149
};
147150

151+
// Filter out any sensitive commands
152+
if(senstiveCommands.indexOf(commandName.toLowerCase())) {
153+
command.commandObj = {};
154+
command.commandObj[commandName] = true;
155+
}
156+
148157
// Emit the started event
149158
self.emit('started', command)
150159

@@ -165,9 +174,21 @@ var Instrumentation = function(core, options, callback) {
165174
// If we have an error
166175
if(err || (r.result.ok == 0)) {
167176
command.failure = err || r.result.writeErrors || r.result;
177+
178+
// Filter out any sensitive commands
179+
if(senstiveCommands.indexOf(commandName.toLowerCase())) {
180+
command.failure = {};
181+
}
182+
168183
self.emit('failed', command);
169184
} else {
170185
command.reply = r;
186+
187+
// Filter out any sensitive commands
188+
if(senstiveCommands.indexOf(commandName.toLowerCase())) {
189+
command.reply = {};
190+
}
191+
171192
self.emit('succeeded', command);
172193
}
173194

test/functional/apm_tests.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,3 +588,51 @@ exports['Correctly receive the APM explain command'] = {
588588
});
589589
}
590590
}
591+
592+
exports['Correctly filter out sensitive commands'] = {
593+
metadata: { requires: { topology: ['single'] } },
594+
595+
// The actual test we wish to run
596+
test: function(configuration, test) {
597+
var ReadPreference = configuration.require.ReadPreference;
598+
var started = [];
599+
var succeeded = [];
600+
var failed = [];
601+
602+
var listener = require('../..').instrument();
603+
listener.on('started', function(event) {
604+
if(event.commandName == 'getnonce')
605+
started.push(event);
606+
});
607+
608+
listener.on('succeeded', function(event) {
609+
if(event.commandName == 'getnonce')
610+
succeeded.push(event);
611+
});
612+
613+
listener.on('failed', function(event) {
614+
if(event.commandName == 'getnonce')
615+
failed.push(event);
616+
});
617+
618+
var db = configuration.newDbInstance({w:1}, {poolSize:1, auto_reconnect:false});
619+
db.open(function(err, db) {
620+
test.equal(null, err);
621+
622+
db.command({getnonce:true}, function(err, r) {
623+
test.equal(null, err);
624+
test.ok(r != null);
625+
test.equal(1, started.length);
626+
test.equal(1, succeeded.length);
627+
test.equal(0, failed.length);
628+
test.deepEqual({getnonce:true}, started[0].commandObj);
629+
test.deepEqual({}, succeeded[0].reply);
630+
631+
// Remove instrumentation
632+
listener.uninstrument();
633+
db.close();
634+
test.done();
635+
});
636+
});
637+
}
638+
}

0 commit comments

Comments
 (0)