Skip to content

Commit edc5636

Browse files
Aaron Elinejohn-h-kastner-aws
andauthored
new bugfix for 3.2.x (#1110)
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>
1 parent d282618 commit edc5636

File tree

9 files changed

+139
-21
lines changed

9 files changed

+139
-21
lines changed

cedar-policy-cli/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "cedar-policy-cli"
33
edition = "2021"
44
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`
55

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

1414
[dependencies]
15-
cedar-policy = { version = "=3.2.2", path = "../cedar-policy" }
16-
cedar-policy-formatter = { version = "=3.2.2", path = "../cedar-policy-formatter" }
15+
cedar-policy = { version = "=3.2.4", path = "../cedar-policy" }
16+
cedar-policy-formatter = { version = "=3.2.4", path = "../cedar-policy-formatter" }
1717
clap = { version = "4", features = ["derive", "env"] }
1818
serde = { version = "1.0", features = ["derive"] }
1919
serde_json = "1.0"

cedar-policy-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ edition = "2021"
44
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`
55
build = "build.rs"
66

7-
version = "3.2.2"
7+
version = "3.2.4"
88
license = "Apache-2.0"
99
categories = ["compilers", "config"]
1010
description = "Core implemenation of the Cedar Policy language."

cedar-policy-core/src/ast/id.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'a> arbitrary::Arbitrary<'a> for Id {
154154
/// (It still can't contain, for instance, spaces or characters like '+'.)
155155
//
156156
// For now, internally, `AnyId`s are just owned `SmolString`s.
157-
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Hash, PartialOrd, Ord)]
157+
#[derive(Serialize, Debug, PartialEq, Eq, Clone, Hash, PartialOrd, Ord)]
158158
pub struct AnyId(SmolStr);
159159

160160
impl AnyId {
@@ -177,6 +177,35 @@ impl AnyId {
177177
}
178178
}
179179

