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

update for cedar#360 #141

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cedar
Submodule cedar updated 1663 files
12 changes: 8 additions & 4 deletions cedar-drt/fuzz/fuzz_targets/abac-type-directed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
use cedar_drt::*;
use cedar_drt_inner::*;
use cedar_policy_core::ast;
use cedar_policy_core::entities::{Entities, TCComputation};
use cedar_policy_core::entities::{Entities, NoEntitiesSchema, TCComputation};
use cedar_policy_core::extensions::Extensions;
use cedar_policy_generators::{
abac::{ABACPolicy, ABACRequest},
err::Error,
Expand Down Expand Up @@ -119,10 +120,13 @@ fn drop_some_entities(entities: Entities, u: &mut Unstructured<'_>) -> arbitrary
}
}
}
Ok(
Entities::from_entities(set.into_iter(), TCComputation::AssumeAlreadyComputed)
.expect("Should be valid"),
Ok(Entities::from_entities(
set.into_iter(),
None::<&NoEntitiesSchema>,
TCComputation::AssumeAlreadyComputed,
Extensions::all_available(),
)
.expect("Should be valid"))
} else {
Ok(entities)
}
Expand Down
12 changes: 8 additions & 4 deletions cedar-drt/fuzz/fuzz_targets/eval-type-directed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use cedar_drt::*;
use cedar_drt_inner::*;
use cedar_policy_core::{
ast::Expr,
entities::{Entities, TCComputation},
entities::{Entities, NoEntitiesSchema, TCComputation},
extensions::Extensions,
};
use cedar_policy_generators::abac::ABACRequest;
use cedar_policy_generators::err::Error;
Expand Down Expand Up @@ -115,10 +116,13 @@ fn drop_some_entities(entities: Entities, u: &mut Unstructured<'_>) -> arbitrary
}
}
}
Ok(
Entities::from_entities(set.into_iter(), TCComputation::AssumeAlreadyComputed)
.expect("Should be valid"),
Ok(Entities::from_entities(
set.into_iter(),
None::<&NoEntitiesSchema>,
TCComputation::AssumeAlreadyComputed,
Extensions::all_available(),
)
.expect("Should be valid"))
} else {
Ok(entities)
}
Expand Down
12 changes: 8 additions & 4 deletions cedar-drt/fuzz/fuzz_targets/partial-eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use cedar_policy_core::ast;
use cedar_policy_core::ast::Policy;
use cedar_policy_core::ast::PolicySet;
use cedar_policy_core::authorizer::Authorizer;
use cedar_policy_core::entities::{Entities, TCComputation};
use cedar_policy_core::entities::{Entities, NoEntitiesSchema, TCComputation};
use cedar_policy_core::extensions::Extensions;
use cedar_policy_generators::{
abac::{ABACPolicy, ABACRequest},
err::Error,
Expand Down Expand Up @@ -120,10 +121,13 @@ fn drop_some_entities(entities: Entities, u: &mut Unstructured<'_>) -> arbitrary
}
}
}
Ok(
Entities::from_entities(set.into_iter(), TCComputation::AssumeAlreadyComputed)
.expect("Should be valid"),
Ok(Entities::from_entities(
set.into_iter(),
None::<&NoEntitiesSchema>,
TCComputation::AssumeAlreadyComputed,
Extensions::all_available(),
)
.expect("Should be valid"))
} else {
Ok(entities)
}
Expand Down
4 changes: 3 additions & 1 deletion cedar-drt/fuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub fn run_val_test(
fn test_run_auth_test() {
use cedar_drt::JavaDefinitionalEngine;
use cedar_policy_core::ast::{Entity, EntityUID, RestrictedExpr};
use cedar_policy_core::entities::TCComputation;
use cedar_policy_core::entities::{NoEntitiesSchema, TCComputation};
use smol_str::SmolStr;

let java_def_engine =
Expand Down Expand Up @@ -241,7 +241,9 @@ fn test_run_auth_test() {
);
let entities = Entities::from_entities(
vec![entity_alice, entity_view, entity_vacation],
None::<&NoEntitiesSchema>,
TCComputation::AssumeAlreadyComputed,
Extensions::all_available(),
)
.unwrap();
run_auth_test(&java_def_engine, &query, &policies, &entities);
Expand Down
12 changes: 9 additions & 3 deletions cedar-policy-generators/src/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::schema::{attrs_from_attrs_or_context, build_qualified_entity_type_nam
use crate::size_hint_utils::{size_hint_for_choose, size_hint_for_ratio};
use arbitrary::{Arbitrary, Unstructured};
use cedar_policy_core::ast::{self, Eid, Entity, EntityUID};
use cedar_policy_core::entities::{Entities, TCComputation};
use cedar_policy_core::entities::{Entities, NoEntitiesSchema, TCComputation};
use cedar_policy_core::extensions::Extensions;
use nanoid::nanoid;

/// EntityUIDs with the mappings to their indices in the container.
Expand Down Expand Up @@ -223,8 +224,13 @@ impl Hierarchy {
impl TryFrom<Hierarchy> for Entities {
type Error = String;
fn try_from(h: Hierarchy) -> std::result::Result<Entities, String> {
Entities::from_entities(h.into_entities().map(Into::into), TCComputation::ComputeNow)
.map_err(|e| e.to_string())
Entities::from_entities(
h.into_entities().map(Into::into),
None::<&NoEntitiesSchema>,
TCComputation::ComputeNow,
Extensions::all_available(),
)
.map_err(|e| e.to_string())
}
}

Expand Down
15 changes: 13 additions & 2 deletions cedar-policy-generators/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ use std::{fs::File, io};
use anyhow::{anyhow, Result};
use arbitrary::Unstructured;
use cedar_policy_core::entities::{Entities, TCComputation};
use cedar_policy_core::extensions::Extensions;
use cedar_policy_generators::{
hierarchy::{EntityUIDGenMode, HierarchyGenerator, HierarchyGeneratorMode, NumEntities},
schema::Schema,
settings::ABACSettings,
};
use cedar_policy_validator::SchemaFragment;
use cedar_policy_validator::{CoreSchema, SchemaFragment, ValidatorSchema};
use clap::{Args, Parser, Subcommand};
use rand::{thread_rng, Rng};

Expand Down Expand Up @@ -85,15 +86,25 @@ fn generate_hierarchy_from_schema(byte_length: usize, args: &HierarchyArgs) -> R
}
.generate()
.map_err(|err| anyhow!("failed to generate hierarchy: {err:#?}"))?;
let vschema = ValidatorSchema::try_from(schema)
.map_err(|err| anyhow!("failed to convert schema to ValidatorSchema: {err}"))?;
let coreschema = CoreSchema::new(&vschema);
// this is just to ensure no cycles.
// we throw away the `Entities` built with `ComputeNow`, because we want to
// generate hierarchies that aren't necessarily TC-closed.
Entities::from_entities(h.entities().cloned(), TCComputation::ComputeNow)?;
Entities::from_entities(
h.entities().cloned(),
Some(&coreschema),
TCComputation::ComputeNow,
Extensions::all_available(),
)?;
Ok(Entities::from_entities(
h.entities().cloned(),
Some(&coreschema),
// use `AssumeAlreadyComputed` because we want a hierarchy that isn't
// necessarily TC-closed.
TCComputation::AssumeAlreadyComputed,
Extensions::all_available(),
)?)
}

Expand Down
8 changes: 7 additions & 1 deletion cedar-policy-generators/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,8 @@ mod tests {
use crate::{hierarchy::EntityUIDGenMode, settings::ABACSettings};
use arbitrary::Unstructured;
use cedar_policy_core::entities::Entities;
use cedar_policy_validator::SchemaFragment;
use cedar_policy_core::extensions::Extensions;
use cedar_policy_validator::{CoreSchema, SchemaFragment, ValidatorSchema};
use rand::{rngs::ThreadRng, thread_rng, RngCore};

const RANDOM_BYTE_SIZE: u16 = 1024;
Expand Down Expand Up @@ -1736,9 +1737,14 @@ mod tests {
let h = schema
.arbitrary_hierarchy_with_nanoid_uids(EntityUIDGenMode::default_nanoid_len(), &mut u)
.expect("failed to generate hierarchy!");
let vschema =
ValidatorSchema::try_from(schema).expect("failed to convert to ValidatorSchema");
let coreschema = CoreSchema::new(&vschema);
Entities::from_entities(
h.entities().into_iter().map(|e| e.clone()),
Some(&coreschema),
cedar_policy_core::entities::TCComputation::ComputeNow,
Extensions::all_available(),
)
}
}