()
| 1965 | use super::*; |
| 1966 | #[test] |
| 1967 | fn policyset_to_json_valid_test() { |
| 1968 | let mut env = JVM.attach_current_thread().unwrap(); |
| 1969 | let policyset_str = r#"{ |
| 1970 | "staticPolicies": { |
| 1971 | "p1": "permit(principal == User::\"Bob\", action == Action::\"View_Photo\", resource in Album::\"Vacation\");" |
| 1972 | }, |
| 1973 | "templates": { |
| 1974 | "t0": "permit(principal == ?principal, action == Action::\"View_Photo\", resource in Album::\"Vacation\");" |
| 1975 | }, |
| 1976 | "templateLinks": [{ |
| 1977 | "templateId": "t0", |
| 1978 | "newId": "tl0", |
| 1979 | "values": { |
| 1980 | "?principal": {"type": "User", "id": "Alice"} |
| 1981 | } |
| 1982 | }] |
| 1983 | }"#; |
| 1984 | |
| 1985 | let policyset_jstr = env.new_string(policyset_str).unwrap(); |
| 1986 | let policyset_json_result = policy_set_to_json_internal(&mut env, policyset_jstr); |
| 1987 | |
| 1988 | assert!(policyset_json_result.is_ok()); |
| 1989 | |
| 1990 | let policyset_json_jstr = |
| 1991 | JString::cast(&mut env, policyset_json_result.unwrap().l().unwrap()).unwrap(); |
| 1992 | let actual_json_str = String::from(env.get_string(&policyset_json_jstr).unwrap()); |
| 1993 | |
| 1994 | let expected_json = serde_json::json!({ |
| 1995 | "templates": { |
| 1996 | "t0": { |
| 1997 | "effect": "permit", |
| 1998 | "principal": { |
| 1999 | "op": "==", |
| 2000 | "slot": "?principal" |
| 2001 | }, |
| 2002 | "action": { |
| 2003 | "op": "==", |
| 2004 | "entity": { |
| 2005 | "type": "Action", |
| 2006 | "id": "View_Photo" |
| 2007 | } |
| 2008 | }, |
| 2009 | "resource": { |
| 2010 | "op": "in", |
| 2011 | "entity": { |
| 2012 | "type": "Album", |
| 2013 | "id": "Vacation" |
| 2014 | } |
| 2015 | }, |
| 2016 | "conditions": [] |
| 2017 | } |
| 2018 | }, |
| 2019 | "staticPolicies": { |
| 2020 | "p1": { |
| 2021 | "effect": "permit", |
| 2022 | "principal": { |
| 2023 | "op": "==", |
| 2024 | "entity": { |
nothing calls this directly
no test coverage detected