Skip to content

Conversation

mishjude
Copy link
Contributor

@mishjude mishjude commented Jun 5, 2025

Description of changes

Address type mismatch false positive for context validation by:
-Creating a new method validate_context to determine whether a context is valid against the provided schema and action
-Calling validate_context in check_parse_context and returned CheckParseAnswer::failure if an error was returned
-Writing a test case to address a faulty context situation and ensuring it passes locally

Issue #, if available

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.)
    (I am like 70% sure the documentation was written under the assumption that the issue I was trying to fix was not an issue (and that context validation worked as intended), so I don't think the documentation needs to be updated, but I'm also not 100% sure)

@mishjude mishjude force-pushed the context_validation branch from 3f8386e to c855834 Compare June 5, 2025 19:54
@mishjude mishjude force-pushed the context_validation branch from c855834 to f13bd28 Compare June 5, 2025 20:05
@john-h-kastner-aws john-h-kastner-aws self-requested a review June 5, 2025 20:16
Copy link

github-actions bot commented Jun 5, 2025

Coverage Report

Head Commit: 4d8ccfd1a7522d5f7208029d2dfd9088dac4e14d

Base Commit: 39700c469730fe354ae6a014d3cd5b92dfeb3d47

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 71.83%

Status: FAILED ❌

Details
File Status Covered Coverage Missed Lines
cedar-policy-core/src/ast/request.rs 🔴 0/8 0.00% 638-645
cedar-policy-core/src/validator/coreschema.rs 🔴 25/36 69.44% 275-277, 345-352
cedar-policy/src/api.rs 🟢 17/18 94.44% 4714
cedar-policy/src/ffi/check_parse.rs 🟢 9/9 100.00%

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 81.90%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-policy 🔴 3248/4680 69.40% 69.25%
cedar-policy-cli 🔴 571/972 58.74% 58.74%
cedar-policy-core 🟢 21040/24779 84.91% 84.96%
cedar-policy-formatter 🟢 1074/1206 89.05% 89.05%
cedar-wasm 🔴 0/29 0.00% 0.00%

Copy link
Contributor

@john-h-kastner-aws john-h-kastner-aws left a comment

Choose a reason for hiding this comment

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

Look pretty good

@cdisselkoen cdisselkoen self-requested a review June 6, 2025 19:08
Copy link
Contributor

@cdisselkoen cdisselkoen left a comment

Choose a reason for hiding this comment

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

Looks good

action: &ast::EntityUID,
extensions: &Extensions<'a>,
) -> std::result::Result<(), RequestValidationError> {
// Following the same logic in validate_request
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment is outdated now that validate_request calls this function

) -> std::result::Result<(), RequestValidationError> {
// Following the same logic in validate_request
// Get the action ID
let action_arc = Arc::new(action.clone());
Copy link
Contributor

Choose a reason for hiding this comment

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

can we avoid cloning the action and constructing an Arc on the happy path? I think the clone and Arc are only needed on error paths

};
use cedar_policy_core::validator::json_schema;
use cedar_policy_core::validator::typecheck::{PolicyCheck, Typechecker};
pub use err::RequestValidationError;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this necessary? I think there is already a pub use err::* below?

}
})?;
let validator_action_id =
self.get_action_id(&Arc::new(action.clone()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this just be let validator_action_id = self.get_action_id(action), or does that not work?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think this should work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

noted! made that change!

Copy link

github-actions bot commented Jun 9, 2025

Coverage Report

Head Commit: 02e2af0c153c81a6319efb4b5c2f08af12340958

Base Commit: 39700c469730fe354ae6a014d3cd5b92dfeb3d47

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 73.13%

Status: FAILED ❌

Details
File Status Covered Coverage Missed Lines
cedar-policy-core/src/ast/request.rs 🔴 0/8 0.00% 638-645
cedar-policy-core/src/validator/coreschema.rs 🟡 26/35 74.29% 261, 329-336
cedar-policy/src/api.rs 🟢 13/13 100.00%
cedar-policy/src/ffi/check_parse.rs 🟢 10/11 90.91% 167

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 81.89%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-policy 🔴 3245/4677 69.38% 69.25%
cedar-policy-cli 🔴 571/972 58.74% 58.74%
cedar-policy-core 🟢 21026/24763 84.91% 84.96%
cedar-policy-formatter 🟢 1074/1206 89.05% 89.05%
cedar-wasm 🔴 0/29 0.00% 0.00%

Copy link

github-actions bot commented Jun 9, 2025

Coverage Report

Head Commit: 62aa6d7d56aca15225ce2a1ded0d4622d9178699

Base Commit: 39700c469730fe354ae6a014d3cd5b92dfeb3d47

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 70.15%

Status: FAILED ❌

Details
File Status Covered Coverage Missed Lines
cedar-policy-core/src/ast/request.rs 🔴 0/8 0.00% 638-645
cedar-policy-core/src/validator/coreschema.rs 🔴 24/35 68.57% 259-261, 329-336
cedar-policy/src/api.rs 🟢 13/13 100.00%
cedar-policy/src/ffi/check_parse.rs 🟢 10/11 90.91% 167

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 81.88%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-policy 🔴 3245/4677 69.38% 69.25%
cedar-policy-cli 🔴 571/972 58.74% 58.74%
cedar-policy-core 🟢 21024/24763 84.90% 84.96%
cedar-policy-formatter 🟢 1074/1206 89.05% 89.05%
cedar-wasm 🔴 0/29 0.00% 0.00%

@john-h-kastner-aws john-h-kastner-aws merged commit 0676afc into cedar-policy:main Jun 9, 2025
19 of 20 checks passed
mishjude added a commit to mishjude/cedar that referenced this pull request Jun 17, 2025
…on (cedar-policy#1651)

Fix sign-off issue

Signed-off-by: Mish Jude <[email protected]>
Co-authored-by: Mish Jude <[email protected]>
Signed-off-by: Mish Jude <[email protected]>
cdisselkoen pushed a commit that referenced this pull request Jun 26, 2025
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.

3 participants