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

Add support for missing operands, invalid method names and invalid variables to 'tolerant-ast' experimental feature #1489

Open
wants to merge 37 commits into
base: main
Choose a base branch
from

Conversation

eidelmanjonathan
Copy link
Contributor

Description of changes

This change expands the 'tolerant-ast' experimental feature to allow for several more error cases to be parsed into partial AST's. This allows us to succeed even if the policy has errors in it.

This change allows us to support the following new cases which will be helpful in creating a better LSP Autocomplete feature in the future:

  1. Missing operands, eg: permit(principal ==, action, resource);
  2. Invalid method names, eg: permit ( principal,action,resource) when { ip(principal.ip).i() };
  3. Invalid variable, eg: permit ( principal,action,resource) when { pri }

Issue #, if available

Checklist for requesting a review

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

  • A breaking change requiring a major version bump to cedar-policy (e.g., changes to the signature of an existing API).
  • A backwards-compatible change requiring a minor version bump to cedar-policy (e.g., addition of a new API).
  • A bug fix or other functionality change requiring a patch to cedar-policy.
  • A change "invisible" to users (e.g., documentation, changes to "internal" crates like cedar-policy-core, cedar-validator, etc.)
  • [ x ] A change (breaking or otherwise) that only impacts unreleased or experimental code.

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

  • [ x ] Updates the "Unreleased" section of the CHANGELOG with a description of my change (required for major/minor version bumps).
  • 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):

  • [x ] Does not require updates because my change does not impact the Cedar formal model or DRT infrastructure.
  • Requires updates, and I have made / will make these updates myself. (Please include in your description a timeline or link to the relevant PR in cedar-spec, and how you have tested that your updates are correct.)
  • Requires updates, but I do not plan to make them in the near future. (Make sure that your changes are hidden behind a feature flag to mark them as experimental.)
  • 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):

  • [ x ] Does not require updates because my change does not impact the Cedar language specification.
  • Requires updates, and I have made / will make these updates myself. (Please include in your description a timeline or link to the relevant PR in cedar-docs. PRs should be targeted at a staging-X.Y branch, not main.)
  • I'm not sure how my change impacts the documentation. (Post your PR anyways, and we'll discuss in the comments.)

@eidelmanjonathan eidelmanjonathan marked this pull request as draft February 24, 2025 19:06
@eidelmanjonathan eidelmanjonathan force-pushed the missing-second-operand branch 6 times, most recently from 712e0ae to 453d268 Compare February 25, 2025 21:22
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Signed-off-by: Jonathan Eidelman <[email protected]>
Copy link

Coverage Report

Head Commit: 508e70823fa69dda671c42663d411ef5741c4e65

Base Commit: 25f7d950cadcfecddaecc2f3ba5af99a0adde0bf

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 86.30%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-policy-core/src/ast/entity.rs 🟢 141/157 89.81% 42, 117-120, 122, 139-143, 427-431
cedar-policy-core/src/ast/policy.rs 🟡 9/12 75.00% 1606, 1664, 1695
cedar-policy-core/src/entities/json/value.rs 🟢 1/1 100.00%
cedar-policy-core/src/est.rs 🟢 11/11 100.00%
cedar-policy-core/src/est/expr.rs 🔴 0/1 0.00% 1143
cedar-policy-core/src/est/scope_constraints.rs 🔴 0/4 0.00% 428, 471, 845, 876
cedar-policy-core/src/parser/cst_to_ast.rs 🟢 201/244 82.38% 336-339, 467-471, 477-481, 486-490, 496-503, 506, 937-940, 942-944, 951, 959-961, 967, 975, 977-978
cedar-policy-core/src/parser/cst_to_ast/to_ref_or_refs.rs 🟢 6/6 100.00%
cedar-policy-core/src/parser/fmt.rs 🟢 17/19 89.47% 65-66
cedar-policy-core/src/parser/text_to_cst.rs 🟢 109/114 95.61% 96-100
cedar-policy-formatter/src/pprint/doc.rs 🟢 31/32 96.88% 191
cedar-policy-validator/src/json_schema.rs 🟢 3/3 100.00%
cedar-policy-validator/src/rbac.rs 🔴 0/2 0.00% 359-360
cedar-policy/src/api.rs 🔴 0/2 0.00% 2832, 3159
cedar-policy/src/proto/policy.rs 🔴 0/5 0.00% 401-405

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 87.05%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-policy 🟢 10129/11695 86.61% 86.66%
cedar-policy-cli 🔴 526/912 57.68% 57.68%
cedar-policy-core 🟢 12374/14930 82.88% 82.72%
cedar-policy-formatter 🟢 914/1043 87.63% 87.63%
cedar-policy-validator 🟢 20375/21876 93.14% 93.15%
cedar-testing 🔴 0/426 0.00% 0.00%
cedar-wasm 🔴 0/29 0.00% 0.00%

@eidelmanjonathan eidelmanjonathan marked this pull request as ready for review February 26, 2025 14:31
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.

1 participant