Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getPathsToPayload not respecting max matches #479

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add failing tests
hansott committed Dec 18, 2024
commit 17d8b325a48fee8f71894caea7b7d853a48b9483
17 changes: 17 additions & 0 deletions library/helpers/attackPath.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as t from "tap";
import { getPathsToPayload as get } from "./attackPath";

t.test("it throws error if max matches is less than 1", async (t) => {
t.throws(() => get("payload", {}, 0));
t.throws(() => get("payload", {}, -1));
});

t.test("it gets paths to payload", async (t) => {
const testObj1 = {
a: {
@@ -91,3 +96,15 @@ t.test("respects max depth and array length", async (t) => {
t.test("first item in array", async (t) => {
t.same(get("id = 1", ["id = 1"]), [".[0]"]);
});

t.test("it checks max matches when iterating over object props", async (t) => {
const testObj = {
a: ["test"],
b: ["test"],
c: ["test"],
};

t.same(get("test", testObj, 1), [".a.[0]"]);
t.same(get("test", testObj, 2), [".a.[0]", ".b.[0]"]);
t.same(get("test", testObj, 3), [".a.[0]", ".b.[0]", ".c.[0]"]);
});