You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Serializing a valid 64-bit int that can't be represented in double precision float
4808
+
#[test]
4809
+
fnjson_bignum_1(){
4810
+
let src = r#"
4811
+
permit(
4812
+
principal,
4813
+
action == Action::"action",
4814
+
resource
4815
+
) when {
4816
+
-9223372036854775808
4817
+
};"#;
4818
+
let p:Policy = src.parse().unwrap();
4819
+
p.to_json().unwrap();
4820
+
}
4821
+
4822
+
#[test]
4823
+
fnjson_bignum_1a(){
4824
+
let src = r#"
4825
+
permit(principal, action, resource) when {
4826
+
(true && (-90071992547409921)) && principal
4827
+
};"#;
4828
+
let p:Policy = src.parse().unwrap();
4829
+
let v = p.to_json().unwrap();
4830
+
let s = serde_json::to_string(&v).unwrap();
4831
+
assert!(s.contains("90071992547409921"));
4832
+
}
4833
+
4834
+
// Deserializing a valid 64-bit int that can't be represented in double precision float
4835
+
#[test]
4836
+
fnjson_bignum_2(){
4837
+
let src = r#"{"effect":"permit","principal":{"op":"All"},"action":{"op":"All"},"resource":{"op":"All"},"conditions":[{"kind":"when","body":{"==":{"left":{".":{"left":{"Var":"principal"},"attr":"x"}},"right":{"Value":90071992547409921}}}}]}"#;
4838
+
let v: serde_json::Value = serde_json::from_str(src).unwrap();
4839
+
let p = Policy::from_json(None, v).unwrap();
4840
+
let pretty = format!("{p}");
4841
+
// Ensure the number didn't get rounded
4842
+
assert!(pretty.contains("90071992547409921"));
4843
+
}
4844
+
4845
+
// Deserializing a valid 64-bit int that can't be represented in double precision float
4846
+
#[test]
4847
+
fnjson_bignum_2a(){
4848
+
let src = r#"{"effect":"permit","principal":{"op":"All"},"action":{"op":"All"},"resource":{"op":"All"},"conditions":[{"kind":"when","body":{"==":{"left":{".":{"left":{"Var":"principal"},"attr":"x"}},"right":{"Value":-9223372036854775808}}}}]}"#;
4849
+
let v: serde_json::Value = serde_json::from_str(src).unwrap();
4850
+
let p = Policy::from_json(None, v).unwrap();
4851
+
let pretty = format!("{p}");
4852
+
// Ensure the number didn't get rounded
4853
+
assert!(pretty.contains("-9223372036854775808"));
4854
+
}
4855
+
4856
+
// Deserializing a number that doesn't fit in 64 bit integer
4857
+
// This _should_ fail, as there's no way to do this w/out loss of precision
4858
+
#[test]
4859
+
fnjson_bignum_3(){
4860
+
let src = r#"{"effect":"permit","principal":{"op":"All"},"action":{"op":"All"},"resource":{"op":"All"},"conditions":[{"kind":"when","body":{"==":{"left":{".":{"left":{"Var":"principal"},"attr":"x"}},"right":{"Value":9223372036854775808}}}}]}"#;
4861
+
let v: serde_json::Value = serde_json::from_str(src).unwrap();
0 commit comments