Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/run_cedar_java_reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jobs:
- name: Check FFI Formatting
working-directory: CedarJavaFFI
run: cargo fmt --all --check
- name: Run FFI tests
working-directory: CedarJavaFFI
run: cargo test --all-features
- name: Install Zig
run: ${{ matrix.zigInstall }}
- name: Setup Java JDK
Expand Down
51 changes: 40 additions & 11 deletions CedarJavaFFI/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#[cfg(feature = "partial-eval")]
use cedar_policy::ffi::is_authorized_partial_json_str;
use cedar_policy::ffi::{is_authorized_partial_json_str, PartialAuthorizationAnswer};
use cedar_policy::{
ffi::{is_authorized_json_str, validate_json_str},
EntityUid, Policy, PolicyId, PolicySet, Schema, SlotId, Template,
Expand Down Expand Up @@ -110,10 +110,10 @@ pub fn getCedarJNIVersion(env: JNIEnv<'_>) -> jstring {

fn call_cedar(call: &str, input: &str) -> String {
let result = match call {
V0_AUTH_OP => is_authorized_json_str(&input),
V0_AUTH_OP => is_authorized_json_str(input),
#[cfg(feature = "partial-eval")]
V0_AUTH_PARTIAL_OP => is_authorized_partial_json_str(&input),
V0_VALIDATE_OP => validate_json_str(&input),
V0_VALIDATE_OP => validate_json_str(input),
V0_PARSE_EUID_OP => {
let ires = json_parse_entity_uid(&input);
serde_json::to_string(&ires)
Expand Down Expand Up @@ -435,6 +435,7 @@ fn get_euid_repr_internal<'a>(
#[cfg(test)]
mod test {
use super::*;
use cedar_policy::ffi::{AuthorizationAnswer, ValidationAnswer};
use cool_asserts::assert_matches;

#[test]
Expand All @@ -460,16 +461,25 @@ mod test {
}
"#,
);
assert_success(result);
assert_authorization_success(result);
}

#[test]
fn empty_validation_call_json_schema_succeeds() {
let result = call_cedar(
"ValidateOperation",
r#"{ "schema": { "json": {} }, "policySet": {} }"#,
);
assert_validation_success(result);
}

#[test]
fn empty_validation_call_succeeds() {
let result = call_cedar(
"ValidateOperation",
r#"{ "schema": { "json": { "": {"entityTypes": {}, "actions": {} } }, "policySet": {} } }"#,
r#"{ "schema": { "human": "" }, "policySet": {} }"#,
);
assert_success(result);
assert_validation_success(result);
}

#[test]
Expand Down Expand Up @@ -499,7 +509,7 @@ mod test {
}
"#,
);
assert_success(result);
assert_authorization_success(result);
}

#[test]
Expand All @@ -523,7 +533,7 @@ mod test {
}
"#,
);
assert_success(result);
assert_authorization_success(result);
}

#[test]
Expand Down Expand Up @@ -570,7 +580,7 @@ mod test {
}
"#,
);
assert_success(result);
assert_authorization_success(result);
}

#[cfg(feature = "partial-eval")]
Expand All @@ -594,7 +604,7 @@ mod test {
}
"#,
);
assert_success(result);
assert_partial_authorization_success(result);
}

#[cfg(feature = "partial-eval")]
Expand All @@ -618,7 +628,7 @@ mod test {
}
"#,
);
assert_success(result);
assert_partial_authorization_success(result);
}

#[track_caller]
Expand All @@ -632,4 +642,23 @@ mod test {
let result: Answer = serde_json::from_str(result.as_str()).unwrap();
assert_matches!(result, Answer::Failure { .. });
}

#[track_caller]
fn assert_authorization_success(result: String) {
let result: AuthorizationAnswer = serde_json::from_str(result.as_str()).unwrap();
assert_matches!(result, AuthorizationAnswer::Success { .. });
}

#[cfg(feature = "partial-eval")]
#[track_caller]
fn assert_partial_authorization_success(result: String) {
let result: PartialAuthorizationAnswer = serde_json::from_str(result.as_str()).unwrap();
assert_matches!(result, PartialAuthorizationAnswer::Residuals { .. });
}

#[track_caller]
fn assert_validation_success(result: String) {
let result: ValidationAnswer = serde_json::from_str(result.as_str()).unwrap();
assert_matches!(result, ValidationAnswer::Success { .. });
}
}