use super::utils::cedarling_util::get_cedarling_with_callback;
use super::utils::test_helpers::create_test_unsigned_request;
use super::utils::*;
use crate::EntityData;
use serde_json::json;
use tokio::test;
#[test]
async fn success_test_json() {
static POLICY_STORE_RAW_JSON: &str = include_str!("../../../test_files/policy-store_ok_2.yaml");
let cedarling = get_cedarling_with_callback(
PolicyStoreSource::Yaml(POLICY_STORE_RAW_JSON.to_string()),
|_| {},
)
.await;
let resource = EntityData::deserialize(json!({
"cedar_entity_mapping": {
"entity_type": "Jans::Issue",
"id": "random_id"
},
"org_id": "some_long_id",
"country": "US"
}))
.expect("resource entity should deserialize");
let principal = EntityData::deserialize(json!({
"cedar_entity_mapping": {
"entity_type": "Jans::TestPrincipal1",
"id": "1"
},
"is_ok": true
}))
.expect("principal entity should deserialize");
let request = create_test_unsigned_request(
"Jans::Action::\"UpdateForTestPrincipals\"",
Some(principal),
resource,
);
let result = cedarling
.authorize_unsigned(request)
.await
.expect("request should be parsed without errors");
assert!(result.decision, "request result should be allowed");
}