diff --git a/jans-cedarling/Cargo.lock b/jans-cedarling/Cargo.lock index 2b945125af4..552a1acadaa 100644 --- a/jans-cedarling/Cargo.lock +++ b/jans-cedarling/Cargo.lock @@ -185,11 +185,11 @@ dependencies = [ [[package]] name = "askama" -version = "0.13.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d4744ed2eef2645831b441d8f5459689ade2ab27c854488fbab1fbe94fce1a7" +checksum = "f1bf825125edd887a019d0a3a837dcc5499a68b0d034cc3eb594070c3e18addc" dependencies = [ - "askama_derive", + "askama_macros", "itoa", "percent-encoding", "serde", @@ -198,12 +198,13 @@ dependencies = [ [[package]] name = "askama_derive" -version = "0.13.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d661e0f57be36a5c14c48f78d09011e67e0cb618f269cca9f2fd8d15b68c46ac" +checksum = "e1c7065972a130eafa84215f21352ae15b4a7393da48c1f5e103904490736738" dependencies = [ "askama_parser", "basic-toml", + "glob", "memchr", "proc-macro2", "quote", @@ -213,16 +214,26 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "askama_macros" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e23b1d2c4bd39a41971f6124cef4cc6fd0540913ecb90919b69ab3bbe44ae1a" +dependencies = [ + "askama_derive", +] + [[package]] name = "askama_parser" -version = "0.13.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf315ce6524c857bb129ff794935cf6d42c82a6cff60526fe2a63593de4d0d4f" +checksum = "7db09fde9143e7ac4513358fb32ee32847125b63b18ea715afd487956da715da" dependencies = [ - "memchr", + "rustc-hash", "serde", "serde_derive", - "winnow 0.7.15", + "unicode-ident", + "winnow 1.0.4", ] [[package]] @@ -615,6 +626,16 @@ dependencies = [ "serde", ] +[[package]] +name = "cargo-platform" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0061da739915fae12ea00e16397555ed4371a6bb285431aab930f61b0aa4ba" +dependencies = [ + "serde", + "serde_core", +] + [[package]] name = "cargo_metadata" version = "0.18.1" @@ -622,7 +643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" dependencies = [ "camino", - "cargo-platform", + "cargo-platform 0.1.9", "semver", "serde", "serde_json", @@ -631,12 +652,12 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.19.2" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd5eb614ed4c27c5d706420e4320fbe3216ab31fa1c33cd8246ac36dae4479ba" +checksum = "ef987d17b0a113becdd19d3d0022d04d7ef41f9efe4f3fb63ac44ba61df3ade9" dependencies = [ "camino", - "cargo-platform", + "cargo-platform 0.3.3", "semver", "serde", "serde_json", @@ -1959,9 +1980,9 @@ dependencies = [ [[package]] name = "fs-err" -version = "2.11.0" +version = "3.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88a41f105fe1d5b6b34b2055e3dc59bb79b46b48b2040b9e6c7b4b5de097aa41" +checksum = "b91aa448ca50d7e79433bdf3ee8d99215430d2ec02ade5aefab2a073a1822e8a" dependencies = [ "autocfg", ] @@ -3766,7 +3787,7 @@ version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" dependencies = [ - "siphasher 1.0.3", + "siphasher", ] [[package]] @@ -3775,7 +3796,7 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266" dependencies = [ - "siphasher 1.0.3", + "siphasher", ] [[package]] @@ -5208,12 +5229,6 @@ dependencies = [ "time", ] -[[package]] -name = "siphasher" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" - [[package]] name = "siphasher" version = "1.0.3" @@ -5748,15 +5763,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - [[package]] name = "toml" version = "0.8.23" @@ -6171,13 +6177,13 @@ checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "uniffi" -version = "0.29.5" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3291800a6b06569f7d3e15bdb6dc235e0f0c8bd3eb07177f430057feb076415f" +checksum = "a782a48d72cfd7a2d65cfc7c691dbf5375c43104b3c195f7eccc716dcc3540c8" dependencies = [ "anyhow", "camino", - "cargo_metadata 0.19.2", + "cargo_metadata 0.23.1", "clap", "uniffi_bindgen", "uniffi_core", @@ -6187,14 +6193,14 @@ dependencies = [ [[package]] name = "uniffi_bindgen" -version = "0.29.5" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a04b99fa7796eaaa7b87976a0dbdd1178dc1ee702ea00aca2642003aef9b669e" +checksum = "533b0312c73e3b54eb78a4b257ceae390962dd4767995778309a74644643f9ac" dependencies = [ "anyhow", "askama", "camino", - "cargo_metadata 0.19.2", + "cargo_metadata 0.23.1", "fs-err", "glob", "goblin", @@ -6204,7 +6210,7 @@ dependencies = [ "serde", "tempfile", "textwrap", - "toml 0.5.11", + "toml 0.9.12+spec-1.1.0", "uniffi_internal_macros", "uniffi_meta", "uniffi_pipeline", @@ -6213,9 +6219,9 @@ dependencies = [ [[package]] name = "uniffi_core" -version = "0.29.5" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f38a9a27529ccff732f8efddb831b65b1e07f7dea3fd4cacd4a35a8c4b253b98" +checksum = "8e32e261c5b0dfaba6488f536e71957dddd6b1a498ac7eb791bee56b60a086be" dependencies = [ "anyhow", "bytes", @@ -6225,9 +6231,9 @@ dependencies = [ [[package]] name = "uniffi_internal_macros" -version = "0.29.5" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09acd2ce09c777dd65ee97c251d33c8a972afc04873f1e3b21eb3492ade16933" +checksum = "84ae78069a5e6772ef694fd5bdb628532c88d2c2f0e7142bf6a384636eadb1af" dependencies = [ "anyhow", "indexmap 2.14.0", @@ -6238,9 +6244,9 @@ dependencies = [ [[package]] name = "uniffi_macros" -version = "0.29.5" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5596f178c4f7aafa1a501c4e0b96236a96bc2ef92bdb453d83e609dad0040152" +checksum = "330be6770532e86320df31f54c70bb0be67588594e8e77fa56e9083a3fed5d0d" dependencies = [ "camino", "fs-err", @@ -6249,27 +6255,27 @@ dependencies = [ "quote", "serde", "syn 2.0.119", - "toml 0.5.11", + "toml 0.9.12+spec-1.1.0", "uniffi_meta", ] [[package]] name = "uniffi_meta" -version = "0.29.5" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beadc1f460eb2e209263c49c4f5b19e9a02e00a3b2b393f78ad10d766346ecff" +checksum = "78de021f5547e56ab16c665a49d67d4fd3d31e77422f7739a2e9359d328cd9e7" dependencies = [ "anyhow", - "siphasher 0.3.11", + "siphasher", "uniffi_internal_macros", "uniffi_pipeline", ] [[package]] name = "uniffi_pipeline" -version = "0.29.5" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd76b3ac8a2d964ca9fce7df21c755afb4c77b054a85ad7a029ad179cc5abb8a" +checksum = "3f8201bb1907ed8a42d80e11cbc25c8a033e7a31c3cff1d911f56eedb81d4948" dependencies = [ "anyhow", "heck 0.5.0", @@ -6280,9 +6286,9 @@ dependencies = [ [[package]] name = "uniffi_udl" -version = "0.29.5" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4319cf905911d70d5b97ce0f46f101619a22e9a189c8c46d797a9955e9233716" +checksum = "a6e57996bc58009cc29bf04845d627ae313c2547b87171c1c349d6c51a1656c0" dependencies = [ "anyhow", "textwrap", diff --git a/jans-cedarling/bindings/cedarling-java/src/main/java/io/jans/cedarling/binding/wrapper/CedarlingAdapter.java b/jans-cedarling/bindings/cedarling-java/src/main/java/io/jans/cedarling/binding/wrapper/CedarlingAdapter.java index 8f2389429f4..63baf4e52f5 100644 --- a/jans-cedarling/bindings/cedarling-java/src/main/java/io/jans/cedarling/binding/wrapper/CedarlingAdapter.java +++ b/jans-cedarling/bindings/cedarling-java/src/main/java/io/jans/cedarling/binding/wrapper/CedarlingAdapter.java @@ -101,8 +101,8 @@ public MultiIssuerAuthorizeResult authorizeMultiIssuer( throw new IllegalArgumentException("resource must not be null"); } EntityData resourceObj = EntityData.Companion.fromJson(resource.toString()); - String contextStr = context != null ? context.toString() : "{}"; - return cedarling.authorizeMultiIssuer(tokens, action, resourceObj, contextStr); + JsonValue contextJson = context != null ? new JsonValue(context.toString()) : null; + return cedarling.authorizeMultiIssuer(tokens, action, resourceObj, contextJson); } // ── authorize_unsigned ────────────────────────────────────────────── @@ -159,7 +159,7 @@ public AuthorizeResult authorizeUnsignedEntity( } EntityData resourceObj = EntityData.Companion.fromJson(resource.toString()); String contextStr = context != null ? context.toString() : "{}"; - return cedarling.authorizeUnsigned(principal, action, resourceObj, contextStr); + return cedarling.authorizeUnsigned(principal, action, resourceObj, new JsonValue(contextStr)); } // ── authorize_unsigned_batch ──────────────────────────────────────── @@ -264,8 +264,8 @@ public BatchItem batchItemFromJson( throw new IllegalArgumentException("resource must not be null"); } EntityData resourceObj = EntityData.Companion.fromJson(resource.toString()); - String contextStr = context != null ? context.toString() : null; - return new BatchItem(resourceObj, action, contextStr); + JsonValue contextJson = context != null ? new JsonValue(context.toString()) : null; + return new BatchItem(resourceObj, action, contextJson); } /** @@ -362,7 +362,7 @@ public void pushDataCtx(String key, JSONObject value, Long ttlSecs) throws DataE if (value == null) { throw new DataException.SerializationException("value cannot be null"); } - cedarling.pushDataCtx(key, value.toString(), ttlSecs); + cedarling.pushDataCtx(key, new JsonValue(value.toString()), ttlSecs); } /** @@ -382,7 +382,7 @@ public void pushDataCtx(String key, String value, Long ttlSecs) throws DataExcep if (value == null) { throw new DataException.SerializationException("value cannot be null"); } - cedarling.pushDataCtx(key, value, ttlSecs); + cedarling.pushDataCtx(key, new JsonValue(value), ttlSecs); } /** @@ -416,12 +416,12 @@ public void pushDataCtx(String key, String value) throws DataException { * @throws DataException If the operation fails */ public Object getDataCtx(String key) throws DataException { - String result = cedarling.getDataCtx(key); + JsonValue result = cedarling.getDataCtx(key); if (result == null) { return null; } try { - org.json.JSONTokener tokener = new org.json.JSONTokener(result); + org.json.JSONTokener tokener = new org.json.JSONTokener(result.getValue()); Object value = tokener.nextValue(); if (value == org.json.JSONObject.NULL) { return null; diff --git a/jans-cedarling/bindings/cedarling-java/src/test/java/io/jans/cedarling/binding/wrapper/MultiIssuerBatchAuthzTest.java b/jans-cedarling/bindings/cedarling-java/src/test/java/io/jans/cedarling/binding/wrapper/MultiIssuerBatchAuthzTest.java index 5f62c999ac1..2e856386fa1 100644 --- a/jans-cedarling/bindings/cedarling-java/src/test/java/io/jans/cedarling/binding/wrapper/MultiIssuerBatchAuthzTest.java +++ b/jans-cedarling/bindings/cedarling-java/src/test/java/io/jans/cedarling/binding/wrapper/MultiIssuerBatchAuthzTest.java @@ -20,6 +20,7 @@ import uniffi.cedarling_uniffi.AuthorizeException; import uniffi.cedarling_uniffi.BatchAuthorizeMultiIssuerResponse; import uniffi.cedarling_uniffi.BatchItem; +import uniffi.cedarling_uniffi.JsonValue; import uniffi.cedarling_uniffi.BatchItemError; import uniffi.cedarling_uniffi.BatchItemMultiIssuerOutcome; import uniffi.cedarling_uniffi.EntityData; @@ -201,7 +202,8 @@ public void batchMixedDecisionsPreserveOrder() throws Exception { BatchItem badItem = new BatchItem( EntityData.Companion.fromJson(resource.toString()), "this is not a valid uid", - new JSONObject().toString()); + new JsonValue("{}") + ); List items = new ArrayList<>(); items.add(sameItem()); items.add(badItem); diff --git a/jans-cedarling/bindings/cedarling-java/src/test/java/io/jans/cedarling/binding/wrapper/UnsignedBatchAuthzTest.java b/jans-cedarling/bindings/cedarling-java/src/test/java/io/jans/cedarling/binding/wrapper/UnsignedBatchAuthzTest.java index fc68d94a852..4b83cfbe7fa 100644 --- a/jans-cedarling/bindings/cedarling-java/src/test/java/io/jans/cedarling/binding/wrapper/UnsignedBatchAuthzTest.java +++ b/jans-cedarling/bindings/cedarling-java/src/test/java/io/jans/cedarling/binding/wrapper/UnsignedBatchAuthzTest.java @@ -18,6 +18,7 @@ import uniffi.cedarling_uniffi.AuthorizeResult; import uniffi.cedarling_uniffi.BatchAuthorizeUnsignedResponse; import uniffi.cedarling_uniffi.BatchItem; +import uniffi.cedarling_uniffi.JsonValue; import uniffi.cedarling_uniffi.BatchItemError; import uniffi.cedarling_uniffi.BatchItemUnsignedOutcome; import uniffi.cedarling_uniffi.EntityData; @@ -155,7 +156,7 @@ public void batchMixedDecisionsPreserveOrder() throws Exception { items.add(new BatchItem( EntityData.Companion.fromJson(resource.toString()), "this is not a valid uid", - context.toString())); + new JsonValue(context.toString()))); items.add(sameItem()); BatchAuthorizeUnsignedResponse response = diff --git a/jans-cedarling/bindings/cedarling_uniffi/Cargo.toml b/jans-cedarling/bindings/cedarling_uniffi/Cargo.toml index 80732fa2ebb..12f4c1ff190 100644 --- a/jans-cedarling/bindings/cedarling_uniffi/Cargo.toml +++ b/jans-cedarling/bindings/cedarling_uniffi/Cargo.toml @@ -12,8 +12,8 @@ name = "cedarling_uniffi" # dependency for NOT wasm target [target.'cfg(not(target_arch = "wasm32"))'.dependencies] cedarling = { workspace = true, features = ["blocking"] } -uniffi = { version = "0.29.0", features = ["cli"] } -uniffi_macros = "0.29.0" # Procedural macros support +uniffi = { version = "0.32.0", features = ["cli"] } +uniffi_macros = "0.32.0" # Procedural macros support serde_json = { workspace = true } thiserror.workspace = true diff --git a/jans-cedarling/bindings/cedarling_uniffi/README.md b/jans-cedarling/bindings/cedarling_uniffi/README.md index c19941d2f8a..1a80e8a347b 100644 --- a/jans-cedarling/bindings/cedarling_uniffi/README.md +++ b/jans-cedarling/bindings/cedarling_uniffi/README.md @@ -319,7 +319,10 @@ Regenerate Kotlin/Swift bindings from the library (`uniffi-bindgen generate …` val bootstrapJson = assets.open("bootstrap.json").bufferedReader().use { it.readText() } val archiveBytes = assets.open("policy-store.cjar").readBytes() -val cedarling = Cedarling.loadFromJsonWithArchiveBytes(bootstrapJson, archiveBytes) +val buffer = java.nio.ByteBuffer.allocateDirect(archiveBytes.size) +buffer.put(archiveBytes) +buffer.flip() +val cedarling = Cedarling.loadFromJsonWithArchiveBytes(bootstrapJson, buffer) ``` **Swift (bundle resources):** diff --git a/jans-cedarling/bindings/cedarling_uniffi/androidApp/app/src/main/java/com/example/androidapp/MainActivity.kt b/jans-cedarling/bindings/cedarling_uniffi/androidApp/app/src/main/java/com/example/androidapp/MainActivity.kt index 58867f0c03d..0103841d412 100644 --- a/jans-cedarling/bindings/cedarling_uniffi/androidApp/app/src/main/java/com/example/androidapp/MainActivity.kt +++ b/jans-cedarling/bindings/cedarling_uniffi/androidApp/app/src/main/java/com/example/androidapp/MainActivity.kt @@ -135,7 +135,10 @@ fun CardListScreen() { try { val instance: Cedarling? = bootstrapConfig?.let { config -> policyStoreByteArray?.let { bytes -> - Cedarling.loadFromJsonWithArchiveBytes(config, bytes) + val buffer = java.nio.ByteBuffer.allocateDirect(bytes.size) + buffer.put(bytes) + buffer.flip() + Cedarling.loadFromJsonWithArchiveBytes(config, buffer) } } diff --git a/jans-cedarling/bindings/cedarling_uniffi/src/lib.rs b/jans-cedarling/bindings/cedarling_uniffi/src/lib.rs index 3cec7a58222..3a8e5780c78 100644 --- a/jans-cedarling/bindings/cedarling_uniffi/src/lib.rs +++ b/jans-cedarling/bindings/cedarling_uniffi/src/lib.rs @@ -124,6 +124,7 @@ pub struct TokenInput { pub struct BatchItem { pub resource: Arc, pub action: String, + #[uniffi(default)] pub context: Option, } @@ -180,9 +181,11 @@ impl TryFrom for DataEntry { Ok(Self { key: entry.key, - value: JsonValue(serde_json::to_string(&entry.value).map_err(|e| { - DataError::SerializationError(format!("Failed to serialize value: {}", e)) - })?), + value: JsonValue { + value: serde_json::to_string(&entry.value).map_err(|e| { + DataError::SerializationError(format!("Failed to serialize value: {}", e)) + })?, + }, data_type, created_at: entry.created_at.to_rfc3339(), expires_at: entry @@ -264,21 +267,25 @@ impl EntityData { } } -/// Wrapper struct for JSON values, holding a string representation of the JSON value. -#[derive(Debug, Clone)] -pub struct JsonValue(String); - -uniffi::custom_newtype!(JsonValue, String); +/// A wrapper struct for JSON values passed across the FFI boundary. +/// +/// This struct allows language bindings (like Kotlin or Swift) to pass valid JSON +/// data to the Cedarling engine as a string, which is then parsed internally. +#[derive(Debug, Clone, uniffi::Record)] +pub struct JsonValue { + /// String representation of the JSON value + pub value: String, +} impl TryFrom for Value { type Error = serde_json::Error; - fn try_from(value: JsonValue) -> Result { + fn try_from(val: JsonValue) -> Result { // Hot-path: callers commonly pass the exact literal `"{}"` for an empty // context. - if value.0 == "{}" { + if val.value == "{}" { return Ok(Value::Object(serde_json::Map::new())); } - serde_json::from_str(&value.0) + serde_json::from_str(&val.value) } } @@ -322,7 +329,7 @@ impl Cedarling { #[uniffi::constructor] pub fn load_from_json_with_archive_bytes( config: String, - archive_bytes: Vec, + archive_bytes: &[u8], ) -> Result { let mut raw_config: BootstrapConfigRaw = serde_json::from_str(&config).map_err(|e| CedarlingError::InitializationFailed { @@ -342,7 +349,7 @@ impl Cedarling { // Override the policy store source with the archive bytes bootstrap_config.policy_store_config.source = - PolicyStoreSource::ArchiveBytes(archive_bytes); + PolicyStoreSource::ArchiveBytes(archive_bytes.to_vec()); let cedarling = core::blocking::Cedarling::new(&bootstrap_config).map_err(|e| { CedarlingError::InitializationFailed { @@ -641,9 +648,11 @@ impl Cedarling { pub fn get_data_ctx(&self, key: String) -> Result, DataError> { let result: Result<_, core::DataError> = self.inner.get_data_ctx(&key); match result.map_err(DataError::from)? { - Some(value) => Ok(Some(JsonValue(serde_json::to_string(&value).map_err( - |e| DataError::SerializationError(format!("Failed to serialize value: {}", e)), - )?))), + Some(value) => Ok(Some(JsonValue { + value: serde_json::to_string(&value).map_err(|e| { + DataError::SerializationError(format!("Failed to serialize value: {}", e)) + })?, + })), None => Ok(None), } } diff --git a/jans-cedarling/bindings/cedarling_uniffi/src/tests.rs b/jans-cedarling/bindings/cedarling_uniffi/src/tests.rs index f96ab562b58..3657aa179a9 100644 --- a/jans-cedarling/bindings/cedarling_uniffi/src/tests.rs +++ b/jans-cedarling/bindings/cedarling_uniffi/src/tests.rs @@ -60,7 +60,9 @@ fn test_authorize_unsigned_success() { principal, r#"Jans::Action::"UpdateTestPrincipal""#.to_string(), resource, - JsonValue("{}".to_string()), + JsonValue { + value: "{}".to_string(), + }, ) .expect("Should be executed successfully."); @@ -83,7 +85,7 @@ fn test_load_from_json_with_archive_bytes_rejects_invalid() { let config = std::fs::read_to_string("../../bindings/cedarling_uniffi/test_files/bootstrap.json") .expect("bootstrap.json should be readable"); - let result = Cedarling::load_from_json_with_archive_bytes(config, vec![0x00, 0x01, 0x02, 0x03]); + let result = Cedarling::load_from_json_with_archive_bytes(config, &[0x00, 0x01, 0x02, 0x03]); assert!( matches!(&result, Err(CedarlingError::InitializationFailed { .. })), "invalid archive bytes should yield InitializationFailed, is_ok={}", @@ -99,7 +101,9 @@ fn test_data_api_push_and_get() { cedarling .push_data_ctx( "key1".to_string(), - JsonValue(r#""value1""#.to_string()), + JsonValue { + value: r#""value1""#.to_string(), + }, None, ) .expect("push_data_ctx should succeed"); @@ -108,7 +112,7 @@ fn test_data_api_push_and_get() { .get_data_ctx("key1".to_string()) .expect("get_data_ctx should succeed"); assert!(result.is_some(), "result should not be None"); - let value: String = serde_json::from_str(&result.unwrap().0) + let value: String = serde_json::from_str(&result.unwrap().value) .expect("result should be deserializable to string"); assert_eq!(value, "value1", "retrieved value should match pushed value"); @@ -116,7 +120,9 @@ fn test_data_api_push_and_get() { cedarling .push_data_ctx( "key2".to_string(), - JsonValue(r#"{"nested": "data"}"#.to_string()), + JsonValue { + value: r#"{"nested": "data"}"#.to_string(), + }, Some(60), ) .expect("push_data_ctx with TTL should succeed"); @@ -125,8 +131,8 @@ fn test_data_api_push_and_get() { .get_data_ctx("key2".to_string()) .expect("get_data_ctx should succeed"); assert!(result2.is_some(), "result should not be None"); - let value2: serde_json::Value = - serde_json::from_str(&result2.unwrap().0).expect("result should be deserializable to JSON"); + let value2: serde_json::Value = serde_json::from_str(&result2.unwrap().value) + .expect("result should be deserializable to JSON"); assert_eq!( value2, serde_json::json!({"nested": "data"}), @@ -137,7 +143,9 @@ fn test_data_api_push_and_get() { cedarling .push_data_ctx( "key3".to_string(), - JsonValue(r#"[1, 2, 3]"#.to_string()), + JsonValue { + value: r#"[1, 2, 3]"#.to_string(), + }, None, ) .expect("push_data_ctx should succeed"); @@ -146,7 +154,7 @@ fn test_data_api_push_and_get() { .get_data_ctx("key3".to_string()) .expect("get_data_ctx should succeed"); assert!(result3.is_some(), "result should not be None"); - let value3: Vec = serde_json::from_str(&result3.unwrap().0) + let value3: Vec = serde_json::from_str(&result3.unwrap().value) .expect("result should be deserializable to array"); assert_eq!( value3, @@ -162,7 +170,9 @@ fn test_data_api_get_data_entry_ctx() { cedarling .push_data_ctx( "test_key".to_string(), - JsonValue(r#"{"foo": "bar"}"#.to_string()), + JsonValue { + value: r#"{"foo": "bar"}"#.to_string(), + }, None, ) .expect("push_data_ctx should succeed"); @@ -187,7 +197,9 @@ fn test_data_api_remove_data_ctx() { cedarling .push_data_ctx( "to_remove".to_string(), - JsonValue(r#""data""#.to_string()), + JsonValue { + value: r#""data""#.to_string(), + }, None, ) .expect("push_data_ctx should succeed"); @@ -227,21 +239,27 @@ fn test_data_api_clear_data_ctx() { cedarling .push_data_ctx( "key1".to_string(), - JsonValue(r#""value1""#.to_string()), + JsonValue { + value: r#""value1""#.to_string(), + }, None, ) .expect("push_data_ctx should succeed"); cedarling .push_data_ctx( "key2".to_string(), - JsonValue(r#""value2""#.to_string()), + JsonValue { + value: r#""value2""#.to_string(), + }, None, ) .expect("push_data_ctx should succeed"); cedarling .push_data_ctx( "key3".to_string(), - JsonValue(r#""value3""#.to_string()), + JsonValue { + value: r#""value3""#.to_string(), + }, None, ) .expect("push_data_ctx should succeed"); @@ -302,21 +320,27 @@ fn test_data_api_list_data_ctx() { cedarling .push_data_ctx( "key1".to_string(), - JsonValue(r#""value1""#.to_string()), + JsonValue { + value: r#""value1""#.to_string(), + }, None, ) .expect("push_data_ctx should succeed"); cedarling .push_data_ctx( "key2".to_string(), - JsonValue(r#"{"nested": "data"}"#.to_string()), + JsonValue { + value: r#"{"nested": "data"}"#.to_string(), + }, None, ) .expect("push_data_ctx should succeed"); cedarling .push_data_ctx( "key3".to_string(), - JsonValue(r#"[1, 2, 3]"#.to_string()), + JsonValue { + value: r#"[1, 2, 3]"#.to_string(), + }, None, ) .expect("push_data_ctx should succeed"); @@ -353,14 +377,18 @@ fn test_data_api_get_stats_ctx() { cedarling .push_data_ctx( "key1".to_string(), - JsonValue(r#""value1""#.to_string()), + JsonValue { + value: r#""value1""#.to_string(), + }, None, ) .expect("push_data_ctx should succeed"); cedarling .push_data_ctx( "key2".to_string(), - JsonValue(r#""value2""#.to_string()), + JsonValue { + value: r#""value2""#.to_string(), + }, None, ) .expect("push_data_ctx should succeed"); @@ -378,7 +406,13 @@ fn test_data_api_get_stats_ctx() { fn test_data_api_invalid_key() { let cedarling = create_test_cedarling(); - let result = cedarling.push_data_ctx("".to_string(), JsonValue(r#""value""#.to_string()), None); + let result = cedarling.push_data_ctx( + "".to_string(), + JsonValue { + value: r#""value""#.to_string(), + }, + None, + ); result.expect_err("push_data_ctx with empty key should fail"); } @@ -451,7 +485,9 @@ fn batch_item(resource_id: &str) -> BatchItem { BatchItem { resource: batch_resource(resource_id), action: r#"Jans::Action::"UpdateTestPrincipal""#.to_string(), - context: Some(JsonValue("{}".to_string())), + context: Some(JsonValue { + value: "{}".to_string(), + }), } } @@ -465,7 +501,9 @@ fn test_authorize_unsigned_batch_ordered_mixed_decisions() { let bad_item = BatchItem { resource: batch_resource("bad-1"), action: "this is not a valid uid".to_string(), - context: Some(JsonValue("{}".to_string())), + context: Some(JsonValue { + value: "{}".to_string(), + }), }; let items = vec![ok_item, bad_item, batch_item("ok-2")]; @@ -584,7 +622,9 @@ fn multi_issuer_item(id: &str) -> BatchItem { BatchItem { resource: multi_issuer_resource(id), action: r#"Jans::Action::"Update""#.to_string(), - context: Some(JsonValue("{}".to_string())), + context: Some(JsonValue { + value: "{}".to_string(), + }), } } @@ -672,7 +712,9 @@ fn test_authorize_multi_issuer_batch_bad_action_surfaces_error_at_that_item() { BatchItem { resource: multi_issuer_resource("bad-1"), action: "this is not a valid uid".to_string(), - context: Some(JsonValue("{}".to_string())), + context: Some(JsonValue { + value: "{}".to_string(), + }), }, multi_issuer_item("ok-2"), ];