Skip to content

Fixed #2016 issue - Allow referencing entities JSON files in run-test…#2171

Closed
mihai2500 wants to merge 1 commit intocedar-policy:mainfrom
mihai2500:fix-issue-2016
Closed

Fixed #2016 issue - Allow referencing entities JSON files in run-test…#2171
mihai2500 wants to merge 1 commit intocedar-policy:mainfrom
mihai2500:fix-issue-2016

Conversation

@mihai2500
Copy link
Copy Markdown

…s input

Description of changes

Added support for referencing external entity JSON files in the cedar/cedar-policy-cli/src/lib.rs (run-tests) .
Added support for referencing external entity JSON files in the cedar/cedar-policy-cli/tests/sample.rs (cedar run-tests) command instead of requiring entities to be defined inline in test JSON.
Changes:
Modified CheckedTestCaseSeed to track the test file directory for resolving relative paths;
Updated the deserializer to detect when entities is a string (file path) vs. inline JSON array;
Entity file paths are resolved relative to the test file's directory;
Added test case demonstrating the new functionality;

Issue #, if available

Fixed issue #2016

Checklist for requesting a review

The change in this PR is (choose one, and delete the other options):

  • A bug fix or other functionality change requiring a patch to cedar-policy.

I confirm that this PR (choose one, and delete the other options):

  • Does not update the CHANGELOG because my change does not significantly impact released code.

I confirm that cedar-spec (choose one, and delete the other options):

  • I'm not sure how my change impacts cedar-spec. (Post your PR anyways, and we'll discuss in the comments.)

I confirm that docs.cedarpolicy.com (choose one, and delete the other options):

  • I'm not sure how my change impacts the documentation. (Post your PR anyways, and we'll discuss in the comments.)

Comment on lines +1849 to +1852
let test_file_path = Path::new(&args.tests);
let test_file_dir = test_file_path
.parent()
.unwrap_or_else(|| Path::new("."));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to do something here to protect against possible path traversal. We mainly see this being used as a development tools, but it'd be best to proactively prevent this in case it's called on untrusted input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants