Skip to content

Commit

Permalink
new bugfix for 3.2.x (#1110)
Browse files Browse the repository at this point in the history
Signed-off-by: John Kastner <jkastner@amazon.com>
Signed-off-by: Aaron Eline <aeline+github@amazon.com>
Co-authored-by: John Kastner <130772734+john-h-kastner-aws@users.noreply.github.com>
  • Loading branch information
aaronjeline and john-h-kastner-aws authored Aug 5, 2024
1 parent d282618 commit edc5636
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 21 deletions.
6 changes: 3 additions & 3 deletions cedar-policy-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "cedar-policy-cli"
edition = "2021"
rust-version = "1.76.0" # minimum supported Rust version is currently 1.76.0 because `cedar-policy-core` requirement. Check with `cargo install cargo-msrv && cargo msrv --min 1.75.0`

version = "3.2.2"
version = "3.2.4"
license = "Apache-2.0"
categories = ["compilers", "config"]
description = "CLI interface for the Cedar Policy language."
Expand All @@ -12,8 +12,8 @@ homepage = "https://cedarpolicy.com"
repository = "https://github.com/cedar-policy/cedar"

[dependencies]
cedar-policy = { version = "=3.2.2", path = "../cedar-policy" }
cedar-policy-formatter = { version = "=3.2.2", path = "../cedar-policy-formatter" }
cedar-policy = { version = "=3.2.4", path = "../cedar-policy" }
cedar-policy-formatter = { version = "=3.2.4", path = "../cedar-policy-formatter" }
clap = { version = "4", features = ["derive", "env"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion cedar-policy-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ edition = "2021"
rust-version = "1.76.0" # minimum supported Rust version is currently 1.76.0 because of use of `Arc::unwrap_or_clone()`. Check with `cargo install cargo-msrv && cargo msrv --min 1.75.0`
build = "build.rs"

version = "3.2.2"
version = "3.2.4"
license = "Apache-2.0"
categories = ["compilers", "config"]
description = "Core implemenation of the Cedar Policy language."
Expand Down
31 changes: 30 additions & 1 deletion cedar-policy-core/src/ast/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl<'a> arbitrary::Arbitrary<'a> for Id {
/// (It still can't contain, for instance, spaces or characters like '+'.)
//
// For now, internally, `AnyId`s are just owned `SmolString`s.
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Hash, PartialOrd, Ord)]
#[derive(Serialize, Debug, PartialEq, Eq, Clone, Hash, PartialOrd, Ord)]
pub struct AnyId(SmolStr);

impl AnyId {
Expand All @@ -177,6 +177,35 @@ impl AnyId {
}
}

struct AnyIdVisitor;

impl<'de> serde::de::Visitor<'de> for AnyIdVisitor {
type Value = AnyId;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str("any id")
}

fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
AnyId::from_normalized_str(value)
.map_err(|err| serde::de::Error::custom(format!("invalid id `{value}`: {err}")))
}
}

/// Deserialize an `AnyId` using `from_normalized_str`.
/// This deserialization implementation is used in the JSON policy format.
impl<'de> Deserialize<'de> for AnyId {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
deserializer.deserialize_str(AnyIdVisitor)
}
}

impl AsRef<str> for AnyId {
fn as_ref(&self) -> &str {
&self.0
Expand Down
89 changes: 89 additions & 0 deletions cedar-policy-core/src/est.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3679,3 +3679,92 @@ mod test {
}
}
}

#[cfg(test)]
mod issue_994 {
use crate::{
entities::JsonDeserializationError,
est,
test_utils::{expect_err, ExpectedErrorMessageBuilder},
};
use cool_asserts::assert_matches;
use serde_json::json;

#[test]
fn empty_annotation() {
let src = json!(
{
"annotations": {"": ""},
"effect": "permit",
"principal": { "op": "All" },
"action": { "op": "All" },
"resource": { "op": "All" },
"conditions": []
}
);
assert_matches!(
serde_json::from_value::<est::Policy>(src.clone())
.map_err(|e| JsonDeserializationError::Serde(e.into())),
Err(e) => {
expect_err(
&src,
&miette::Report::new(e),
&ExpectedErrorMessageBuilder::error(r#"invalid id ``: unexpected end of input"#)
.build()
);
}
);
}

#[test]
fn annotation_with_space() {
let src = json!(
{
"annotations": {"has a space": ""},
"effect": "permit",
"principal": { "op": "All" },
"action": { "op": "All" },
"resource": { "op": "All" },
"conditions": []
}
);
assert_matches!(
serde_json::from_value::<est::Policy>(src.clone())
.map_err(|e| JsonDeserializationError::Serde(e.into())),
Err(e) => {
expect_err(
&src,
&miette::Report::new(e),
&ExpectedErrorMessageBuilder::error(r#"invalid id `has a space`: unexpected token `a`"#)
.build()
);
}
);
}

#[test]
fn special_char() {
let src = json!(
{
"annotations": {"@": ""},
"effect": "permit",
"principal": { "op": "All" },
"action": { "op": "All" },
"resource": { "op": "All" },
"conditions": []
}
);
assert_matches!(
serde_json::from_value::<est::Policy>(src.clone())
.map_err(|e| JsonDeserializationError::Serde(e.into())),
Err(e) => {
expect_err(
&src,
&miette::Report::new(e),
&ExpectedErrorMessageBuilder::error(r#"invalid id `@`: unexpected token `@`"#)
.build()
);
}
);
}
}
4 changes: 2 additions & 2 deletions cedar-policy-formatter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cedar-policy-formatter"
version = "3.2.2"
version = "3.2.4"
edition = "2021"
rust-version = "1.76.0" # minimum supported Rust version is currently 1.76.0 because `cedar-policy-core` requirement. Check with `cargo install cargo-msrv && cargo msrv --min 1.75.0`
license = "Apache-2.0"
Expand All @@ -11,7 +11,7 @@ homepage = "https://cedarpolicy.com"
repository = "https://github.com/cedar-policy/cedar"

[dependencies]
cedar-policy-core = { version = "=3.2.2", path = "../cedar-policy-core" }
cedar-policy-core = { version = "=3.2.4", path = "../cedar-policy-core" }
pretty = "0.12.1"
logos = "0.14.0"
itertools = "0.12"
Expand Down
6 changes: 3 additions & 3 deletions cedar-policy-validator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "cedar-policy-validator"
edition = "2021"
rust-version = "1.76.0" # minimum supported Rust version is currently 1.76.0 because `cedar-policy-core` requirement. Check with `cargo install cargo-msrv && cargo msrv --min 1.75.0`

version = "3.2.2"
version = "3.2.4"
license = "Apache-2.0"
categories = ["compilers", "config"]
description = "Validator for the Cedar Policy language."
Expand All @@ -12,7 +12,7 @@ homepage = "https://cedarpolicy.com"
repository = "https://github.com/cedar-policy/cedar"

[dependencies]
cedar-policy-core = { version = "=3.2.2", path = "../cedar-policy-core" }
cedar-policy-core = { version = "=3.2.4", path = "../cedar-policy-core" }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
serde_with = "3.0"
Expand Down Expand Up @@ -49,7 +49,7 @@ wasm = ["serde-wasm-bindgen", "tsify", "wasm-bindgen"]

[dev-dependencies]
cool_asserts = "2.0"
cedar-policy-core = { version = "=3.2.2", path = "../cedar-policy-core", features = [
cedar-policy-core = { version = "=3.2.4", path = "../cedar-policy-core", features = [
"test-util",
] }

Expand Down
6 changes: 3 additions & 3 deletions cedar-policy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "cedar-policy"
edition = "2021"
rust-version = "1.76.0" # minimum supported Rust version is currently 1.76.0 because `cedar-policy-core` requirement. Check with `cargo install cargo-msrv && cargo msrv --min 1.75.0`

version = "3.2.2"
version = "3.2.4"
license = "Apache-2.0"
categories = ["compilers", "config"]
description = "Cedar is a language for defining permissions as policies, which describe who should have access to what."
Expand All @@ -12,8 +12,8 @@ homepage = "https://cedarpolicy.com"
repository = "https://github.com/cedar-policy/cedar"

[dependencies]
cedar-policy-core = { version = "=3.2.2", path = "../cedar-policy-core" }
cedar-policy-validator = { version = "=3.2.2", path = "../cedar-policy-validator" }
cedar-policy-core = { version = "=3.2.4", path = "../cedar-policy-core" }
cedar-policy-validator = { version = "=3.2.4", path = "../cedar-policy-validator" }
ref-cast = "1.0"
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = "1.0"
Expand Down
6 changes: 3 additions & 3 deletions cedar-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ license = "Apache-2.0"
publish = false

[dependencies]
cedar-policy = { version = "=3.2.2", path = "../cedar-policy" }
cedar-policy-core = { version = "=3.2.2", path = "../cedar-policy-core" }
cedar-policy-validator = { version = "=3.2.2", path = "../cedar-policy-validator" }
cedar-policy = { version = "=3.2.4", path = "../cedar-policy" }
cedar-policy-core = { version = "=3.2.4", path = "../cedar-policy-core" }
cedar-policy-validator = { version = "=3.2.4", path = "../cedar-policy-validator" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
smol_str = { version = "0.2", features = ["serde"] }
Expand Down
10 changes: 5 additions & 5 deletions cedar-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cedar-wasm"
version = "3.2.2"
version = "3.2.4"
edition = "2021"
rust-version = "1.76.0" # minimum supported Rust version is currently 1.76.0 because `cedar-policy-core` requirement. Check with `cargo install cargo-msrv && cargo msrv --min 1.75.0`
description = "Wasm bindings and typescript types for Cedar lib"
Expand All @@ -9,14 +9,14 @@ license = "Apache-2.0"
exclude = ['/build']

[dependencies]
cedar-policy = { version = "=3.2.2", path = "../cedar-policy", features = [
cedar-policy = { version = "=3.2.4", path = "../cedar-policy", features = [
"wasm",
] }
cedar-policy-core = { version = "=3.2.2", path = "../cedar-policy-core", features = [
cedar-policy-core = { version = "=3.2.4", path = "../cedar-policy-core", features = [
"wasm",
] }
cedar-policy-formatter = { version = "=3.2.2", path = "../cedar-policy-formatter" }
cedar-policy-validator = { version = "=3.2.2", path = "../cedar-policy-validator", features = [
cedar-policy-formatter = { version = "=3.2.4", path = "../cedar-policy-formatter" }
cedar-policy-validator = { version = "=3.2.4", path = "../cedar-policy-validator", features = [
"wasm",
] }

Expand Down

0 comments on commit edc5636

Please sign in to comment.