Skip to content

Commit 370842d

Browse files
authored
Prep for 3.1.4 release (#881)
2 parents 7e9c0dc + fbd3c32 commit 370842d

File tree

8 files changed

+98
-23
lines changed

8 files changed

+98
-23
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+
## 3.1.4
4+
35
## 3.1.3
46

57
- The `translate-schema` command now produces prettier output.

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 = "3.1.3"
5+
version = "3.1.4"
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 = "=3.1.3", path = "../cedar-policy" }
15-
cedar-policy-formatter = { version = "=3.1.3", path = "../cedar-policy-formatter" }
14+
cedar-policy = { version = "=3.1.4", path = "../cedar-policy" }
15+
cedar-policy-formatter = { version = "=3.1.4", 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 = "3.1.3"
6+
version = "3.1.4"
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 = "3.1.3"
3+
version = "3.1.4"
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 = "=3.1.3", path = "../cedar-policy-core" }
13+
cedar-policy-core = { version = "=3.1.4", path = "../cedar-policy-core" }
1414
pretty = "0.12.1"
1515
logos = "0.14.0"
1616
itertools = "0.12"

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

Lines changed: 77 additions & 11 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,17 +43,31 @@ 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
.map(|(k, v)| (k, &v.val))
@@ -59,8 +76,12 @@ fn soundness_check(ps: &str, ast: &PolicySet) -> Result<()> {
5976
.map(|(k, v)| (k, &v.val))
6077
.collect::<std::collections::BTreeMap<_, _>>(),
6178
);
62-
if !(f_anno == anno
63-
&& f_p.effect() == p.effect()
79+
if f_anno != anno {
80+
return Err(miette!(
81+
"formatter changed the annotations from {anno:?} to {f_anno:?}"
82+
));
83+
}
84+
if !(f_p.effect() == p.effect()
6485
&& f_p.principal_constraint() == p.principal_constraint()
6586
&& f_p.action_constraint() == p.action_constraint()
6687
&& f_p.resource_constraint() == p.resource_constraint()
@@ -69,7 +90,7 @@ fn soundness_check(ps: &str, ast: &PolicySet) -> Result<()> {
6990
.eq_shape(p.non_head_constraints()))
7091
{
7192
return Err(miette!(
72-
"policies differ in meaning or annotations:\noriginal: {p}\nformatted: {f_p}"
93+
"formatter changed the policy structure:\noriginal:\n{p}\nformatted:\n{f_p}"
7394
));
7495
}
7596
}
@@ -124,7 +145,9 @@ pub fn policies_str_to_pretty(ps: &str, config: &Config) -> Result<String> {
124145
}
125146
};
126147
// add soundness check to make sure formatting doesn't alter policy ASTs
127-
soundness_check(&formatted_policies, &ast)?;
148+
soundness_check(&formatted_policies, &ast).wrap_err(
149+
"internal error: please file an issue at <https://github.com/cedar-policy/cedar/issues>",
150+
)?;
128151
Ok(formatted_policies)
129152
}
130153

@@ -167,6 +190,49 @@ mod tests {
167190
);
168191
}
169192

193+
#[test]
194+
fn test_soundness_check() {
195+
let p1 = r#"permit (principal, action, resource)
196+
when { "
197+
198+
a
199+
" };"#;
200+
let p2 = r#"permit (principal, action, resource)
201+
when { "
202+
a
203+
" };"#;
204+
assert!(soundness_check(p2, &parse_policyset(p1).unwrap()).is_err());
205+
206+
let p1 = r#"
207+
permit (principal, action, resource)
208+
when { "a"};
209+
permit (principal, action, resource)
210+
when { "
211+
212+
a
213+
" };"#;
214+
let p2 = r#"
215+
permit (principal, action, resource)
216+
when { "
217+
a
218+
" };
219+
permit (principal, action, resource)
220+
when { "a"};"#;
221+
assert!(soundness_check(p2, &parse_policyset(p1).unwrap()).is_err());
222+
223+
let p1 = r#"
224+
permit (principal, action, resource)
225+
when { "a" };
226+
permit (principal, action, resource)
227+
when { "b" };"#;
228+
let p2 = r#"
229+
permit (principal, action, resource)
230+
when { "a" };
231+
permit (principal, action, resource)
232+
when { "b"};"#;
233+
assert!(soundness_check(p2, &parse_policyset(p1).unwrap()).is_ok());
234+
}
235+
170236
#[test]
171237
fn test_format_files() {
172238
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 = "3.1.3"
5+
version = "3.1.4"
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 = "=3.1.3", path = "../cedar-policy-core" }
14+
cedar-policy-core = { version = "=3.1.4", path = "../cedar-policy-core" }
1515
serde = { version = "1.0", features = ["derive"] }
1616
serde_json = { version = "1.0", features = ["preserve_order"] }
1717
serde_with = "3.0"

cedar-policy/CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.1.4] - 2024-05-17
9+
10+
### Fixed
11+
12+
- The formatter will now fail with an error if it changes a policy's semantics. (#865)
13+
814
## [3.1.3] - 2024-04-15
915

1016
### Changed
@@ -423,7 +429,8 @@ Cedar Language Version: 2.0.0
423429
Cedar Language Version: 2.0.0
424430
- Initial release of `cedar-policy`.
425431

426-
[Unreleased]: https://github.com/cedar-policy/cedar/compare/v3.1.3...main
432+
[Unreleased]: https://github.com/cedar-policy/cedar/compare/v3.1.4...main
433+
[3.1.4]: https://github.com/cedar-policy/cedar/compare/v3.1.3...v3.1.4
427434
[3.1.3]: https://github.com/cedar-policy/cedar/compare/v3.1.2...v3.1.3
428435
[3.1.2]: https://github.com/cedar-policy/cedar/compare/v3.1.1...v3.1.2
429436
[3.1.1]: https://github.com/cedar-policy/cedar/compare/v3.1.0...v3.1.1

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 = "3.1.3"
5+
version = "3.1.4"
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 = "=3.1.3", path = "../cedar-policy-core" }
15-
cedar-policy-validator = { version = "=3.1.3", path = "../cedar-policy-validator" }
14+
cedar-policy-core = { version = "=3.1.4", path = "../cedar-policy-core" }
15+
cedar-policy-validator = { version = "=3.1.4", 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)