fix(mongodb): guard aggregate execution paths
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { strict as assert } from "node:assert";
|
||||
import test from "node:test";
|
||||
import {
|
||||
evaluateMongoAggregateSafety,
|
||||
mongoAggregateWriteStage,
|
||||
mongoCountToQueryResult,
|
||||
mongoDocumentsToQueryResult,
|
||||
parseMongoAggregateCommand,
|
||||
@@ -76,6 +78,19 @@ test("parseMongoAggregateCommand normalises ObjectId arguments with either quote
|
||||
}
|
||||
});
|
||||
|
||||
test("evaluateMongoAggregateSafety blocks write stages unless MCP write flags allow them", () => {
|
||||
const out = parseMongoAggregateCommand('db.products.aggregate([{"$out":"products_copy"}])');
|
||||
assert.ok(out);
|
||||
assert.equal(mongoAggregateWriteStage(out.pipeline), "$out");
|
||||
assert.match(evaluateMongoAggregateSafety(out, {}).reason || "", /DBX_MCP_ALLOW_WRITES=1/);
|
||||
|
||||
const merge = parseMongoAggregateCommand('db.products.aggregate([{"$merge":{"into":"products_copy"}}])');
|
||||
assert.ok(merge);
|
||||
assert.equal(mongoAggregateWriteStage(merge.pipeline), "$merge");
|
||||
assert.match(evaluateMongoAggregateSafety(merge, { allowWrites: true }).reason || "", /DBX_MCP_ALLOW_DANGEROUS_SQL=1/);
|
||||
assert.equal(evaluateMongoAggregateSafety(merge, { allowWrites: true, allowDangerous: true }).allowed, true);
|
||||
});
|
||||
|
||||
test("mongoCountToQueryResult returns a single count row", () => {
|
||||
assert.deepEqual(mongoCountToQueryResult(42, 5), {
|
||||
columns: ["count"],
|
||||
|
||||
Reference in New Issue
Block a user