180+
struct AnyIdVisitor;
181+
182+
impl<'de> serde::de::Visitor<'de> for AnyIdVisitor {
183+
type Value = AnyId;
184+
185+
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
186+
formatter.write_str("any id")
187+
}
188+
189+
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
190+
where
191+
E: serde::de::Error,
192+
{
193+
AnyId::from_normalized_str(value)
194+
.map_err(|err| serde::de::Error::custom(format!("invalid id `{value}`: {err}")))
195+
}
196+
}
197+
198+
/// Deserialize an `AnyId` using `from_normalized_str`.
199+
/// This deserialization implementation is used in the JSON policy format.
200+
impl<'de> Deserialize<'de> for AnyId {
201+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
202+
where
203+
D: Deserializer<'de>,
204+
{
205+
deserializer.deserialize_str(AnyIdVisitor)
206+
}
207+
}
208+
180209
impl AsRef<str> for AnyId {
181210
fn as_ref(&self) -> &str {
182211
&self.0

cedar-policy-core/src/est.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,3 +3679,92 @@ mod test {
36793679
}
36803680
}
36813681
}
3682+
3683+
#[cfg(test)]
3684+
mod issue_994 {
3685+
use crate::{
3686+
entities::JsonDeserializationError,
3687+
est,
3688+
test_utils::{expect_err, ExpectedErrorMessageBuilder},
3689+
};
3690+
use cool_asserts::assert_matches;
3691+
use serde_json::json;
3692+
3693+
#[test]
3694+
fn empty_annotation() {
3695+
let src = json!(
3696+
{
3697+
"annotations": {"": ""},
3698+
"effect": "permit",
3699+
"principal": { "op": "All" },
3700+
"action": { "op": "All" },
3701+
"resource": { "op": "All" },
3702+
"conditions": []
3703+
}
3704+
);
3705+
assert_matches!(
3706+
serde_json::from_value::<est::Policy>(src.clone())
3707+
.map_err(|e| JsonDeserializationError::Serde(e.into())),
3708+
Err(e) => {
3709+
expect_err(
3710+
&src,
3711+
&miette::Report::new(e),
3712+
&ExpectedErrorMessageBuilder::error(r#"invalid id ``: unexpected end of input"#)
3713+
.build()
3714+
);
3715+
}
3716+
);
3717+
}
3718+
3719+
#[test]
3720+
fn annotation_with_space() {
3721+
let src = json!(
3722+
{
3723+
"annotations": {"has a space": ""},
3724+
"effect": "permit",
3725+
"principal": { "op": "All" },
3726+
"action": { "op": "All" },
3727+
"resource": { "op": "All" },
3728+
"conditions": []
3729+
}
3730+
);
3731+
assert_matches!(
3732+
serde_json::from_value::<est::Policy>(src.clone())
3733+
.map_err(|e| JsonDeserializationError::Serde(e.into())),
3734+
Err(e) => {
3735+
expect_err(
3736+
&src,
3737+
&miette::Report::new(e),
3738+
&ExpectedErrorMessageBuilder::error(r#"invalid id `has a space`: unexpected token `a`"#)
3739+
.build()
3740+
);
3741+
}
3742+
);
3743+
}
3744+
3745+
#[test]
3746+
fn special_char() {
3747+
let src = json!(
3748+
{
3749+
"annotations": {"@": ""},
3750+
"effect": "permit",
3751+
"principal": { "op": "All" },
3752+
"action": { "op": "All" },
3753+
"resource": { "op": "All" },
3754+
"conditions": []
3755+
}
3756+
);
3757+
assert_matches!(
3758+
serde_json::from_value::<est::Policy>(src.clone())
3759+
.map_err(|e| JsonDeserializationError::Serde(e.into())),
3760+
Err(e) => {
3761+
expect_err(
3762+
&src,
3763+
&miette::Report::new(e),
3764+
&ExpectedErrorMessageBuilder::error(r#"invalid id `@`: unexpected token `@`"#)
3765+
.build()
3766+
);
3767+
}
3768+
);
3769+
}
3770+
}

cedar-policy-formatter/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cedar-policy-formatter"
3-
version = "3.2.2"
3+
version = "3.2.4"
44
edition = "2021"
55
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`
66
license = "Apache-2.0"
@@ -11,7 +11,7 @@ homepage = "https://cedarpolicy.com"
1111
repository = "https://github.com/cedar-policy/cedar"
1212

1313
[dependencies]
14-
cedar-policy-core = { version = "=3.2.2", path = "../cedar-policy-core" }
14+
cedar-policy-core = { version = "=3.2.4", path = "../cedar-policy-core" }
1515
pretty = "0.12.1"
1616
logos = "0.14.0"
1717
itertools = "0.12"

cedar-policy-validator/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "cedar-policy-validator"
33
edition = "2021"
44
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`
55

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

1414
[dependencies]
15-
cedar-policy-core = { version = "=3.2.2", path = "../cedar-policy-core" }
15+
cedar-policy-core = { version = "=3.2.4", path = "../cedar-policy-core" }
1616
serde = { version = "1.0", features = ["derive"] }
1717
serde_json = { version = "1.0", features = ["preserve_order"] }
1818
serde_with = "3.0"
@@ -49,7 +49,7 @@ wasm = ["serde-wasm-bindgen", "tsify", "wasm-bindgen"]
4949

5050
[dev-dependencies]
5151
cool_asserts = "2.0"
52-
cedar-policy-core = { version = "=3.2.2", path = "../cedar-policy-core", features = [
52+
cedar-policy-core = { version = "=3.2.4", path = "../cedar-policy-core", features = [
5353
"test-util",
5454
] }
5555

cedar-policy/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "cedar-policy"
33
edition = "2021"
44
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`
55

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

1414
[dependencies]
15-
cedar-policy-core = { version = "=3.2.2", path = "../cedar-policy-core" }
16-
cedar-policy-validator = { version = "=3.2.2", path = "../cedar-policy-validator" }
15+
cedar-policy-core = { version = "=3.2.4", path = "../cedar-policy-core" }
16+
cedar-policy-validator = { version = "=3.2.4", path = "../cedar-policy-validator" }
1717
ref-cast = "1.0"
1818
serde = { version = "1.0", features = ["derive", "rc"] }
1919
serde_json = "1.0"

cedar-testing/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ license = "Apache-2.0"
77
publish = false
88

99
[dependencies]
10-
cedar-policy = { version = "=3.2.2", path = "../cedar-policy" }
11-
cedar-policy-core = { version = "=3.2.2", path = "../cedar-policy-core" }
12-
cedar-policy-validator = { version = "=3.2.2", path = "../cedar-policy-validator" }
10+
cedar-policy = { version = "=3.2.4", path = "../cedar-policy" }
11+
cedar-policy-core = { version = "=3.2.4", path = "../cedar-policy-core" }
12+
cedar-policy-validator = { version = "=3.2.4", path = "../cedar-policy-validator" }
1313
serde = { version = "1.0", features = ["derive"] }
1414
serde_json = "1.0"
1515
smol_str = { version = "0.2", features = ["serde"] }

cedar-wasm/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cedar-wasm"
3-
version = "3.2.2"
3+
version = "3.2.4"
44
edition = "2021"
55
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`
66
description = "Wasm bindings and typescript types for Cedar lib"
@@ -9,14 +9,14 @@ license = "Apache-2.0"
99
exclude = ['/build']
1010

1111
[dependencies]
12-
cedar-policy = { version = "=3.2.2", path = "../cedar-policy", features = [
12+
cedar-policy = { version = "=3.2.4", path = "../cedar-policy", features = [
1313
"wasm",
1414
] }
15-
cedar-policy-core = { version = "=3.2.2", path = "../cedar-policy-core", features = [
15+
cedar-policy-core = { version = "=3.2.4", path = "../cedar-policy-core", features = [
1616
"wasm",
1717
] }
18-
cedar-policy-formatter = { version = "=3.2.2", path = "../cedar-policy-formatter" }
19-
cedar-policy-validator = { version = "=3.2.2", path = "../cedar-policy-validator", features = [
18+
cedar-policy-formatter = { version = "=3.2.4", path = "../cedar-policy-formatter" }
19+
cedar-policy-validator = { version = "=3.2.4", path = "../cedar-policy-validator", features = [
2020
"wasm",
2121
] }
2222

0 commit comments

Comments
 (0)