Skip to content

Commit

Permalink
update: add tests for eval rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushpahwa committed Nov 21, 2024
1 parent e72081e commit 74951dc
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion app/client/src/plugins/Linting/tests/getLintingErrors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ describe.each(linterTypes)(
});

expect(Array.isArray(lintErrors)).toBe(true);
// Should have no errors
expect(lintErrors.length).toEqual(1);
const lintError = lintErrors[0];

Expand Down Expand Up @@ -471,6 +470,33 @@ describe.each(linterTypes)(
// Should have no errors for assignments in conditions
expect(lintErrors.length).toEqual(0);
});

// Test for 'evil: false' (Disallow use of eval)
it("11. Should error when 'eval' is used", () => {
const data = {};
const originalBinding = "{{ eval('var a = 1;') }}";
const script = "eval('var a = 1;');";

const scriptType = getScriptType(false, true);

const lintErrors = getLintingErrors({
getLinterTypeFn: () => linterType,
data,
originalBinding,
script,
scriptType,
webworkerTelemetry,
});

expect(Array.isArray(lintErrors)).toBe(true);
expect(lintErrors.length).toEqual(1);
const lintError = lintErrors[0];

const expectedMessage = "eval can be harmful.";

expect(lintError.severity).toBe(Severity.ERROR);
expect(lintError.errorMessage.message).toBe(expectedMessage);
});
});
},
);

0 comments on commit 74951dc

Please sign in to comment.