From 298fa696e56106ec8f9ebc49a253b256f986c583 Mon Sep 17 00:00:00 2001 From: Craig Disselkoen Date: Tue, 4 Mar 2025 11:54:37 -0800 Subject: [PATCH] remove PE from CedarTestImplementation (#1521) Signed-off-by: Craig Disselkoen --- cedar-testing/src/cedar_test_impl.rs | 88 +--------------------------- 1 file changed, 1 insertion(+), 87 deletions(-) diff --git a/cedar-testing/src/cedar_test_impl.rs b/cedar-testing/src/cedar_test_impl.rs index cde4d116c..98dfb60db 100644 --- a/cedar-testing/src/cedar_test_impl.rs +++ b/cedar-testing/src/cedar_test_impl.rs @@ -20,8 +20,7 @@ //! testing (see ). pub use cedar_policy::ffi; -use cedar_policy_core::ast::{self, PartialValue}; -use cedar_policy_core::ast::{Expr, PolicySet, Request, Value}; +use cedar_policy_core::ast::{self, Expr, PolicySet, Request, Value}; use cedar_policy_core::authorizer::Authorizer; use cedar_policy_core::entities::{Entities, TCComputation}; use cedar_policy_core::evaluator::Evaluator; @@ -31,7 +30,6 @@ use core::panic; use miette::miette; use serde::Deserialize; use std::collections::HashMap; -use std::collections::HashSet; use std::time::{Duration, Instant}; /// Return type for `CedarTestImplementation` methods @@ -97,15 +95,6 @@ pub struct TestValidationResult { pub mod partial { use super::*; - #[derive(Debug, Deserialize, PartialEq, Eq)] - #[serde(rename_all = "camelCase")] - pub struct FlatPartialResponse { - pub known_permits: HashSet, - pub known_forbids: HashSet, - pub determining_under_approx: HashSet, - pub determining_over_approx: HashSet, - pub decision: Decision, - } #[derive(Debug, Deserialize, PartialEq, Eq)] #[serde(rename_all = "camelCase")] @@ -177,26 +166,6 @@ pub trait CedarTestImplementation { expected: Option, ) -> TestResult; - fn partial_is_authorized( - &self, - request: &Request, - entities: &Entities, - policies: &PolicySet, - ) -> TestResult; - - /// Custom partial evaluator entry point. The bool return value indicates the whether - /// evaluating the provided expression produces the expected value. - /// `expected` is optional to allow for the case where no return value is - /// expected due to errors. - fn partial_evaluate( - &self, - request: &Request, - entities: &Entities, - expr: &Expr, - enable_extensions: bool, - expected: Option, - ) -> TestResult; - /// Custom validator entry point. fn validate( &self, @@ -317,61 +286,6 @@ impl CedarTestImplementation for RustEngine { TestResult::Success(response) } - fn partial_is_authorized( - &self, - request: &Request, - entities: &Entities, - policies: &PolicySet, - ) -> TestResult { - let a = Authorizer::new(); - let pr = a.is_authorized_core(request.clone(), policies, entities); - - let r = partial::FlatPartialResponse { - known_permits: pr.satisfied_permits.keys().map(|x| x.to_string()).collect(), - known_forbids: pr.satisfied_forbids.keys().map(|x| x.to_string()).collect(), - decision: partial::Decision::from_core(pr.decision()), - determining_over_approx: pr - .may_be_determining() - .map(|x| x.id().to_string()) - .collect(), - determining_under_approx: pr - .must_be_determining() - .map(|x| x.id().to_string()) - .collect(), - }; - - TestResult::Success(r) - } - - fn partial_evaluate( - &self, - request: &Request, - entities: &Entities, - expr: &Expr, - enable_extensions: bool, - expected: Option, - ) -> TestResult { - let exts = if enable_extensions { - Extensions::all_available() - } else { - Extensions::none() - }; - let e = Evaluator::new(request.clone(), entities, exts); - let result = e.partial_interpret(expr, &HashMap::default()); - match (result, expected) { - (Ok(PartialValue::Residual(r)), Some(ExprOrValue::Expr(e))) => { - TestResult::Success(r == e) - } - (Ok(PartialValue::Value(v)), Some(ExprOrValue::Value(e))) => { - let v_as_e: Expr = v.into(); - TestResult::Success(v_as_e == e) - } - - (Err(_), None) => TestResult::Success(true), - _ => TestResult::Success(false), - } - } - fn interpret( &self, request: &Request,