Skip to content

Commit

Permalink
Assert error message
Browse files Browse the repository at this point in the history
  • Loading branch information
hansott committed Jan 30, 2024
1 parent 9d6c7c8 commit 2eb4355
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion library/src/integrations/MongoDB.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ t.test("we can highjack the MongoDB library", async () => {
{ title: "Title" }
);

await t.rejects(async () => {
const error = await t.rejects(async () => {
await runWithContext(
{
aikido: new Aikido(new LoggerNoop(), new APIForTesting(), undefined),
Expand All @@ -57,6 +57,12 @@ t.test("we can highjack the MongoDB library", async () => {
}
);
});
if (error instanceof Error) {
t.equal(
error.message,
"Blocked NoSQL injection for MongoDB.Collection.find(...), please check body (.title)!"
);
}

await runWithContext(
{
Expand Down
2 changes: 1 addition & 1 deletion library/src/integrations/MongoDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class MongoDB implements Integration {
const result = detectNoSQLInjection(context.request, filter);

if (result.injection) {
const message = `Blocked NoSQL injection for MongoDB.Collection.${operation}(...), please check ${friendlyName(result.source)}!`;
const message = `Blocked NoSQL injection for MongoDB.Collection.${operation}(...), please check ${friendlyName(result.source)} (${result.path})!`;
context.aikido.report({
source: result.source,
kind: "nosql-injection",
Expand Down

0 comments on commit 2eb4355

Please sign in to comment.