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
3967
+
#[test]
3968
+
fnjson_bignum_1(){
3969
+
let src = r#"
3970
+
permit(
3971
+
principal,
3972
+
action == Action::"action",
3973
+
resource
3974
+
) when {
3975
+
-9223372036854775808
3976
+
};"#;
3977
+
let p:Policy = src.parse().unwrap();
3978
+
p.to_json().unwrap();
3979
+
}
3980
+
3981
+
#[test]
3982
+
fnjson_bignum_1a(){
3983
+
let src = r#"
3984
+
permit(principal, action, resource) when {
3985
+
(true && (-90071992547409921)) && principal
3986
+
};"#;
3987
+
let p:Policy = src.parse().unwrap();
3988
+
let v = p.to_json().unwrap();
3989
+
let s = serde_json::to_string(&v).unwrap();
3990
+
assert!(s.contains("90071992547409921"));
3991
+
}
3992
+
3993
+
// Deserializing a valid 64-bit int that can't be represented in double precision float
3994
+
#[test]
3995
+
fnjson_bignum_2(){
3996
+
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}}}}]}"#;
3997
+
let v: serde_json::Value = serde_json::from_str(src).unwrap();
3998
+
let p = Policy::from_json(None, v).unwrap();
3999
+
let pretty = format!("{p}");
4000
+
// Ensure the number didn't get rounded
4001
+
assert!(pretty.contains("90071992547409921"));
4002
+
}
4003
+
4004
+
// Deserializing a valid 64-bit int that can't be represented in double precision float
4005
+
#[test]
4006
+
fnjson_bignum_2a(){
4007
+
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}}}}]}"#;
4008
+
let v: serde_json::Value = serde_json::from_str(src).unwrap();
4009
+
let p = Policy::from_json(None, v).unwrap();
4010
+
let pretty = format!("{p}");
4011
+
// Ensure the number didn't get rounded
4012
+
assert!(pretty.contains("-9223372036854775808"));
4013
+
}
4014
+
4015
+
// Deserializing a number that doesn't fit in 64 bit integer
4016
+
// This _should_ fail, as there's no way to do this w/out loss of precision
4017
+
#[test]
4018
+
fnjson_bignum_3(){
4019
+
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}}}}]}"#;
4020
+
let v: serde_json::Value = serde_json::from_str(src).unwrap();
0 commit comments