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

Fixes convert-schema-json-to-cedar #458

Merged
merged 3 commits into from
Oct 23, 2024
Merged
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
50 changes: 30 additions & 20 deletions cedar-drt/fuzz/fuzz_targets/convert-schema-json-to-cedar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,37 @@ fuzz_target!(|src: String| {
if TryInto::<ValidatorSchema>::try_into(parsed.clone()).is_err() {
return;
}
let cedar_src = parsed
.to_cedarschema()
.expect("Failed to convert the JSON schema into a Cedar schema");
let (cedar_parsed, _) = json_schema::Fragment::<RawName>::from_cedarschema_str(
&cedar_src,
Extensions::all_available(),
)
.expect("Failed to parse converted Cedar schema");
if let Err(msg) = equivalence_check(&parsed, &cedar_parsed) {
println!("Original JSON schema: {src}");
println!("Converted to Cedar format:\n{cedar_src}");
println!(
"{}",
SimpleDiff::from_str(
&format!("{:#?}", parsed),
&format!("{:#?}", cedar_parsed),
"Parsed JSON",
"Cedar Round tripped"

match parsed.to_cedarschema() {
Ok(cedar_src) => {
let (cedar_parsed, _) = json_schema::Fragment::<RawName>::from_cedarschema_str(
&cedar_src,
Extensions::all_available(),
)
);
panic!("{msg}");
.expect("Failed to parse converted Cedar schema");
if let Err(msg) = equivalence_check(&parsed, &cedar_parsed) {
println!("Original JSON schema: {src}");
println!("Converted to Cedar format:\n{cedar_src}");
println!(
"{}",
SimpleDiff::from_str(
&format!("{:#?}", parsed),
&format!("{:#?}", cedar_parsed),
"Parsed JSON",
"Cedar Round tripped"
)
);
panic!("{msg}");
}
}
Err(
cedar_policy_validator::cedar_schema::fmt::ToCedarSchemaSyntaxError::NameCollisions(
_,
),
) => {
// Currently, we ignore name-collisions errors, as JSON schemas encountering name-collisions errors are not supported for conversion to Cedar format; see cedar#1272
return;
}
}
}
});