Skip to content

Commit

Permalink
revert cedar testing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
oflatt committed Aug 28, 2024
1 parent 127cae9 commit ea27913
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 40 deletions.
1 change: 0 additions & 1 deletion cedar-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ default = ["ipaddr", "decimal"]
decimal = ["cedar-policy/decimal"]
ipaddr = ["cedar-policy/ipaddr"]
integration-testing = []
entity-manifest = ["cedar-policy/entity-manifest"]

[dev-dependencies]
assert_cmd = "2.0"
Expand Down
38 changes: 0 additions & 38 deletions cedar-testing/src/cedar_test_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ use cedar_policy_core::authorizer::Authorizer;
use cedar_policy_core::entities::{Entities, TCComputation};
use cedar_policy_core::evaluator::Evaluator;
use cedar_policy_core::extensions::Extensions;
#[cfg(feature = "entity-manifest")]
use cedar_policy_validator::entity_manifest::compute_entity_manifest;
use cedar_policy_validator::{ValidationMode, Validator, ValidatorSchema};
use core::panic;
use miette::miette;
Expand Down Expand Up @@ -160,7 +158,6 @@ pub trait CedarTestImplementation {
/// Custom authorizer entry point.
fn is_authorized(
&self,
schema: &ValidatorSchema,
request: &Request,
policies: &PolicySet,
entities: &Entities,
Expand Down Expand Up @@ -285,7 +282,6 @@ where
impl CedarTestImplementation for RustEngine {
fn is_authorized(
&self,
schema: &ValidatorSchema,
request: &Request,
policies: &PolicySet,
entities: &Entities,
Expand Down Expand Up @@ -317,40 +313,6 @@ impl CedarTestImplementation for RustEngine {
response,
timing_info: HashMap::from([("authorize".into(), Micros(duration.as_micros()))]),
};

// now check that we get the same response with entity manifest, as long as the schema is valid
#[cfg(feature = "entity-manifest")]
{
let validator = Validator::new(schema.clone());
let validation_result = validator.validate(policies, ValidationMode::Strict);
if validation_result.validation_passed() {
let entity_manifest = match compute_entity_manifest(schema, policies) {
Ok(entity_manifest) => entity_manifest,
Err(err) => {
return TestResult::Failure(format!(
"Failed to compute entity manifest. Error: {}",
err
));
}
};
let entity_slice = match entity_manifest.slice_entities(entities, request) {
Ok(slice) => slice,
Err(err) => {
return TestResult::Failure(format!(
"Failed to slice entities. Error: {}",
err
));
}
};

let slice_response =
authorizer.is_authorized(request.clone(), policies, &entity_slice);
if response.response.decision() != slice_response.decision {
return TestResult::Failure(format!("Response decision differed with and without entity slicing. \nWithout: {:?}\nWith: {:?}\n", response.response.decision(), slice_response.decision));
}
}
}

TestResult::Success(response)
}

Expand Down
2 changes: 1 addition & 1 deletion cedar-testing/src/integration_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ pub fn perform_integration_test(
for json_request in requests {
let request = parse_request_from_test(&json_request, &schema, test_name);
let response = test_impl
.is_authorized(&schema, &request, &policies, &entities)
.is_authorized(&request, &policies, &entities)
.expect("Authorization failed");
// check decision
assert_eq!(
Expand Down

0 comments on commit ea27913

Please sign in to comment.