Skip to content

Commit 5a6e030

Browse files
authored
Prep for 2.4.6 release (#877)
2 parents 54a6c1b + 0674ac1 commit 5a6e030

File tree

8 files changed

+96
-24
lines changed

8 files changed

+96
-24
lines changed

cedar-policy-cli/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Changelog
22

3+
## 2.4.6
4+
35
## 2.4.5
46

57
## 2.4.4

cedar-policy-cli/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "cedar-policy-cli"
33
edition = "2021"
44

5-
version = "2.4.5"
5+
version = "2.4.6"
66
license = "Apache-2.0"
77
categories = ["compilers", "config"]
88
description = "CLI interface for the Cedar Policy language."
@@ -11,8 +11,8 @@ homepage = "https://cedarpolicy.com"
1111
repository = "https://github.com/cedar-policy/cedar"
1212

1313
[dependencies]
14-
cedar-policy = { version = "=2.4.5", path = "../cedar-policy" }
15-
cedar-policy-formatter = { version = "=2.4.5", path = "../cedar-policy-formatter" }
14+
cedar-policy = { version = "=2.4.6", path = "../cedar-policy" }
15+
cedar-policy-formatter = { version = "=2.4.6", path = "../cedar-policy-formatter" }
1616
clap = { version = "4", features = ["derive", "env"] }
1717
serde = { version = "1.0", features = ["derive"] }
1818
serde_json = "1.0"

cedar-policy-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "cedar-policy-core"
33
edition = "2021"
44
build = "build.rs"
55

6-
version = "2.4.5"
6+
version = "2.4.6"
77
license = "Apache-2.0"
88
categories = ["compilers", "config"]
99
description = "Core implemenation of the Cedar Policy language."

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 = "2.4.5"
3+
version = "2.4.6"
44
edition = "2021"
55
license = "Apache-2.0"
66
categories = ["compilers", "config"]
@@ -10,7 +10,7 @@ homepage = "https://cedarpolicy.com"
1010
repository = "https://github.com/cedar-policy/cedar"
1111

1212
[dependencies]
13-
cedar-policy-core = { version = "=2.4.5", path = "../cedar-policy-core" }
13+
cedar-policy-core = { version = "=2.4.6", path = "../cedar-policy-core" }
1414
pretty = "0.12.1"
1515
logos = "0.13.0"
1616
itertools = "0.10"

cedar-policy-formatter/src/pprint/fmt.rs

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17+
use std::collections::BTreeMap;
18+
1719
use miette::{miette, Result, WrapErr};
1820

19-
use cedar_policy_core::ast::{PolicySet, Template};
21+
use cedar_policy_core::ast::PolicySet;
2022
use cedar_policy_core::parser::parse_policyset;
2123
use cedar_policy_core::parser::{err::ParseErrors, text_to_cst::parse_policies};
24+
use smol_str::ToSmolStr;
2225

2326
use crate::token::get_comment;
2427

@@ -40,24 +43,42 @@ fn tree_to_pretty<T: Doc>(t: &T, context: &mut config::Context<'_>) -> Result<St
4043
}
4144

4245
fn soundness_check(ps: &str, ast: &PolicySet) -> Result<()> {
43-
let formatted_ast = parse_policyset(ps).wrap_err("formatter produces invalid policies")?;
46+
let formatted_ast =
47+
parse_policyset(ps).wrap_err(format!("formatter produced an invalid policy set:\n{ps}"))?;
4448
let (formatted_policies, policies) = (
45-
formatted_ast.templates().collect::<Vec<&Template>>(),
46-
ast.templates().collect::<Vec<&Template>>(),
49+
formatted_ast
50+
.policies()
51+
.map(|p| (p.id().to_smolstr(), p))
52+
.collect::<BTreeMap<_, _>>(),
53+
ast.policies()
54+
.map(|p| (p.id().to_smolstr(), p))
55+
.collect::<BTreeMap<_, _>>(),
4756
);
4857

4958
if formatted_policies.len() != policies.len() {
50-
return Err(miette!("missing formatted policies"));
59+
return Err(miette!(
60+
"formatter changed the number of policies from {} to {}",
61+
policies.len(),
62+
formatted_policies.len()
63+
));
5164
}
52-
53-
for (f_p, p) in formatted_policies.into_iter().zip(policies.into_iter()) {
65+
for ((f_p_id, f_p), (p_id, p)) in formatted_policies.into_iter().zip(policies.into_iter()) {
66+
if f_p_id != p_id {
67+
return Err(miette!(
68+
"formatter changed the policy id from {p_id} to {f_p_id}"
69+
));
70+
}
5471
let (f_anno, anno) = (
5572
f_p.annotations()
5673
.collect::<std::collections::HashMap<_, _>>(),
5774
p.annotations().collect::<std::collections::HashMap<_, _>>(),
5875
);
59-
if !(f_anno == anno
60-
&& f_p.effect() == p.effect()
76+
if f_anno != anno {
77+
return Err(miette!(
78+
"formatter changed the annotations from {anno:?} to {f_anno:?}"
79+
));
80+
}
81+
if !(f_p.effect() == p.effect()
6182
&& f_p.principal_constraint() == p.principal_constraint()
6283
&& f_p.action_constraint() == p.action_constraint()
6384
&& f_p.resource_constraint() == p.resource_constraint()
@@ -66,9 +87,7 @@ fn soundness_check(ps: &str, ast: &PolicySet) -> Result<()> {
6687
.eq_shape(p.non_head_constraints()))
6788
{
6889
return Err(miette!(
69-
"policies differ:\nformatted: {}\ninput: {}",
70-
f_p,
71-
p
90+
"formatter changed the policy structure:\noriginal:\n{p}\nformatted:\n{f_p}"
7291
));
7392
}
7493
}
@@ -123,7 +142,9 @@ pub fn policies_str_to_pretty(ps: &str, config: &Config) -> Result<String> {
123142
}
124143
};
125144
// add soundness check to make sure formatting doesn't alter policy ASTs
126-
soundness_check(&formatted_policies, &ast)?;
145+
soundness_check(&formatted_policies, &ast).wrap_err(
146+
"internal error: please file an issue at <https://github.com/cedar-policy/cedar/issues>",
147+
)?;
127148
Ok(formatted_policies)
128149
}
129150

@@ -166,6 +187,49 @@ mod tests {
166187
);
167188
}
168189

190+
#[test]
191+
fn test_soundness_check() {
192+
let p1 = r#"permit (principal, action, resource)
193+
when { "
194+
195+
a
196+
" };"#;
197+
let p2 = r#"permit (principal, action, resource)
198+
when { "
199+
a
200+
" };"#;
201+
assert!(soundness_check(p2, &parse_policyset(p1).unwrap()).is_err());
202+
203+
let p1 = r#"
204+
permit (principal, action, resource)
205+
when { "a"};
206+
permit (principal, action, resource)
207+
when { "
208+
209+
a
210+
" };"#;
211+
let p2 = r#"
212+
permit (principal, action, resource)
213+
when { "
214+
a
215+
" };
216+
permit (principal, action, resource)
217+
when { "a"};"#;
218+
assert!(soundness_check(p2, &parse_policyset(p1).unwrap()).is_err());
219+
220+
let p1 = r#"
221+
permit (principal, action, resource)
222+
when { "a" };
223+
permit (principal, action, resource)
224+
when { "b" };"#;
225+
let p2 = r#"
226+
permit (principal, action, resource)
227+
when { "a" };
228+
permit (principal, action, resource)
229+
when { "b"};"#;
230+
assert!(soundness_check(p2, &parse_policyset(p1).unwrap()).is_ok());
231+
}
232+
169233
#[test]
170234
fn test_format_files() {
171235
use std::fs::read_to_string;

cedar-policy-validator/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "cedar-policy-validator"
33
edition = "2021"
44

5-
version = "2.4.5"
5+
version = "2.4.6"
66
license = "Apache-2.0"
77
categories = ["compilers", "config"]
88
description = "Validator for the Cedar Policy language."
@@ -11,7 +11,7 @@ homepage = "https://cedarpolicy.com"
1111
repository = "https://github.com/cedar-policy/cedar"
1212

1313
[dependencies]
14-
cedar-policy-core = { version = "=2.4.5", path = "../cedar-policy-core" }
14+
cedar-policy-core = { version = "=2.4.6", path = "../cedar-policy-core" }
1515
serde = { version = "=1.0.193", features = ["derive"] }
1616
serde_json = { version = "=1.0.108", features = ["preserve_order"] }
1717
serde_with = "=3.4.0"

cedar-policy/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 2.4.6
4+
5+
### Fixed
6+
7+
- The formatter will now fail with an error if it changes a policy's semantics.
8+
39
## 2.4.5
410

511
### Changed

cedar-policy/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "cedar-policy"
33
edition = "2021"
44

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

1313
[dependencies]
14-
cedar-policy-core = { version = "=2.4.5", path = "../cedar-policy-core" }
15-
cedar-policy-validator = { version = "=2.4.5", path = "../cedar-policy-validator" }
14+
cedar-policy-core = { version = "=2.4.6", path = "../cedar-policy-core" }
15+
cedar-policy-validator = { version = "=2.4.6", path = "../cedar-policy-validator" }
1616
ref-cast = "1.0"
1717
serde = { version = "1.0", features = ["derive", "rc"] }
1818
serde_json = "1.0"

0 commit comments

Comments
 (0)