From 4b8f1dd1af406bb8ef3d9d817d2d87c9a96f8472 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Fri, 8 May 2020 23:46:36 +0200 Subject: [PATCH 01/20] upgrade async-std to 1.6 beta --- Cargo.toml | 4 +-- src/cache/default_cache.rs | 63 +++++++++++++++----------------------- src/cache/mod.rs | 11 +++---- src/cached_enforcer.rs | 4 +-- src/emitter.rs | 16 +--------- 5 files changed, 35 insertions(+), 63 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f66e7b89..56f1e533 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ ip_network = "0.3.4" ttl_cache = "0.5.1" lazy_static = "1.4.0" indexmap = "1.3.1" -async-std = { version = "1.5.0", optional = true } +async-std = { version = "1.6.0-beta.1", optional = true } async-trait = "0.1.24" log = { version = "0.4.8", optional = true } tokio = { version = "0.2.11", optional = true, default-features = false } @@ -37,5 +37,5 @@ logging = ["log"] opt-level = 0 [dev-dependencies] -async-std = { version = "1.5.0", features = [ "attributes" ] } +async-std = { version = "1.6.0-beta.1", features = [ "attributes" ] } tokio = { version = "0.2.11", features = [ "full" ] } diff --git a/src/cache/default_cache.rs b/src/cache/default_cache.rs index 035961cd..cff91e3b 100644 --- a/src/cache/default_cache.rs +++ b/src/cache/default_cache.rs @@ -1,10 +1,8 @@ use crate::cache::Cache; -use async_trait::async_trait; use ttl_cache::TtlCache; -use std::hash::Hash; -use std::time::Duration; +use std::{hash::Hash, time::Duration}; pub struct DefaultCache where @@ -28,7 +26,6 @@ where } } -#[async_trait] impl Cache for DefaultCache where K: Eq + Hash + Send + Sync + 'static, @@ -42,22 +39,22 @@ where self.ttl = ttl; } - async fn get<'a>(&'a self, k: &K) -> Option<&'a V> { + fn get<'a>(&'a self, k: &K) -> Option<&'a V> { self.cache.get(k) } - async fn has(&self, k: &K) -> bool { + fn has(&self, k: &K) -> bool { self.cache.contains_key(k) } - async fn set(&mut self, k: K, v: V) { - if self.has(&k).await { + fn set(&mut self, k: K, v: V) { + if self.has(&k) { self.cache.remove(&k); } self.cache.insert(k, v, self.ttl); } - async fn clear(&mut self) { + fn clear(&mut self) { self.cache.clear(); } } @@ -67,54 +64,44 @@ mod tests { use super::*; use std::thread::sleep; - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] - async fn test_set_and_get() { + fn test_set_and_get() { let mut cache = DefaultCache::new(1); - cache.set(vec!["alice", "/data1", "read"], false).await; - assert!(cache.get(&vec!["alice", "/data1", "read"]).await == Some(&false)); + cache.set(vec!["alice", "/data1", "read"], false); + assert!(cache.get(&vec!["alice", "/data1", "read"]) == Some(&false)); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] - async fn test_set_ttl() { + fn test_set_ttl() { let mut cache = DefaultCache::new(1); cache.set_ttl(Duration::from_secs(2)); - cache.set(vec!["alice", "/data1", "read"], false).await; + cache.set(vec!["alice", "/data1", "read"], false); sleep(Duration::from_secs(1)); - assert!(cache.get(&vec!["alice", "/data1", "read"]).await == Some(&false)); + assert!(cache.get(&vec!["alice", "/data1", "read"]) == Some(&false)); sleep(Duration::from_secs(2)); - assert!(!cache.has(&vec!["alice", "/data1", "read"]).await); + assert!(!cache.has(&vec!["alice", "/data1", "read"])); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] - async fn test_capacity() { + fn test_capacity() { let mut cache = DefaultCache::new(1); - cache.set(vec!["alice", "/data1", "read"], false).await; - cache.set(vec!["bob", "/data2", "write"], false).await; - assert!(!cache.has(&vec!["alice", "/data1", "read"]).await); - assert!(cache.has(&vec!["bob", "/data2", "write"]).await); + cache.set(vec!["alice", "/data1", "read"], false); + cache.set(vec!["bob", "/data2", "write"], false); + assert!(!cache.has(&vec!["alice", "/data1", "read"])); + assert!(cache.has(&vec!["bob", "/data2", "write"])); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] - async fn test_set_capacity() { + fn test_set_capacity() { let mut cache = DefaultCache::new(1); cache.set_capacity(2); - cache.set(vec!["alice", "/data1", "read"], false).await; - cache.set(vec!["bob", "/data2", "write"], false).await; - cache - .set(vec!["unknow", "/data3", "read_write"], false) - .await; - assert!(!cache.has(&vec!["alice", "/data1", "read"]).await); - assert!(cache.has(&vec!["bob", "/data2", "write"]).await); - assert!(cache.has(&vec!["unknow", "/data3", "read_write"]).await); + cache.set(vec!["alice", "/data1", "read"], false); + cache.set(vec!["bob", "/data2", "write"], false); + cache.set(vec!["unknow", "/data3", "read_write"], false); + assert!(!cache.has(&vec!["alice", "/data1", "read"])); + assert!(cache.has(&vec!["bob", "/data2", "write"])); + assert!(cache.has(&vec!["unknow", "/data3", "read_write"])); } } diff --git a/src/cache/mod.rs b/src/cache/mod.rs index 0b2aecda..ee5cb998 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -1,7 +1,6 @@ use async_trait::async_trait; -use std::hash::Hash; -use std::time::Duration; +use std::{hash::Hash, time::Duration}; pub mod default_cache; @@ -14,8 +13,8 @@ where { fn set_capacity(&mut self, c: usize); fn set_ttl(&mut self, t: Duration); - async fn get(&self, k: &K) -> Option<&V>; - async fn has(&self, k: &K) -> bool; - async fn set(&mut self, k: K, v: V); - async fn clear(&mut self); + fn get(&self, k: &K) -> Option<&V>; + fn has(&self, k: &K) -> bool; + fn set(&mut self, k: K, v: V); + fn clear(&mut self); } diff --git a/src/cached_enforcer.rs b/src/cached_enforcer.rs index a48ed84d..eacad331 100644 --- a/src/cached_enforcer.rs +++ b/src/cached_enforcer.rs @@ -169,11 +169,11 @@ impl CoreApi for CachedEnforcer { }; #[allow(unused_variables)] - let (res, is_cached) = if let Some(result) = self.cache.get(&key).await { + let (res, is_cached) = if let Some(result) = self.cache.get(&key) { (*result, true) } else { let result = self.enforcer.enforce(rvals).await?; - self.cache.set(key.clone(), result).await; + self.cache.set(key.clone(), result); (result, false) }; diff --git a/src/emitter.rs b/src/emitter.rs index da6d474e..a25bc343 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -66,19 +66,5 @@ pub(crate) fn clear_cache(ce: &mut T, d: EventData) { ce.get_logger().print_mgmt_log(&d); } - #[cfg(feature = "runtime-tokio")] - { - tokio::runtime::Builder::new() - .basic_scheduler() - .threaded_scheduler() - .enable_all() - .build() - .unwrap() - .block_on(async { ce.get_mut_cache().clear().await }); - } - - #[cfg(feature = "runtime-async-std")] - { - async_std::task::block_on(async { ce.get_mut_cache().clear().await }); - } + ce.get_mut_cache().clear(); } From 75650b8adfbea5d2b3b73908acd7504d336bfa0d Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 12:30:51 +0200 Subject: [PATCH 02/20] add ip feature --- Cargo.toml | 3 ++- src/model/function_map.rs | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 56f1e533..b2164022 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ keywords = ["auth", "authorization", "rbac", "acl", "abac"] [dependencies] regex = "1.3.1" rhai = { version = "0.13.0", default-features = false, features = ["sync", "only_i32", "no_function", "no_float"] } -ip_network = "0.3.4" +ip_network = { version = "0.3.4", optional = true } ttl_cache = "0.5.1" lazy_static = "1.4.0" indexmap = "1.3.1" @@ -32,6 +32,7 @@ default = ["runtime-async-std"] runtime-tokio = ["tokio/fs", "tokio/io-util", "tokio/stream", "tokio/rt-threaded", "tokio/blocking"] runtime-async-std = ["async-std"] logging = ["log"] +ip = ["ip_network"] [profile.release.build-override] opt-level = 0 diff --git a/src/model/function_map.rs b/src/model/function_map.rs index f48d040b..8a853ee1 100644 --- a/src/model/function_map.rs +++ b/src/model/function_map.rs @@ -1,10 +1,11 @@ -#[cfg(feature = "runtime-async-std")] +#[cfg(all(feature = "runtime-async-std", feature = "ip"))] use async_std::net::IpAddr; #[cfg(feature = "runtime-tokio")] use std::net::IpAddr; use globset::GlobBuilder; +#[cfg(feature = "ip")] use ip_network::IpNetwork; use lazy_static::lazy_static; use regex::Regex; @@ -27,9 +28,13 @@ impl Default for FunctionMap { fm.insert("keyMatch2".to_owned(), key_match2); fm.insert("keyMatch3".to_owned(), key_match3); fm.insert("regexMatch".to_owned(), regex_match); - fm.insert("ipMatch".to_owned(), ip_match); fm.insert("globMatch".to_owned(), glob_match); + #[cfg(feature = "ip")] + { + fm.insert("ipMatch".to_owned(), ip_match); + } + FunctionMap { fm } } } @@ -92,6 +97,7 @@ pub fn regex_match(key1: String, key2: String) -> bool { // ip_match determines whether IP address ip1 matches the pattern of IP address ip2, ip2 can be an IP address or a CIDR pattern. // For example, "192.168.2.123" matches "192.168.2.0/24" +#[cfg(feature = "ip")] pub fn ip_match(key1: String, key2: String) -> bool { let key2_split = key2.splitn(2, '/').collect::>(); let ip_addr2 = key2_split[0]; From 0638598f7cebb22f23161fd986c9abaa9db13ae3 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 12:33:00 +0200 Subject: [PATCH 03/20] add glob feature --- Cargo.toml | 3 ++- src/model/function_map.rs | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b2164022..d061b4aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ async-std = { version = "1.6.0-beta.1", optional = true } async-trait = "0.1.24" log = { version = "0.4.8", optional = true } tokio = { version = "0.2.11", optional = true, default-features = false } -globset = "0.4.5" +globset = { version = "0.4.5", optional = true } thiserror = "1.0.14" [features] @@ -33,6 +33,7 @@ runtime-tokio = ["tokio/fs", "tokio/io-util", "tokio/stream", "tokio/rt-threaded runtime-async-std = ["async-std"] logging = ["log"] ip = ["ip_network"] +glob = ["globset"] [profile.release.build-override] opt-level = 0 diff --git a/src/model/function_map.rs b/src/model/function_map.rs index 8a853ee1..d8cc1aba 100644 --- a/src/model/function_map.rs +++ b/src/model/function_map.rs @@ -4,6 +4,7 @@ use async_std::net::IpAddr; #[cfg(feature = "runtime-tokio")] use std::net::IpAddr; +#[cfg(feature = "glob")] use globset::GlobBuilder; #[cfg(feature = "ip")] use ip_network::IpNetwork; @@ -28,7 +29,11 @@ impl Default for FunctionMap { fm.insert("keyMatch2".to_owned(), key_match2); fm.insert("keyMatch3".to_owned(), key_match3); fm.insert("regexMatch".to_owned(), regex_match); - fm.insert("globMatch".to_owned(), glob_match); + + #[cfg(feature = "glob")] + { + fm.insert("globMatch".to_owned(), glob_match); + } #[cfg(feature = "ip")] { @@ -126,6 +131,7 @@ pub fn ip_match(key1: String, key2: String) -> bool { } // glob_match determines whether key1 matches the pattern of key2 using glob pattern +#[cfg(feature = "glob")] pub fn glob_match(key1: String, key2: String) -> bool { GlobBuilder::new(key2.as_str()) .literal_separator(true) From bb8cd91df809835938ed087bec299683219c1184 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 12:45:32 +0200 Subject: [PATCH 04/20] add cacehd feature --- Cargo.toml | 3 ++- benches/benchmark.rs | 11 +++++++++++ src/emitter.rs | 6 +++++- src/internal_api.rs | 5 ++++- src/lib.rs | 6 ++++++ src/model/function_map.rs | 4 ++++ src/prelude.rs | 8 +++++--- 7 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d061b4aa..e1efddf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ keywords = ["auth", "authorization", "rbac", "acl", "abac"] regex = "1.3.1" rhai = { version = "0.13.0", default-features = false, features = ["sync", "only_i32", "no_function", "no_float"] } ip_network = { version = "0.3.4", optional = true } -ttl_cache = "0.5.1" +ttl_cache = { version = "0.5.1", optional = true } lazy_static = "1.4.0" indexmap = "1.3.1" async-std = { version = "1.6.0-beta.1", optional = true } @@ -34,6 +34,7 @@ runtime-async-std = ["async-std"] logging = ["log"] ip = ["ip_network"] glob = ["globset"] +cached = ["ttl_cache"] [profile.release.build-override] opt-level = 0 diff --git a/benches/benchmark.rs b/benches/benchmark.rs index fedf0a86..cb2e93a3 100644 --- a/benches/benchmark.rs +++ b/benches/benchmark.rs @@ -63,6 +63,7 @@ fn b_benchmark_basic_model(b: &mut Bencher) { }); } +#[cfg(feature = "cached")] #[bench] fn b_benmark_cached_basic_model(b: &mut Bencher) { let mut e = await_future(CachedEnforcer::new( @@ -89,6 +90,7 @@ fn b_benchmark_rbac_model(b: &mut Bencher) { }); } +#[cfg(feature = "cached")] #[bench] fn b_benchmark_cached_rbac_model(b: &mut Bencher) { let mut e = await_future(CachedEnforcer::new( @@ -139,6 +141,7 @@ fn b_benchmark_rbac_model_small(b: &mut Bencher) { b.iter(|| await_future(e.enforce(&["user501", "data9", "read"])).unwrap()); } +#[cfg(feature = "cached")] #[bench] fn b_benchmark_cached_rbac_model_small(b: &mut Bencher) { let mut e = await_future(CachedEnforcer::new("examples/rbac_model.conf", ())).unwrap(); @@ -213,6 +216,7 @@ fn b_benchmark_rbac_model_medium(b: &mut Bencher) { b.iter(|| await_future(e.enforce(&["user5001", "data15", "read"])).unwrap()); } +#[cfg(feature = "cached")] #[bench] fn b_benchmark_cached_rbac_model_medium(b: &mut Bencher) { let mut e = await_future(CachedEnforcer::new("examples/rbac_model.conf", ())).unwrap(); @@ -287,6 +291,7 @@ fn b_benchmark_rbac_model_large(b: &mut Bencher) { b.iter(|| await_future(e.enforce(&["user50001", "data1500", "read"])).unwrap()); } +#[cfg(feature = "cached")] #[bench] fn b_benchmark_cached_rbac_model_large(b: &mut Bencher) { let mut e = await_future(CachedEnforcer::new("examples/rbac_model.conf", ())).unwrap(); @@ -335,6 +340,7 @@ fn b_benchmark_rbac_with_resource_roles(b: &mut Bencher) { b.iter(|| await_future(e.enforce(&["alice", "data1", "read"])).unwrap()); } +#[cfg(feature = "cached")] #[bench] fn b_benchmark_cached_rbac_with_resource_roles(b: &mut Bencher) { let mut e = await_future(CachedEnforcer::new( @@ -357,6 +363,7 @@ fn b_benchmark_rbac_model_with_domains(b: &mut Bencher) { b.iter(|| await_future(e.enforce(&["alice", "domain1", "data1", "read"])).unwrap()); } +#[cfg(feature = "cached")] #[bench] fn b_benchmark_cached_rbac_model_with_domains(b: &mut Bencher) { let mut e = await_future(CachedEnforcer::new( @@ -375,6 +382,7 @@ fn b_benchmark_abac_model(b: &mut Bencher) { b.iter(|| await_future(e.enforce(&["alice", r#"{"Owner": "alice"}"#, "read"])).unwrap()); } +#[cfg(feature = "cached")] #[bench] fn b_benchmark_cached_abac_model(b: &mut Bencher) { let mut e = await_future(CachedEnforcer::new("examples/abac_model.conf", ())).unwrap(); @@ -393,6 +401,7 @@ fn b_benchmark_key_match(b: &mut Bencher) { b.iter(|| await_future(e.enforce(&["alice", "/alice_data/resource1", "GET"])).unwrap()); } +#[cfg(feature = "cached")] #[bench] fn b_benchmark_cached_key_match(b: &mut Bencher) { let mut e = await_future(CachedEnforcer::new( @@ -415,6 +424,7 @@ fn b_benchmark_rbac_with_deny(b: &mut Bencher) { b.iter(|| await_future(e.enforce(&["alice", "data1", "read"])).unwrap()); } +#[cfg(feature = "cached")] #[bench] fn b_benchmark_cached_rbac_with_deny(b: &mut Bencher) { let mut e = await_future(CachedEnforcer::new( @@ -437,6 +447,7 @@ fn b_benchmark_priority_model(b: &mut Bencher) { b.iter(|| await_future(e.enforce(&["alice", "data1", "read"])).unwrap()); } +#[cfg(feature = "cached")] #[bench] fn b_benchmark_cached_priority_model(b: &mut Bencher) { let mut e = await_future(CachedEnforcer::new( diff --git a/src/emitter.rs b/src/emitter.rs index a25bc343..88f69fbe 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -1,4 +1,7 @@ -use crate::{cached_api::CachedApi, core_api::CoreApi}; +use crate::core_api::CoreApi; + +#[cfg(feature = "cached")] +use crate::cached_api::CachedApi; use std::{fmt, hash::Hash}; @@ -59,6 +62,7 @@ pub(crate) fn notify_watcher(e: &mut T, d: EventData) { } } +#[cfg(feature = "cached")] #[allow(unused_variables)] pub(crate) fn clear_cache(ce: &mut T, d: EventData) { #[cfg(feature = "logging")] diff --git a/src/internal_api.rs b/src/internal_api.rs index 4aa373ca..b58495c5 100644 --- a/src/internal_api.rs +++ b/src/internal_api.rs @@ -1,11 +1,13 @@ use crate::{ - cached_enforcer::CachedEnforcer, core_api::CoreApi, emitter::{Event, EventData, EventEmitter}, enforcer::Enforcer, Result, }; +#[cfg(feature = "cached")] +use crate::cached_enforcer::CachedEnforcer; + use async_trait::async_trait; #[async_trait] @@ -169,6 +171,7 @@ impl InternalApi for Enforcer { } } +#[cfg(feature = "cached")] #[async_trait] impl InternalApi for CachedEnforcer { async fn add_policy_internal( diff --git a/src/lib.rs b/src/lib.rs index efa15f24..0b41bcbc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,9 @@ mod adapter; +#[cfg(feature = "cached")] mod cache; +#[cfg(feature = "cached")] mod cached_api; +#[cfg(feature = "cached")] mod cached_enforcer; mod config; mod convert; @@ -22,8 +25,11 @@ pub mod error; pub mod prelude; pub use adapter::{Adapter, FileAdapter, Filter, MemoryAdapter, NullAdapter}; +#[cfg(feature = "cached")] pub use cache::{Cache, DefaultCache}; +#[cfg(feature = "cached")] pub use cached_api::CachedApi; +#[cfg(feature = "cached")] pub use cached_enforcer::CachedEnforcer; pub use convert::{TryIntoAdapter, TryIntoModel}; pub use core_api::CoreApi; diff --git a/src/model/function_map.rs b/src/model/function_map.rs index d8cc1aba..9ad36907 100644 --- a/src/model/function_map.rs +++ b/src/model/function_map.rs @@ -181,6 +181,7 @@ mod tests { assert!(!key_match3("/baz".to_owned(), "/foo".to_owned())); } + #[cfg(feature = "ip")] #[test] fn test_ip_match() { assert!(ip_match("::1".to_owned(), "::0:1".to_owned())); @@ -200,18 +201,21 @@ mod tests { )); } + #[cfg(feature = "ip")] #[test] #[should_panic] fn test_ip_match_panic_1() { assert!(ip_match("I am alice".to_owned(), "127.0.0.1".to_owned())); } + #[cfg(feature = "ip")] #[test] #[should_panic] fn test_ip_match_panic_2() { assert!(ip_match("127.0.0.1".to_owned(), "I am alice".to_owned())); } + #[cfg(feature = "glob")] #[test] fn test_glob_match() { assert!(glob_match("/abc/123".to_owned(), "/abc/*".to_owned())); diff --git a/src/prelude.rs b/src/prelude.rs index f455735a..26471122 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,5 +1,7 @@ pub use crate::{ - CachedApi, CachedEnforcer, CoreApi, DefaultModel, Enforcer, EventData, FileAdapter, Filter, - InternalApi, MemoryAdapter, MgmtApi, Model, NullAdapter, RbacApi, Result, TryIntoAdapter, - TryIntoModel, Watcher, + CoreApi, DefaultModel, Enforcer, EventData, FileAdapter, Filter, InternalApi, MemoryAdapter, + MgmtApi, Model, NullAdapter, RbacApi, Result, TryIntoAdapter, TryIntoModel, Watcher, }; + +#[cfg(feature = "cached")] +pub use crate::{CachedApi, CachedEnforcer}; From c0932d1c9e7c1e00c4459972cb0792a997e3d4f7 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 12:50:17 +0200 Subject: [PATCH 05/20] fix runtime-tokio clippy warnings --- Cargo.toml | 2 +- src/model/function_map.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e1efddf9..1555ae45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ thiserror = "1.0.14" [features] default = ["runtime-async-std"] -runtime-tokio = ["tokio/fs", "tokio/io-util", "tokio/stream", "tokio/rt-threaded", "tokio/blocking"] +runtime-tokio = ["tokio/fs", "tokio/io-util"] runtime-async-std = ["async-std"] logging = ["log"] ip = ["ip_network"] diff --git a/src/model/function_map.rs b/src/model/function_map.rs index 9ad36907..4d06c1c3 100644 --- a/src/model/function_map.rs +++ b/src/model/function_map.rs @@ -1,7 +1,7 @@ #[cfg(all(feature = "runtime-async-std", feature = "ip"))] use async_std::net::IpAddr; -#[cfg(feature = "runtime-tokio")] +#[cfg(all(feature = "runtime-tokio", feature = "ip"))] use std::net::IpAddr; #[cfg(feature = "glob")] From 47858f278d16538f4693ac04a3e5d92bfef799b1 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 13:14:37 +0200 Subject: [PATCH 06/20] add watcher feature --- Cargo.toml | 3 ++- src/cached_enforcer.rs | 9 ++++++++- src/core_api.rs | 12 +++++++++--- src/emitter.rs | 1 + src/enforcer.rs | 30 +++++++++++++++++++++++++---- src/internal_api.rs | 43 +++++++++++++++++++++++++++++------------- src/lib.rs | 2 ++ src/prelude.rs | 5 ++++- 8 files changed, 82 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1555ae45..c29cbd3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ globset = { version = "0.4.5", optional = true } thiserror = "1.0.14" [features] -default = ["runtime-async-std"] +default = ["runtime-async-std", "cached"] runtime-tokio = ["tokio/fs", "tokio/io-util"] runtime-async-std = ["async-std"] @@ -35,6 +35,7 @@ logging = ["log"] ip = ["ip_network"] glob = ["globset"] cached = ["ttl_cache"] +watcher = [] [profile.release.build-override] opt-level = 0 diff --git a/src/cached_enforcer.rs b/src/cached_enforcer.rs index eacad331..d933c1e7 100644 --- a/src/cached_enforcer.rs +++ b/src/cached_enforcer.rs @@ -9,10 +9,12 @@ use crate::{ enforcer::Enforcer, model::Model, rbac::RoleManager, - watcher::Watcher, Result, }; +#[cfg(feature = "watcher")] +use crate::watcher::Watcher; + #[cfg(feature = "logging")] use crate::Logger; @@ -92,16 +94,19 @@ impl CoreApi for CachedEnforcer { self.enforcer.get_mut_adapter() } + #[cfg(feature = "watcher")] #[inline] fn set_watcher(&mut self, w: Box) { self.enforcer.set_watcher(w); } + #[cfg(feature = "watcher")] #[inline] fn get_watcher(&self) -> Option<&dyn Watcher> { self.enforcer.get_watcher() } + #[cfg(feature = "watcher")] #[inline] fn get_mut_watcher(&mut self) -> Option<&mut dyn Watcher> { self.enforcer.get_mut_watcher() @@ -246,6 +251,7 @@ impl CoreApi for CachedEnforcer { .enable_auto_build_role_links(auto_build_role_links); } + #[cfg(feature = "watcher")] #[inline] fn enable_auto_notify_watcher(&mut self, auto_notify_watcher: bool) { self.enforcer @@ -257,6 +263,7 @@ impl CoreApi for CachedEnforcer { self.enforcer.has_auto_save_enabled() } + #[cfg(feature = "watcher")] #[inline] fn has_auto_notify_watcher_enabled(&self) -> bool { self.enforcer.has_auto_notify_watcher_enabled() diff --git a/src/core_api.rs b/src/core_api.rs index 63658e37..a1a55565 100644 --- a/src/core_api.rs +++ b/src/core_api.rs @@ -1,6 +1,7 @@ -use crate::{ - Adapter, Effector, Filter, Model, Result, RoleManager, TryIntoAdapter, TryIntoModel, Watcher, -}; +use crate::{Adapter, Effector, Filter, Model, Result, RoleManager, TryIntoAdapter, TryIntoModel}; + +#[cfg(feature = "watcher")] +use crate::Watcher; #[cfg(feature = "logging")] use crate::Logger; @@ -17,8 +18,11 @@ pub trait CoreApi: Sized + Send + Sync { fn get_mut_model(&mut self) -> &mut dyn Model; fn get_adapter(&self) -> &dyn Adapter; fn get_mut_adapter(&mut self) -> &mut dyn Adapter; + #[cfg(feature = "watcher")] fn set_watcher(&mut self, w: Box); + #[cfg(feature = "watcher")] fn get_watcher(&self) -> Option<&dyn Watcher>; + #[cfg(feature = "watcher")] fn get_mut_watcher(&mut self) -> Option<&mut dyn Watcher>; fn get_role_manager(&self) -> Arc>; fn set_role_manager(&mut self, rm: Arc>) -> Result<()>; @@ -43,7 +47,9 @@ pub trait CoreApi: Sized + Send + Sync { fn enable_auto_save(&mut self, auto_save: bool); fn enable_enforce(&mut self, enabled: bool); fn enable_auto_build_role_links(&mut self, auto_build_role_links: bool); + #[cfg(feature = "watcher")] fn enable_auto_notify_watcher(&mut self, auto_notify_watcher: bool); fn has_auto_save_enabled(&self) -> bool; + #[cfg(feature = "watcher")] fn has_auto_notify_watcher_enabled(&self) -> bool; } diff --git a/src/emitter.rs b/src/emitter.rs index 88f69fbe..ce32068c 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -51,6 +51,7 @@ where fn emit(&mut self, e: K, d: EventData); } +#[cfg(feature = "watcher")] pub(crate) fn notify_watcher(e: &mut T, d: EventData) { #[cfg(feature = "logging")] { diff --git a/src/enforcer.rs b/src/enforcer.rs index ca9107c1..df92dc53 100644 --- a/src/enforcer.rs +++ b/src/enforcer.rs @@ -3,16 +3,21 @@ use crate::{ convert::{TryIntoAdapter, TryIntoModel}, core_api::CoreApi, effector::{DefaultEffector, EffectKind, Effector}, - emitter::{notify_watcher, Event, EventData, EventEmitter}, + emitter::{Event, EventData, EventEmitter}, error::{Error, ModelError, PolicyError, RequestError}, management_api::MgmtApi, model::{FunctionMap, Model}, rbac::{DefaultRoleManager, RoleManager}, util::{escape_eval, ESC_E}, - watcher::Watcher, Result, }; +#[cfg(feature = "watcher")] +use crate::emitter::notify_watcher; + +#[cfg(feature = "watcher")] +use crate::watcher::Watcher; + #[cfg(feature = "logging")] use crate::{DefaultLogger, Logger}; @@ -81,7 +86,9 @@ pub struct Enforcer { pub(crate) enabled: bool, pub(crate) auto_save: bool, pub(crate) auto_build_role_links: bool, + #[cfg(feature = "watcher")] pub(crate) auto_notify_watcher: bool, + #[cfg(feature = "watcher")] pub(crate) watcher: Option>, pub(crate) events: HashMap>, pub(crate) engine: Engine, @@ -246,7 +253,9 @@ impl CoreApi for Enforcer { enabled: true, auto_save: true, auto_build_role_links: true, + #[cfg(feature = "watcher")] auto_notify_watcher: true, + #[cfg(feature = "watcher")] watcher: None, events: HashMap::new(), engine, @@ -265,7 +274,9 @@ impl CoreApi for Enforcer { enabled: true, auto_save: true, auto_build_role_links: true, + #[cfg(feature = "watcher")] auto_notify_watcher: true, + #[cfg(feature = "watcher")] watcher: None, events: HashMap::new(), engine, @@ -273,7 +284,10 @@ impl CoreApi for Enforcer { } }; - e.on(Event::PolicyChange, notify_watcher); + #[cfg(feature = "watcher")] + { + e.on(Event::PolicyChange, notify_watcher); + } e.load_policy().await?; @@ -313,6 +327,7 @@ impl CoreApi for Enforcer { &mut *self.adapter } + #[cfg(feature = "watcher")] #[inline] fn set_watcher(&mut self, w: Box) { self.watcher = Some(w); @@ -330,6 +345,7 @@ impl CoreApi for Enforcer { self.logger = l; } + #[cfg(feature = "watcher")] #[inline] fn get_watcher(&self) -> Option<&dyn Watcher> { if let Some(ref watcher) = self.watcher { @@ -339,6 +355,7 @@ impl CoreApi for Enforcer { } } + #[cfg(feature = "watcher")] #[inline] fn get_mut_watcher(&mut self) -> Option<&mut dyn Watcher> { if let Some(ref mut watcher) = self.watcher { @@ -481,7 +498,10 @@ impl CoreApi for Enforcer { policies.extend(gpolicies); - self.emit(Event::PolicyChange, EventData::SavePolicy(policies)); + #[cfg(feature = "watcher")] + { + self.emit(Event::PolicyChange, EventData::SavePolicy(policies)); + } Ok(()) } @@ -511,6 +531,7 @@ impl CoreApi for Enforcer { self.auto_build_role_links = auto_build_role_links; } + #[cfg(feature = "watcher")] #[inline] fn enable_auto_notify_watcher(&mut self, auto_notify_watcher: bool) { if !auto_notify_watcher { @@ -526,6 +547,7 @@ impl CoreApi for Enforcer { self.auto_save } + #[cfg(feature = "watcher")] #[inline] fn has_auto_notify_watcher_enabled(&self) -> bool { self.auto_notify_watcher diff --git a/src/internal_api.rs b/src/internal_api.rs index b58495c5..46ca0d53 100644 --- a/src/internal_api.rs +++ b/src/internal_api.rs @@ -63,8 +63,11 @@ impl InternalApi for Enforcer { } let rule_added = self.get_mut_model().add_policy(sec, ptype, rule.clone()); - if rule_added && self.has_auto_notify_watcher_enabled() { - self.emit(Event::PolicyChange, EventData::AddPolicy(rule)); + #[cfg(feature = "watcher")] + { + if rule_added && self.has_auto_notify_watcher_enabled() { + self.emit(Event::PolicyChange, EventData::AddPolicy(rule)); + } } Ok(rule_added) @@ -86,8 +89,11 @@ impl InternalApi for Enforcer { } let rules_added = self.get_mut_model().add_policies(sec, ptype, rules.clone()); - if rules_added && self.has_auto_notify_watcher_enabled() { - self.emit(Event::PolicyChange, EventData::AddPolicies(rules)); + #[cfg(feature = "watcher")] + { + if rules_added && self.has_auto_notify_watcher_enabled() { + self.emit(Event::PolicyChange, EventData::AddPolicies(rules)); + } } Ok(rules_added) @@ -109,8 +115,11 @@ impl InternalApi for Enforcer { } let rule_removed = self.get_mut_model().remove_policy(sec, ptype, rule.clone()); - if rule_removed && self.has_auto_notify_watcher_enabled() { - self.emit(Event::PolicyChange, EventData::RemovePolicy(rule)); + #[cfg(feature = "watcher")] + { + if rule_removed && self.has_auto_notify_watcher_enabled() { + self.emit(Event::PolicyChange, EventData::RemovePolicy(rule)); + } } Ok(rule_removed) @@ -134,8 +143,12 @@ impl InternalApi for Enforcer { let rules_removed = self .get_mut_model() .remove_policies(sec, ptype, rules.clone()); - if rules_removed && self.has_auto_notify_watcher_enabled() { - self.emit(Event::PolicyChange, EventData::RemovePolicies(rules)); + + #[cfg(feature = "watcher")] + { + if rules_removed && self.has_auto_notify_watcher_enabled() { + self.emit(Event::PolicyChange, EventData::RemovePolicies(rules)); + } } Ok(rules_removed) @@ -160,11 +173,15 @@ impl InternalApi for Enforcer { let (rules_removed, rules) = self.get_mut_model() .remove_filtered_policy(sec, ptype, field_index, field_values); - if rules_removed && self.has_auto_notify_watcher_enabled() { - self.emit( - Event::PolicyChange, - EventData::RemoveFilteredPolicy(rules.clone()), - ); + + #[cfg(feature = "watcher")] + { + if rules_removed && self.has_auto_notify_watcher_enabled() { + self.emit( + Event::PolicyChange, + EventData::RemoveFilteredPolicy(rules.clone()), + ); + } } Ok((rules_removed, rules)) diff --git a/src/lib.rs b/src/lib.rs index 0b41bcbc..e071367c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,7 @@ mod model; mod rbac; mod rbac_api; mod util; +#[cfg(feature = "watcher")] mod watcher; pub mod error; @@ -44,6 +45,7 @@ pub use management_api::MgmtApi; pub use model::{function_map, Assertion, DefaultModel, Model}; pub use rbac::{DefaultRoleManager, RoleManager}; pub use rbac_api::RbacApi; +#[cfg(feature = "watcher")] pub use watcher::Watcher; pub type Result = std::result::Result; diff --git a/src/prelude.rs b/src/prelude.rs index 26471122..6b862090 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,7 +1,10 @@ pub use crate::{ CoreApi, DefaultModel, Enforcer, EventData, FileAdapter, Filter, InternalApi, MemoryAdapter, - MgmtApi, Model, NullAdapter, RbacApi, Result, TryIntoAdapter, TryIntoModel, Watcher, + MgmtApi, Model, NullAdapter, RbacApi, Result, TryIntoAdapter, TryIntoModel, }; #[cfg(feature = "cached")] pub use crate::{CachedApi, CachedEnforcer}; + +#[cfg(feature = "watcher")] +pub use crate::Watcher; From 76045f9818b0bb580f12f9c0e790a3fc96ca8ebc Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 13:20:40 +0200 Subject: [PATCH 07/20] don't clone if watcher feature has been disabled --- Cargo.toml | 2 +- src/emitter.rs | 1 + src/internal_api.rs | 55 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c29cbd3b..a92bdb58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ globset = { version = "0.4.5", optional = true } thiserror = "1.0.14" [features] -default = ["runtime-async-std", "cached"] +default = ["runtime-async-std"] runtime-tokio = ["tokio/fs", "tokio/io-util"] runtime-async-std = ["async-std"] diff --git a/src/emitter.rs b/src/emitter.rs index ce32068c..bc6e9108 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "watcher")] use crate::core_api::CoreApi; #[cfg(feature = "cached")] diff --git a/src/internal_api.rs b/src/internal_api.rs index 46ca0d53..05a2589c 100644 --- a/src/internal_api.rs +++ b/src/internal_api.rs @@ -1,10 +1,13 @@ use crate::{ core_api::CoreApi, - emitter::{Event, EventData, EventEmitter}, + emitter::{Event, EventEmitter}, enforcer::Enforcer, Result, }; +#[cfg(feature = "watcher")] +use crate::emitter::EventData; + #[cfg(feature = "cached")] use crate::cached_enforcer::CachedEnforcer; @@ -62,7 +65,17 @@ impl InternalApi for Enforcer { return Ok(false); } - let rule_added = self.get_mut_model().add_policy(sec, ptype, rule.clone()); + let rule_added = self.get_mut_model().add_policy(sec, ptype, { + #[cfg(feature = "watcher")] + { + rule.clone() + } + + #[cfg(not(feature = "watcher"))] + { + rule + } + }); #[cfg(feature = "watcher")] { if rule_added && self.has_auto_notify_watcher_enabled() { @@ -88,7 +101,17 @@ impl InternalApi for Enforcer { return Ok(false); } - let rules_added = self.get_mut_model().add_policies(sec, ptype, rules.clone()); + let rules_added = self.get_mut_model().add_policies(sec, ptype, { + #[cfg(feature = "watcher")] + { + rules.clone() + } + + #[cfg(not(feature = "watcher"))] + { + rules + } + }); #[cfg(feature = "watcher")] { if rules_added && self.has_auto_notify_watcher_enabled() { @@ -114,7 +137,17 @@ impl InternalApi for Enforcer { return Ok(false); } - let rule_removed = self.get_mut_model().remove_policy(sec, ptype, rule.clone()); + let rule_removed = self.get_mut_model().remove_policy(sec, ptype, { + #[cfg(feature = "watcher")] + { + rule.clone() + } + + #[cfg(not(feature = "watcher"))] + { + rule + } + }); #[cfg(feature = "watcher")] { if rule_removed && self.has_auto_notify_watcher_enabled() { @@ -140,9 +173,17 @@ impl InternalApi for Enforcer { return Ok(false); } - let rules_removed = self - .get_mut_model() - .remove_policies(sec, ptype, rules.clone()); + let rules_removed = self.get_mut_model().remove_policies(sec, ptype, { + #[cfg(feature = "watcher")] + { + rules.clone() + } + + #[cfg(not(feature = "watcher"))] + { + rules + } + }); #[cfg(feature = "watcher")] { From 0385d58dec73699f597c361068c81efa05491141 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 13:36:35 +0200 Subject: [PATCH 08/20] use https://github.com/async-rs/async-std/pull/768 for fixing tests --- Cargo.toml | 4 ++-- src/cache/default_cache.rs | 8 ++++++++ src/emitter.rs | 2 +- src/enforcer.rs | 1 + src/internal_api.rs | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a92bdb58..96a7172f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ ip_network = { version = "0.3.4", optional = true } ttl_cache = { version = "0.5.1", optional = true } lazy_static = "1.4.0" indexmap = "1.3.1" -async-std = { version = "1.6.0-beta.1", optional = true } +async-std = { git = "https://github.com/async-rs/async-std", branch = "fix/file-block", optional = true } async-trait = "0.1.24" log = { version = "0.4.8", optional = true } tokio = { version = "0.2.11", optional = true, default-features = false } @@ -41,5 +41,5 @@ watcher = [] opt-level = 0 [dev-dependencies] -async-std = { version = "1.6.0-beta.1", features = [ "attributes" ] } +async-std = { git = "https://github.com/async-rs/async-std", branch = "fix/file-block", features = [ "attributes" ] } tokio = { version = "0.2.11", features = [ "full" ] } diff --git a/src/cache/default_cache.rs b/src/cache/default_cache.rs index cff91e3b..11efc463 100644 --- a/src/cache/default_cache.rs +++ b/src/cache/default_cache.rs @@ -64,6 +64,8 @@ mod tests { use super::*; use std::thread::sleep; + #[cfg(feature = "cached")] + #[test] fn test_set_and_get() { let mut cache = DefaultCache::new(1); @@ -71,6 +73,8 @@ mod tests { assert!(cache.get(&vec!["alice", "/data1", "read"]) == Some(&false)); } + #[cfg(feature = "cached")] + #[test] fn test_set_ttl() { let mut cache = DefaultCache::new(1); cache.set_ttl(Duration::from_secs(2)); @@ -84,6 +88,8 @@ mod tests { assert!(!cache.has(&vec!["alice", "/data1", "read"])); } + #[cfg(feature = "cached")] + #[test] fn test_capacity() { let mut cache = DefaultCache::new(1); @@ -93,6 +99,8 @@ mod tests { assert!(cache.has(&vec!["bob", "/data2", "write"])); } + #[cfg(feature = "cached")] + #[test] fn test_set_capacity() { let mut cache = DefaultCache::new(1); cache.set_capacity(2); diff --git a/src/emitter.rs b/src/emitter.rs index bc6e9108..31783e45 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -1,4 +1,4 @@ -#[cfg(feature = "watcher")] +#[cfg(any(feature = "watcher", feature = "cached"))] use crate::core_api::CoreApi; #[cfg(feature = "cached")] diff --git a/src/enforcer.rs b/src/enforcer.rs index df92dc53..073e777a 100644 --- a/src/enforcer.rs +++ b/src/enforcer.rs @@ -951,6 +951,7 @@ mod tests { ); } + #[cfg(feature = "ip")] #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn test_ip_match_model() { diff --git a/src/internal_api.rs b/src/internal_api.rs index 05a2589c..1a45a800 100644 --- a/src/internal_api.rs +++ b/src/internal_api.rs @@ -5,7 +5,7 @@ use crate::{ Result, }; -#[cfg(feature = "watcher")] +#[cfg(any(feature = "watcher", feature = "cached"))] use crate::emitter::EventData; #[cfg(feature = "cached")] From ceedc71f244d3790372cef7c83bc0dab73cccf12 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 13:42:32 +0200 Subject: [PATCH 09/20] activate all features for bench test over previous version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 96a7172f..4fe97ff9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ globset = { version = "0.4.5", optional = true } thiserror = "1.0.14" [features] -default = ["runtime-async-std"] +default = ["runtime-async-std", "watcher", "ip", "globset", "cached"] runtime-tokio = ["tokio/fs", "tokio/io-util"] runtime-async-std = ["async-std"] From 7b8ecdcf573bce48abcb38dd3cc1dc4e122e3497 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 14:57:02 +0200 Subject: [PATCH 10/20] benchmark pull_request and decrease the threshold --- .github/workflows/benchmark.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index e2845b98..86972cc4 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -1,5 +1,6 @@ name: Benchmark on: + pull_request: push: branches: - master @@ -23,7 +24,7 @@ jobs: github-token: ${{ secrets.PERSONAL_GITHUB_TOKEN }} auto-push: true # Show alert with commit comment on detecting possible performance regression - alert-threshold: '200%' + alert-threshold: '150%' comment-on-alert: true fail-on-alert: true alert-comment-cc-users: '@GopherJ' From c9b52d5b1e31eaa7f11acc49d6a0889cbbb3d501 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 15:20:43 +0200 Subject: [PATCH 11/20] switch to github actions --- .github/workflows/benchmark.yml | 1 + .github/workflows/ci.yml | 62 +++++++++++++++++++++++++++++++++ .github/workflows/coverage.yml | 33 ++++++++++++++++++ .travis.yml | 49 -------------------------- README.md | 4 +-- 5 files changed, 98 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/coverage.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 86972cc4..da388b2a 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -26,5 +26,6 @@ jobs: # Show alert with commit comment on detecting possible performance regression alert-threshold: '150%' comment-on-alert: true + comment-always: true fail-on-alert: true alert-comment-cc-users: '@GopherJ' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..1b46bffb --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,62 @@ +name: CI + +on: + pull_request: + push: + branches: + - master + +jobs: + build: + name: Auto Build CI + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@master + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: rustfmt, clippy + override: true + + - name: Install Dependencies + run: sudo apt-get install libssl-dev + + - name: Cargo Clean + uses: actions-rs/cargo@v1 + with: + command: clean + + - name: Cargo Build + uses: actions-rs/cargo@v1 + with: + command: build + + # Todo: https://github.com/rust-lang/cargo/issues/2980 + - name: Cargo Test For All Features Using async-std + uses: actions-rs/cargo@v1 + with: + command: test + args: --no-default-features --features runtime-async-std, cached, glob, ip, watcher, logging + + - name: Cargo Test For All Features Using tokio + uses: actions-rs/cargo@v1 + with: + command: test + args: --no-default-features --features runtime-tokio, cached, glob, ip, watcher, logging + + - name: Cargo Clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings + + - name: Cargo Fmt Check + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..8c6e0f30 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,33 @@ +name: Coverage + +on: + pull_request: + push: + branches: + - master + +jobs: + cover: + name: Auto Codecov Coverage + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@master + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Run cargo-tarpaulin + uses: actions-rs/tarpaulin@v0.1 + with: + args: --out Xml + + - name: Upload to codecov.io + uses: codecov/codecov-action@v1 + with: + token: ${{secrets.CODECOV_TOKEN}} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f5d8a2c2..00000000 --- a/.travis.yml +++ /dev/null @@ -1,49 +0,0 @@ -language: rust -sudo: required -dist: trusty -addons: - apt: - packages: - - libssl-dev -cache: cargo -rust: - - stable - - nightly -matrix: - allow_failures: - - rust: nightly -before_script: -- rustup component add rustfmt -- rustup component add clippy -script: -- cargo clean -- cargo build -# Todo: https://github.com/rust-lang/cargo/issues/2980 -- cargo test --no-default-features --features runtime-async-std,logging -- cargo test --no-default-features --features runtime-tokio,logging -- cargo clippy -- -D warnings -- cargo fmt --all -- --check - -after_success: | - if [[ "$TRAVIS_RUST_VERSION" == nightly ]]; then - # upload report to codecov - docker run --security-opt seccomp=unconfined -v "$PWD:/volume" xd009642/tarpaulin sh -c "cargo tarpaulin --out Xml" - bash <(curl -s https://codecov.io/bash) - - if [[ "${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}" != "master" ]] && [[ "$TRAVIS_PULL_REQUEST" != false ]]; then - REMOTE_URL="$(git config --get remote.origin.url)"; - # Clone the repository fresh..for some reason checking out master fails - # from a normal PR build's provided directory - cd ${TRAVIS_BUILD_DIR}/.. && \ - git clone ${REMOTE_URL} "${TRAVIS_REPO_SLUG}-bench" && \ - cd "${TRAVIS_REPO_SLUG}-bench" && \ - git fetch origin +refs/pull/${TRAVIS_PULL_REQUEST}/merge - # Bench master - cargo bench > before && \ - # Bench PR - git checkout FETCH_HEAD && \ - cargo bench > after && \ - cargo install cargo-benchcmp --force && \ - cargo benchcmp before after - fi - fi diff --git a/README.md b/README.md index 9c34b84d..34621fc5 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ [![Crates.io](https://img.shields.io/crates/v/casbin.svg)](https://crates.io/crates/casbin) [![crates.io](https://img.shields.io/crates/d/casbin)](https://crates.io/crates/casbin) [![Docs](https://docs.rs/casbin/badge.svg)](https://docs.rs/casbin) -[![Build Status](https://travis-ci.org/casbin/casbin-rs.svg?branch=master)](https://travis-ci.org/casbin/casbin-rs) -[![codecov](https://codecov.io/gh/casbin/casbin-rs/branch/master/graph/badge.svg)](https://codecov.io/gh/casbin/casbin-rs) +[![CI](https://github.com/casbin/casbin-rs/workflows/CI/badge.svg)](https://github.com/casbin/casbin-rs/actions) +[![Codecov](https://codecov.io/gh/casbin/casbin-rs/branch/master/graph/badge.svg)](https://codecov.io/gh/casbin/casbin-rs) **Casbin-RS** is a powerful and efficient open-source access control library for Rust projects. It provides support for enforcing authorization based on various [access control models](https://en.wikipedia.org/wiki/Computer_security_model). From 0849a6f6945ddd633033ac756614000501f44bd7 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 15:26:29 +0200 Subject: [PATCH 12/20] fix typo --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4fe97ff9..d71f7126 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ globset = { version = "0.4.5", optional = true } thiserror = "1.0.14" [features] -default = ["runtime-async-std", "watcher", "ip", "globset", "cached"] +default = ["runtime-async-std", "watcher", "ip", "glob", "cached"] runtime-tokio = ["tokio/fs", "tokio/io-util"] runtime-async-std = ["async-std"] From c4cdbc1d5186897deea97428c997957c29ecd359 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 15:31:50 +0200 Subject: [PATCH 13/20] Fix: cargo test features doesn't like space --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b46bffb..2fe77616 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,13 +41,13 @@ jobs: uses: actions-rs/cargo@v1 with: command: test - args: --no-default-features --features runtime-async-std, cached, glob, ip, watcher, logging + args: --no-default-features --features runtime-async-std,cached,glob,ip,watcher,logging - name: Cargo Test For All Features Using tokio uses: actions-rs/cargo@v1 with: command: test - args: --no-default-features --features runtime-tokio, cached, glob, ip, watcher, logging + args: --no-default-features --features runtime-tokio,cached,glob,ip,watcher,logging - name: Cargo Clippy uses: actions-rs/cargo@v1 From 43c565bd874197e112e17c0f5cad9592e6dee2b2 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 19:03:36 +0200 Subject: [PATCH 14/20] better management of feature:logging and feature:watcher --- Cargo.toml | 2 +- src/emitter.rs | 25 ++++++----- src/enforcer.rs | 12 ++--- src/internal_api.rs | 106 +++++++++++++++++++++++++++++++------------- 4 files changed, 96 insertions(+), 49 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d71f7126..96a7172f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ globset = { version = "0.4.5", optional = true } thiserror = "1.0.14" [features] -default = ["runtime-async-std", "watcher", "ip", "glob", "cached"] +default = ["runtime-async-std"] runtime-tokio = ["tokio/fs", "tokio/io-util"] runtime-async-std = ["async-std"] diff --git a/src/emitter.rs b/src/emitter.rs index 31783e45..4ac4af9f 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -1,4 +1,4 @@ -#[cfg(any(feature = "watcher", feature = "cached"))] +#[cfg(any(feature = "watcher", feature = "cached", feature = "logging"))] use crate::core_api::CoreApi; #[cfg(feature = "cached")] @@ -52,25 +52,28 @@ where fn emit(&mut self, e: K, d: EventData); } -#[cfg(feature = "watcher")] -pub(crate) fn notify_watcher(e: &mut T, d: EventData) { +#[cfg(any(feature = "logging", feature = "watcher"))] +pub(crate) fn notify_logger_and_watcher(e: &mut T, d: EventData) { #[cfg(feature = "logging")] { e.get_logger().print_mgmt_log(&d); } - if let Some(w) = e.get_mut_watcher() { - w.update(d); + #[cfg(feature = "watcher")] + { + if let Some(w) = e.get_mut_watcher() { + w.update(d); + } } } -#[cfg(feature = "cached")] -#[allow(unused_variables)] +#[cfg(all(feature = "cached", feature = "logging"))] pub(crate) fn clear_cache(ce: &mut T, d: EventData) { - #[cfg(feature = "logging")] - { - ce.get_logger().print_mgmt_log(&d); - } + ce.get_logger().print_mgmt_log(&d); + ce.get_mut_cache().clear(); +} +#[cfg(all(feature = "cached", not(feature = "logging")))] +pub(crate) fn clear_cache(ce: &mut T, _d: EventData) { ce.get_mut_cache().clear(); } diff --git a/src/enforcer.rs b/src/enforcer.rs index 073e777a..9cac6aea 100644 --- a/src/enforcer.rs +++ b/src/enforcer.rs @@ -12,8 +12,8 @@ use crate::{ Result, }; -#[cfg(feature = "watcher")] -use crate::emitter::notify_watcher; +#[cfg(any(feature = "logging", feature = "watcher"))] +use crate::emitter::notify_logger_and_watcher; #[cfg(feature = "watcher")] use crate::watcher::Watcher; @@ -284,9 +284,9 @@ impl CoreApi for Enforcer { } }; - #[cfg(feature = "watcher")] + #[cfg(any(feature = "logging", feature = "watcher"))] { - e.on(Event::PolicyChange, notify_watcher); + e.on(Event::PolicyChange, notify_logger_and_watcher); } e.load_policy().await?; @@ -498,7 +498,7 @@ impl CoreApi for Enforcer { policies.extend(gpolicies); - #[cfg(feature = "watcher")] + #[cfg(any(feature = "logging", feature = "watcher"))] { self.emit(Event::PolicyChange, EventData::SavePolicy(policies)); } @@ -537,7 +537,7 @@ impl CoreApi for Enforcer { if !auto_notify_watcher { self.off(Event::PolicyChange); } else { - self.on(Event::PolicyChange, notify_watcher); + self.on(Event::PolicyChange, notify_logger_and_watcher); } self.auto_notify_watcher = auto_notify_watcher; } diff --git a/src/internal_api.rs b/src/internal_api.rs index 1a45a800..d97cecb1 100644 --- a/src/internal_api.rs +++ b/src/internal_api.rs @@ -5,7 +5,7 @@ use crate::{ Result, }; -#[cfg(any(feature = "watcher", feature = "cached"))] +#[cfg(any(feature = "watcher", feature = "cached", feature = "logging"))] use crate::emitter::EventData; #[cfg(feature = "cached")] @@ -66,20 +66,28 @@ impl InternalApi for Enforcer { } let rule_added = self.get_mut_model().add_policy(sec, ptype, { - #[cfg(feature = "watcher")] + #[cfg(any(feature = "watcher", feature = "logging"))] { rule.clone() } - - #[cfg(not(feature = "watcher"))] + #[cfg(all(not(feature = "watcher"), not(feature = "logging")))] { rule } }); - #[cfg(feature = "watcher")] + #[cfg(any(feature = "watcher", feature = "logging"))] { - if rule_added && self.has_auto_notify_watcher_enabled() { - self.emit(Event::PolicyChange, EventData::AddPolicy(rule)); + #[cfg(feature = "watcher")] + { + if rule_added && self.has_auto_notify_watcher_enabled() { + self.emit(Event::PolicyChange, EventData::AddPolicy(rule)); + } + } + #[cfg(not(feature = "watcher"))] + { + if rule_added { + self.emit(Event::PolicyChange, EventData::AddPolicy(rule)); + } } } @@ -102,20 +110,28 @@ impl InternalApi for Enforcer { } let rules_added = self.get_mut_model().add_policies(sec, ptype, { - #[cfg(feature = "watcher")] + #[cfg(any(feature = "watcher", feature = "logging"))] { rules.clone() } - - #[cfg(not(feature = "watcher"))] + #[cfg(all(not(feature = "watcher"), not(feature = "logging")))] { rules } }); - #[cfg(feature = "watcher")] + #[cfg(any(feature = "watcher", feature = "logging"))] { - if rules_added && self.has_auto_notify_watcher_enabled() { - self.emit(Event::PolicyChange, EventData::AddPolicies(rules)); + #[cfg(feature = "watcher")] + { + if rules_added && self.has_auto_notify_watcher_enabled() { + self.emit(Event::PolicyChange, EventData::AddPolicies(rules)); + } + } + #[cfg(not(feature = "watcher"))] + { + if rules_added { + self.emit(Event::PolicyChange, EventData::AddPolicies(rules)); + } } } @@ -138,20 +154,28 @@ impl InternalApi for Enforcer { } let rule_removed = self.get_mut_model().remove_policy(sec, ptype, { - #[cfg(feature = "watcher")] + #[cfg(any(feature = "watcher", feature = "logging"))] { rule.clone() } - - #[cfg(not(feature = "watcher"))] + #[cfg(all(not(feature = "watcher"), not(feature = "logging")))] { rule } }); - #[cfg(feature = "watcher")] + #[cfg(any(feature = "watcher", feature = "logging"))] { - if rule_removed && self.has_auto_notify_watcher_enabled() { - self.emit(Event::PolicyChange, EventData::RemovePolicy(rule)); + #[cfg(feature = "watcher")] + { + if rule_removed && self.has_auto_notify_watcher_enabled() { + self.emit(Event::PolicyChange, EventData::RemovePolicy(rule)); + } + } + #[cfg(not(feature = "watcher"))] + { + if rule_removed { + self.emit(Event::PolicyChange, EventData::RemovePolicy(rule)); + } } } @@ -174,21 +198,29 @@ impl InternalApi for Enforcer { } let rules_removed = self.get_mut_model().remove_policies(sec, ptype, { - #[cfg(feature = "watcher")] + #[cfg(any(feature = "watcher", feature = "logging"))] { rules.clone() } - - #[cfg(not(feature = "watcher"))] + #[cfg(all(not(feature = "watcher"), not(feature = "logging")))] { rules } }); - #[cfg(feature = "watcher")] + #[cfg(any(feature = "watcher", feature = "logging"))] { - if rules_removed && self.has_auto_notify_watcher_enabled() { - self.emit(Event::PolicyChange, EventData::RemovePolicies(rules)); + #[cfg(feature = "watcher")] + { + if rules_removed && self.has_auto_notify_watcher_enabled() { + self.emit(Event::PolicyChange, EventData::RemovePolicies(rules)); + } + } + #[cfg(not(feature = "watcher"))] + { + if rules_removed { + self.emit(Event::PolicyChange, EventData::RemovePolicies(rules)); + } } } @@ -215,13 +247,25 @@ impl InternalApi for Enforcer { self.get_mut_model() .remove_filtered_policy(sec, ptype, field_index, field_values); - #[cfg(feature = "watcher")] + #[cfg(any(feature = "watcher", feature = "logging"))] { - if rules_removed && self.has_auto_notify_watcher_enabled() { - self.emit( - Event::PolicyChange, - EventData::RemoveFilteredPolicy(rules.clone()), - ); + #[cfg(feature = "watcher")] + { + if rules_removed && self.has_auto_notify_watcher_enabled() { + self.emit( + Event::PolicyChange, + EventData::RemoveFilteredPolicy(rules.clone()), + ); + } + } + #[cfg(not(feature = "watcher"))] + { + if rules_removed { + self.emit( + Event::PolicyChange, + EventData::RemoveFilteredPolicy(rules.clone()), + ); + } } } From 3ac52effc9fcdbb37813aa87d1d4ec1e95617986 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 19:39:16 +0200 Subject: [PATCH 15/20] use async-std/master for testing --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 96a7172f..b19d3760 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ ip_network = { version = "0.3.4", optional = true } ttl_cache = { version = "0.5.1", optional = true } lazy_static = "1.4.0" indexmap = "1.3.1" -async-std = { git = "https://github.com/async-rs/async-std", branch = "fix/file-block", optional = true } +async-std = { git = "https://github.com/async-rs/async-std", optional = true } async-trait = "0.1.24" log = { version = "0.4.8", optional = true } tokio = { version = "0.2.11", optional = true, default-features = false } @@ -41,5 +41,5 @@ watcher = [] opt-level = 0 [dev-dependencies] -async-std = { git = "https://github.com/async-rs/async-std", branch = "fix/file-block", features = [ "attributes" ] } +async-std = { git = "https://github.com/async-rs/async-std", features = [ "attributes" ] } tokio = { version = "0.2.11", features = [ "full" ] } From c4c28fea2617503278e3c3498c0c25265867d619 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 23:04:05 +0200 Subject: [PATCH 16/20] add basic wasm32 support --- src/adapter/mod.rs | 2 ++ src/config.rs | 15 +++++++++------ src/convert.rs | 24 +++++++++++++++++++++--- src/lib.rs | 5 ++++- src/model/default_model.rs | 5 +++-- src/prelude.rs | 7 +++++-- 6 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/adapter/mod.rs b/src/adapter/mod.rs index e7633f78..b69d3f21 100644 --- a/src/adapter/mod.rs +++ b/src/adapter/mod.rs @@ -1,9 +1,11 @@ use async_trait::async_trait; +#[cfg(not(target_arch = "wasm32"))] pub mod file_adapter; pub mod memory_adapter; pub mod null_adapter; +#[cfg(not(target_arch = "wasm32"))] pub use file_adapter::FileAdapter; pub use memory_adapter::MemoryAdapter; pub use null_adapter::NullAdapter; diff --git a/src/config.rs b/src/config.rs index bea9cb26..bd0c3f4e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,19 +2,20 @@ use crate::Result; #[cfg(feature = "runtime-async-std")] use async_std::{ - fs::File, io::prelude::*, io::{BufReader, Cursor, Error as IoError, ErrorKind}, - path::Path, }; +#[cfg(all(feature = "runtime-async-std", not(target_arch = "wasm32")))] +use async_std::{fs::File, path::Path}; + #[cfg(feature = "runtime-tokio")] use std::{io::Cursor, path::Path}; #[cfg(feature = "runtime-tokio")] -use tokio::{ - fs::File, - io::{AsyncBufReadExt, AsyncReadExt, BufReader, Error as IoError, ErrorKind}, -}; +use tokio::io::{AsyncBufReadExt, AsyncReadExt, BufReader, Error as IoError, ErrorKind}; + +#[cfg(all(feature = "runtime-tokio", not(target_arch = "wasm32")))] +use tokio::fs::File; use std::collections::HashMap; @@ -28,6 +29,7 @@ pub(crate) struct Config { } impl Config { + #[cfg(not(target_arch = "wasm32"))] pub(crate) async fn from_file>(p: P) -> Result { let mut c = Config { data: HashMap::new(), @@ -47,6 +49,7 @@ impl Config { Ok(c) } + #[cfg(not(target_arch = "wasm32"))] async fn parse>(&mut self, p: P) -> Result<()> { let mut f = File::open(p).await?; let mut c = Vec::new(); diff --git a/src/convert.rs b/src/convert.rs index f6041a7d..e5b4f456 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -1,4 +1,7 @@ -use crate::{Adapter, DefaultModel, FileAdapter, Model, NullAdapter, Result}; +use crate::{Adapter, DefaultModel, Model, NullAdapter, Result}; + +#[cfg(not(target_arch = "wasm32"))] +use crate::FileAdapter; use async_trait::async_trait; @@ -15,7 +18,14 @@ pub trait TryIntoAdapter: Send + Sync { #[async_trait] impl TryIntoModel for &'static str { async fn try_into_model(self) -> Result> { - Ok(Box::new(DefaultModel::from_file(self).await?)) + #[cfg(not(target_arch = "wasm32"))] + { + Ok(Box::new(DefaultModel::from_file(self).await?)) + } + #[cfg(target_arch = "wasm32")] + { + Ok(Box::new(DefaultModel::from_str(self).await?)) + } } } @@ -36,7 +46,15 @@ where #[async_trait] impl TryIntoAdapter for &'static str { async fn try_into_adapter(self) -> Result> { - Ok(Box::new(FileAdapter::new(self))) + #[cfg(not(target_arch = "wasm32"))] + { + Ok(Box::new(FileAdapter::new(self))) + } + + #[cfg(target_arch = "wasm32")] + { + Ok(Box::new(NullAdapter)) + } } } diff --git a/src/lib.rs b/src/lib.rs index e071367c..8082c915 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,10 @@ mod watcher; pub mod error; pub mod prelude; -pub use adapter::{Adapter, FileAdapter, Filter, MemoryAdapter, NullAdapter}; +#[cfg(not(target_arch = "wasm32"))] +pub use adapter::FileAdapter; +pub use adapter::{Adapter, Filter, MemoryAdapter, NullAdapter}; + #[cfg(feature = "cached")] pub use cache::{Cache, DefaultCache}; #[cfg(feature = "cached")] diff --git a/src/model/default_model.rs b/src/model/default_model.rs index 69c0841e..216ef274 100644 --- a/src/model/default_model.rs +++ b/src/model/default_model.rs @@ -9,7 +9,7 @@ use crate::{ use indexmap::{IndexMap, IndexSet}; -#[cfg(feature = "runtime-async-std")] +#[cfg(all(feature = "runtime-async-std", not(target_arch = "wasm32")))] use async_std::path::Path; #[cfg(feature = "runtime-tokio")] @@ -26,6 +26,7 @@ pub struct DefaultModel { } impl DefaultModel { + #[cfg(not(target_arch = "wasm32"))] pub async fn from_file>(p: P) -> Result { let cfg = Config::from_file(p).await?; @@ -41,7 +42,7 @@ impl DefaultModel { Ok(model) } - pub async fn from_str(&mut self, s: &str) -> Result { + pub async fn from_str(s: &str) -> Result { let cfg = Config::from_str(s).await?; let mut model = DefaultModel::default(); diff --git a/src/prelude.rs b/src/prelude.rs index 6b862090..7ea7ff81 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,8 +1,11 @@ pub use crate::{ - CoreApi, DefaultModel, Enforcer, EventData, FileAdapter, Filter, InternalApi, MemoryAdapter, - MgmtApi, Model, NullAdapter, RbacApi, Result, TryIntoAdapter, TryIntoModel, + CoreApi, DefaultModel, Enforcer, EventData, Filter, InternalApi, MemoryAdapter, MgmtApi, Model, + NullAdapter, RbacApi, Result, TryIntoAdapter, TryIntoModel, }; +#[cfg(not(target_arch = "wasm32"))] +pub use crate::FileAdapter; + #[cfg(feature = "cached")] pub use crate::{CachedApi, CachedEnforcer}; From 195a40039d0809053391330c984c3b81701aae55 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 23:07:44 +0200 Subject: [PATCH 17/20] use runtime-async-std for wasm32 test --- .github/workflows/ci.yml | 8 ++++++++ Cargo.toml | 6 +++++- src/config.rs | 4 ++-- src/enforcer.rs | 30 +++++++++++++++--------------- src/management_api.rs | 12 ++++++------ src/model/default_model.rs | 32 ++++++++++++++++---------------- src/rbac_api.rs | 22 +++++++++++----------- 7 files changed, 63 insertions(+), 51 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2fe77616..3ed6460c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,14 @@ jobs: command: test args: --no-default-features --features runtime-tokio,cached,glob,ip,watcher,logging + - name: Cargo Check Wasm + uses: actions-rs/cargo@v1 + with: + command: check + target: wasm32-unknown-unknown + override: true + args: --no-default-features --features runtime-async-std,cached,glob,ip,watcher,logging + - name: Cargo Clippy uses: actions-rs/cargo@v1 with: diff --git a/Cargo.toml b/Cargo.toml index b19d3760..92546325 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,10 @@ watcher = [] [profile.release.build-override] opt-level = 0 -[dev-dependencies] +[target.'cfg(target_arch = "wasm32")'.dev-dependencies] +wasm-bindgen-test = "0.3.10" async-std = { git = "https://github.com/async-rs/async-std", features = [ "attributes" ] } + +[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] tokio = { version = "0.2.11", features = [ "full" ] } +async-std = { git = "https://github.com/async-rs/async-std", features = [ "attributes" ] } diff --git a/src/config.rs b/src/config.rs index bd0c3f4e..cfded295 100644 --- a/src/config.rs +++ b/src/config.rs @@ -215,7 +215,7 @@ mod tests { use super::*; #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_get() { let mut config = Config::from_file("examples/testini.ini").await.unwrap(); @@ -259,7 +259,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_from_text() { let text: &str = r#" # test config diff --git a/src/enforcer.rs b/src/enforcer.rs index 9cac6aea..984fd6db 100644 --- a/src/enforcer.rs +++ b/src/enforcer.rs @@ -574,7 +574,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_enforcer_swap_adapter_type() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); @@ -605,7 +605,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_key_match_model_in_memory() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); @@ -738,7 +738,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_key_match_model_in_memory_deny() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); @@ -762,7 +762,7 @@ mod tests { use crate::RbacApi; #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_rbac_model_in_memory_indeterminate() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); @@ -793,7 +793,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_rbac_model_in_memory() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); @@ -883,7 +883,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_not_used_rbac_model_in_memory() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); @@ -953,7 +953,7 @@ mod tests { #[cfg(feature = "ip")] #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_ip_match_model() { let m = DefaultModel::from_file("examples/ipmatch_model.conf") .await @@ -1029,7 +1029,7 @@ mod tests { use crate::MgmtApi; #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_enable_auto_save() { let m = DefaultModel::from_file("examples/basic_model.conf") .await @@ -1126,7 +1126,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_role_links() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -1143,7 +1143,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_get_and_set_model() { let m1 = DefaultModel::from_file("examples/basic_model.conf") .await @@ -1170,7 +1170,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_get_and_set_adapter_in_mem() { let m1 = DefaultModel::from_file("examples/basic_model.conf") .await @@ -1206,7 +1206,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_keymatch_custom_model() { use crate::model::key_match; @@ -1260,7 +1260,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_filtered_file_adapter() { let mut e = Enforcer::new( "examples/rbac_with_domains_model.conf", @@ -1304,7 +1304,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_set_role_manager() { let mut e = Enforcer::new( "examples/rbac_with_domains_model.conf", @@ -1336,7 +1336,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_policy_abac() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); diff --git a/src/management_api.rs b/src/management_api.rs index e76f14f1..23610d82 100644 --- a/src/management_api.rs +++ b/src/management_api.rs @@ -358,7 +358,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_modify_grouping_policy_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -466,7 +466,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_modify_policy_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -548,7 +548,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_get_policy_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -752,7 +752,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_get_list() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -771,7 +771,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_modify_policies_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -932,7 +932,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_modify_grouping_policies_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await diff --git a/src/model/default_model.rs b/src/model/default_model.rs index 216ef274..cd8eaf72 100644 --- a/src/model/default_model.rs +++ b/src/model/default_model.rs @@ -322,7 +322,7 @@ mod tests { use crate::prelude::*; #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_basic_model() { let m = DefaultModel::from_file("examples/basic_model.conf") .await @@ -342,7 +342,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_basic_model_no_policy() { let m = DefaultModel::from_file("examples/basic_model.conf") .await @@ -362,7 +362,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_basic_model_with_root() { let m = DefaultModel::from_file("examples/basic_with_root_model.conf") .await @@ -386,7 +386,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_basic_model_with_root_no_policy() { let m = DefaultModel::from_file("examples/basic_with_root_model.conf") .await @@ -410,7 +410,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_basic_model_without_users() { let m = DefaultModel::from_file("examples/basic_without_users_model.conf") .await @@ -426,7 +426,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_basic_model_without_resources() { let m = DefaultModel::from_file("examples/basic_without_resources_model.conf") .await @@ -442,7 +442,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_rbac_model() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -486,7 +486,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_rbac_model_with_resource_roles() { let m = DefaultModel::from_file("examples/rbac_with_resource_roles_model.conf") .await @@ -530,7 +530,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_rbac_model_with_domains() { let m = DefaultModel::from_file("examples/rbac_with_domains_model.conf") .await @@ -591,7 +591,7 @@ mod tests { use crate::MgmtApi; #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_rbac_model_with_domains_runtime() { let m = DefaultModel::from_file("examples/rbac_with_domains_model.conf") .await @@ -823,7 +823,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_rbac_model_with_domains_at_runtime_mock_adapter() { let m = DefaultModel::from_file("examples/rbac_with_domains_model.conf") .await @@ -901,7 +901,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_rbac_model_with_deny() { let m = DefaultModel::from_file("examples/rbac_with_deny_model.conf") .await @@ -945,7 +945,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_rbac_model_with_not_deny() { let m = DefaultModel::from_file("examples/rbac_with_not_deny_model.conf") .await @@ -961,7 +961,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_rbac_model_with_custom_data() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -1056,7 +1056,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_rbac_model_using_in_op() { let m = DefaultModel::from_file("examples/rbac_model_matcher_using_in_op.conf") .await @@ -1100,7 +1100,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_abac() { let m = DefaultModel::from_file("examples/abac_model.conf") .await diff --git a/src/rbac_api.rs b/src/rbac_api.rs index fe32cdbb..b3a7feb3 100644 --- a/src/rbac_api.rs +++ b/src/rbac_api.rs @@ -323,7 +323,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_role_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -480,7 +480,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_role_api_threads() { use std::sync::{Arc, RwLock}; use std::thread; @@ -824,7 +824,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_permission_api() { let m = DefaultModel::from_file("examples/basic_without_resources_model.conf") .await @@ -922,7 +922,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_implicit_role_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -951,7 +951,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_implicit_permission_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -986,7 +986,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_implicit_user_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -1040,7 +1040,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_implicit_permission_api_with_domain() { let m = DefaultModel::from_file("examples/rbac_with_domains_model.conf") .await @@ -1060,7 +1060,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_pattern_matching_fn() { let mut e = Enforcer::new( "examples/rbac_with_pattern_model.conf", @@ -1096,7 +1096,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_pattern_matching_fn_with_domain() { let mut e = Enforcer::new( "examples/rbac_with_pattern_domain_model.conf", @@ -1156,7 +1156,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_pattern_matching_basic_role() { let mut e = Enforcer::new( "examples/rbac_basic_role_model.conf", @@ -1198,7 +1198,7 @@ mod tests { } #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(feature = "runtime-tokio", tokio::test)] + #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] async fn test_implicit_users_for_permission() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); From a2d875eb81a9c1f9df042eae7cc071deed8d161d Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sat, 9 May 2020 23:23:21 +0200 Subject: [PATCH 18/20] fix clippy warnings --- src/model/default_model.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/model/default_model.rs b/src/model/default_model.rs index cd8eaf72..67003148 100644 --- a/src/model/default_model.rs +++ b/src/model/default_model.rs @@ -42,6 +42,7 @@ impl DefaultModel { Ok(model) } + #[allow(clippy::should_implement_trait)] pub async fn from_str(s: &str) -> Result { let cfg = Config::from_str(s).await?; From 85d834bc02605cb621aba34775a8bfe48f74ae36 Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sun, 10 May 2020 00:22:44 +0200 Subject: [PATCH 19/20] fix typo --- src/config.rs | 14 +++- src/enforcer.rs | 150 +++++++++++++++++++++++++++++-------- src/management_api.rs | 42 ++++++++--- src/model/default_model.rs | 112 +++++++++++++++++++-------- src/rbac_api.rs | 110 +++++++++++++++++++++------ 5 files changed, 328 insertions(+), 100 deletions(-) diff --git a/src/config.rs b/src/config.rs index cfded295..76378eb5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -214,8 +214,11 @@ impl Config { mod tests { use super::*; - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_get() { let mut config = Config::from_file("examples/testini.ini").await.unwrap(); @@ -258,8 +261,11 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_from_text() { let text: &str = r#" # test config diff --git a/src/enforcer.rs b/src/enforcer.rs index 984fd6db..72f795f9 100644 --- a/src/enforcer.rs +++ b/src/enforcer.rs @@ -573,8 +573,14 @@ mod tests { assert!(is_sync::()); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_enforcer_swap_adapter_type() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); @@ -604,8 +610,14 @@ mod tests { .unwrap()) } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_key_match_model_in_memory() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); @@ -737,8 +749,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_key_match_model_in_memory_deny() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); @@ -761,8 +779,14 @@ mod tests { } use crate::RbacApi; - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_rbac_model_in_memory_indeterminate() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); @@ -792,8 +816,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_rbac_model_in_memory() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); @@ -882,8 +912,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_not_used_rbac_model_in_memory() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); @@ -952,8 +988,14 @@ mod tests { } #[cfg(feature = "ip")] - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_ip_match_model() { let m = DefaultModel::from_file("examples/ipmatch_model.conf") .await @@ -1028,8 +1070,14 @@ mod tests { } use crate::MgmtApi; - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_enable_auto_save() { let m = DefaultModel::from_file("examples/basic_model.conf") .await @@ -1125,8 +1173,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_role_links() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -1142,8 +1196,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_get_and_set_model() { let m1 = DefaultModel::from_file("examples/basic_model.conf") .await @@ -1169,8 +1229,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_get_and_set_adapter_in_mem() { let m1 = DefaultModel::from_file("examples/basic_model.conf") .await @@ -1205,8 +1271,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_keymatch_custom_model() { use crate::model::key_match; @@ -1259,8 +1331,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_filtered_file_adapter() { let mut e = Enforcer::new( "examples/rbac_with_domains_model.conf", @@ -1303,8 +1381,14 @@ mod tests { .unwrap()); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_set_role_manager() { let mut e = Enforcer::new( "examples/rbac_with_domains_model.conf", @@ -1335,8 +1419,14 @@ mod tests { .unwrap()); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_policy_abac() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); diff --git a/src/management_api.rs b/src/management_api.rs index 23610d82..a879ea3e 100644 --- a/src/management_api.rs +++ b/src/management_api.rs @@ -357,8 +357,11 @@ mod tests { v } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_modify_grouping_policy_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -465,8 +468,11 @@ mod tests { assert_eq!(vec!["eve"], e.get_users_for_role("data3_admin", None)); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_modify_policy_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -547,8 +553,11 @@ mod tests { assert_eq!(vec![vec!["eve", "data3", "read"],], e.get_policy()); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_get_policy_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -751,8 +760,11 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_get_list() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -770,8 +782,11 @@ mod tests { assert_eq!(vec!["data2_admin"], e.get_all_roles()); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_modify_policies_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -931,8 +946,11 @@ mod tests { assert_eq!(vec![vec!["eve", "data3", "read"],], e.get_policy()); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_modify_grouping_policies_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await diff --git a/src/model/default_model.rs b/src/model/default_model.rs index 67003148..38922071 100644 --- a/src/model/default_model.rs +++ b/src/model/default_model.rs @@ -322,8 +322,11 @@ impl Model for DefaultModel { mod tests { use crate::prelude::*; - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_basic_model() { let m = DefaultModel::from_file("examples/basic_model.conf") .await @@ -342,8 +345,11 @@ mod tests { assert!(e.enforce(&vec!["bob", "data2", "write"]).await.unwrap()); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_basic_model_no_policy() { let m = DefaultModel::from_file("examples/basic_model.conf") .await @@ -362,8 +368,11 @@ mod tests { assert!(!e.enforce(&vec!["bob", "data2", "write"]).await.unwrap()); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_basic_model_with_root() { let m = DefaultModel::from_file("examples/basic_with_root_model.conf") .await @@ -386,8 +395,11 @@ mod tests { assert!(!e.enforce(&vec!["bob", "data2", "read"]).await.unwrap()); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_basic_model_with_root_no_policy() { let m = DefaultModel::from_file("examples/basic_with_root_model.conf") .await @@ -410,8 +422,11 @@ mod tests { assert!(!e.enforce(&vec!["bob", "data2", "read"]).await.unwrap()); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_basic_model_without_users() { let m = DefaultModel::from_file("examples/basic_without_users_model.conf") .await @@ -426,8 +441,11 @@ mod tests { assert!(e.enforce(&vec!["data2", "write"]).await.unwrap()); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_basic_model_without_resources() { let m = DefaultModel::from_file("examples/basic_without_resources_model.conf") .await @@ -442,8 +460,11 @@ mod tests { assert!(!e.enforce(&vec!["bob", "read"]).await.unwrap()); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_rbac_model() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -486,8 +507,11 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_rbac_model_with_resource_roles() { let m = DefaultModel::from_file("examples/rbac_with_resource_roles_model.conf") .await @@ -530,8 +554,11 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_rbac_model_with_domains() { let m = DefaultModel::from_file("examples/rbac_with_domains_model.conf") .await @@ -591,8 +618,11 @@ mod tests { } use crate::MgmtApi; - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_rbac_model_with_domains_runtime() { let m = DefaultModel::from_file("examples/rbac_with_domains_model.conf") .await @@ -823,8 +853,11 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_rbac_model_with_domains_at_runtime_mock_adapter() { let m = DefaultModel::from_file("examples/rbac_with_domains_model.conf") .await @@ -901,8 +934,11 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_rbac_model_with_deny() { let m = DefaultModel::from_file("examples/rbac_with_deny_model.conf") .await @@ -945,8 +981,11 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_rbac_model_with_not_deny() { let m = DefaultModel::from_file("examples/rbac_with_not_deny_model.conf") .await @@ -961,8 +1000,11 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_rbac_model_with_custom_data() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -1056,8 +1098,11 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_rbac_model_using_in_op() { let m = DefaultModel::from_file("examples/rbac_model_matcher_using_in_op.conf") .await @@ -1100,8 +1145,11 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] async fn test_abac() { let m = DefaultModel::from_file("examples/abac_model.conf") .await diff --git a/src/rbac_api.rs b/src/rbac_api.rs index b3a7feb3..88483ffe 100644 --- a/src/rbac_api.rs +++ b/src/rbac_api.rs @@ -322,8 +322,14 @@ mod tests { v } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_role_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -479,8 +485,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_role_api_threads() { use std::sync::{Arc, RwLock}; use std::thread; @@ -823,8 +835,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_permission_api() { let m = DefaultModel::from_file("examples/basic_without_resources_model.conf") .await @@ -921,8 +939,14 @@ mod tests { assert_eq!(false, e.enforce(&vec!["eve", "write"]).await.unwrap()); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_implicit_role_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -950,8 +974,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_implicit_permission_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -985,8 +1015,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_implicit_user_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -1039,8 +1075,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_implicit_permission_api_with_domain() { let m = DefaultModel::from_file("examples/rbac_with_domains_model.conf") .await @@ -1059,8 +1101,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_pattern_matching_fn() { let mut e = Enforcer::new( "examples/rbac_with_pattern_model.conf", @@ -1095,8 +1143,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_pattern_matching_fn_with_domain() { let mut e = Enforcer::new( "examples/rbac_with_pattern_domain_model.conf", @@ -1155,8 +1209,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_pattern_matching_basic_role() { let mut e = Enforcer::new( "examples/rbac_basic_role_model.conf", @@ -1197,8 +1257,14 @@ mod tests { ); } - #[cfg_attr(feature = "runtime-async-std", async_std::test)] - #[cfg_attr(all(feature = "runtime-tokio", not(target_os = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-async-std", not(target_arch = "wasm32")), + async_std::test + )] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_implicit_users_for_permission() { let mut m = DefaultModel::default(); m.add_def("r", "r", "sub, obj, act"); From f01680914cc285b9ecba881efeb1ed3e19f9810c Mon Sep 17 00:00:00 2001 From: Cheng JIANG Date: Sun, 10 May 2020 00:50:42 +0200 Subject: [PATCH 20/20] make other tests avalaible only on no-wasm32 target --- src/config.rs | 12 ++++- src/enforcer.rs | 16 ++++++- src/management_api.rs | 36 +++++++++++--- src/model/default_model.rs | 97 +++++++++++++++++++++++++++++++------- src/rbac_api.rs | 11 +++++ 5 files changed, 146 insertions(+), 26 deletions(-) diff --git a/src/config.rs b/src/config.rs index 76378eb5..da028483 100644 --- a/src/config.rs +++ b/src/config.rs @@ -214,11 +214,15 @@ impl Config { mod tests { use super::*; + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_get() { let mut config = Config::from_file("examples/testini.ini").await.unwrap(); @@ -261,11 +265,15 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_from_text() { let text: &str = r#" # test config diff --git a/src/enforcer.rs b/src/enforcer.rs index 72f795f9..241dfc3f 100644 --- a/src/enforcer.rs +++ b/src/enforcer.rs @@ -573,6 +573,7 @@ mod tests { assert!(is_sync::()); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -610,6 +611,7 @@ mod tests { .unwrap()) } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -749,6 +751,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -779,6 +782,7 @@ mod tests { } use crate::RbacApi; + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -816,6 +820,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -912,6 +917,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -988,6 +994,7 @@ mod tests { } #[cfg(feature = "ip")] + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -1069,7 +1076,7 @@ mod tests { .unwrap()); } - use crate::MgmtApi; + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -1173,6 +1180,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -1196,6 +1204,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -1229,6 +1238,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -1271,6 +1281,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -1331,6 +1342,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -1381,6 +1393,7 @@ mod tests { .unwrap()); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -1419,6 +1432,7 @@ mod tests { .unwrap()); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test diff --git a/src/management_api.rs b/src/management_api.rs index a879ea3e..657332e8 100644 --- a/src/management_api.rs +++ b/src/management_api.rs @@ -357,11 +357,15 @@ mod tests { v } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_modify_grouping_policy_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -468,11 +472,15 @@ mod tests { assert_eq!(vec!["eve"], e.get_users_for_role("data3_admin", None)); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_modify_policy_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -553,11 +561,15 @@ mod tests { assert_eq!(vec![vec!["eve", "data3", "read"],], e.get_policy()); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_get_policy_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -760,11 +772,15 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_get_list() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -782,11 +798,15 @@ mod tests { assert_eq!(vec!["data2_admin"], e.get_all_roles()); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_modify_policies_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -946,11 +966,15 @@ mod tests { assert_eq!(vec![vec!["eve", "data3", "read"],], e.get_policy()); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_modify_grouping_policies_api() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await diff --git a/src/model/default_model.rs b/src/model/default_model.rs index 38922071..ee465bfe 100644 --- a/src/model/default_model.rs +++ b/src/model/default_model.rs @@ -322,11 +322,15 @@ impl Model for DefaultModel { mod tests { use crate::prelude::*; + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_basic_model() { let m = DefaultModel::from_file("examples/basic_model.conf") .await @@ -345,11 +349,15 @@ mod tests { assert!(e.enforce(&vec!["bob", "data2", "write"]).await.unwrap()); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_basic_model_no_policy() { let m = DefaultModel::from_file("examples/basic_model.conf") .await @@ -368,11 +376,15 @@ mod tests { assert!(!e.enforce(&vec!["bob", "data2", "write"]).await.unwrap()); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_basic_model_with_root() { let m = DefaultModel::from_file("examples/basic_with_root_model.conf") .await @@ -395,11 +407,15 @@ mod tests { assert!(!e.enforce(&vec!["bob", "data2", "read"]).await.unwrap()); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_basic_model_with_root_no_policy() { let m = DefaultModel::from_file("examples/basic_with_root_model.conf") .await @@ -422,11 +438,15 @@ mod tests { assert!(!e.enforce(&vec!["bob", "data2", "read"]).await.unwrap()); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_basic_model_without_users() { let m = DefaultModel::from_file("examples/basic_without_users_model.conf") .await @@ -441,11 +461,15 @@ mod tests { assert!(e.enforce(&vec!["data2", "write"]).await.unwrap()); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_basic_model_without_resources() { let m = DefaultModel::from_file("examples/basic_without_resources_model.conf") .await @@ -460,11 +484,15 @@ mod tests { assert!(!e.enforce(&vec!["bob", "read"]).await.unwrap()); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_rbac_model() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -507,11 +535,15 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_rbac_model_with_resource_roles() { let m = DefaultModel::from_file("examples/rbac_with_resource_roles_model.conf") .await @@ -554,11 +586,15 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_rbac_model_with_domains() { let m = DefaultModel::from_file("examples/rbac_with_domains_model.conf") .await @@ -617,12 +653,15 @@ mod tests { ); } - use crate::MgmtApi; + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_rbac_model_with_domains_runtime() { let m = DefaultModel::from_file("examples/rbac_with_domains_model.conf") .await @@ -853,11 +892,15 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_rbac_model_with_domains_at_runtime_mock_adapter() { let m = DefaultModel::from_file("examples/rbac_with_domains_model.conf") .await @@ -934,11 +977,15 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_rbac_model_with_deny() { let m = DefaultModel::from_file("examples/rbac_with_deny_model.conf") .await @@ -981,11 +1028,15 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_rbac_model_with_not_deny() { let m = DefaultModel::from_file("examples/rbac_with_not_deny_model.conf") .await @@ -1000,11 +1051,15 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_rbac_model_with_custom_data() { let m = DefaultModel::from_file("examples/rbac_model.conf") .await @@ -1098,11 +1153,15 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_rbac_model_using_in_op() { let m = DefaultModel::from_file("examples/rbac_model_matcher_using_in_op.conf") .await @@ -1145,11 +1204,15 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test )] - #[cfg_attr(all(feature = "runtime-tokio", not(target_arch = "wasm32")), tokio::test)] + #[cfg_attr( + all(feature = "runtime-tokio", not(target_arch = "wasm32")), + tokio::test + )] async fn test_abac() { let m = DefaultModel::from_file("examples/abac_model.conf") .await diff --git a/src/rbac_api.rs b/src/rbac_api.rs index 88483ffe..d84ca5c6 100644 --- a/src/rbac_api.rs +++ b/src/rbac_api.rs @@ -322,6 +322,7 @@ mod tests { v } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -485,6 +486,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -835,6 +837,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -939,6 +942,7 @@ mod tests { assert_eq!(false, e.enforce(&vec!["eve", "write"]).await.unwrap()); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -974,6 +978,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -1015,6 +1020,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -1075,6 +1081,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -1101,6 +1108,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -1143,6 +1151,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -1209,6 +1218,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test @@ -1257,6 +1267,7 @@ mod tests { ); } + #[cfg(not(target_arch = "wasm32"))] #[cfg_attr( all(feature = "runtime-async-std", not(target_arch = "wasm32")), async_std::test