summaryrefslogtreecommitdiff
path: root/tests/support
diff options
context:
space:
mode:
Diffstat (limited to 'tests/support')
-rw-r--r--tests/support/common.rs12
-rw-r--r--tests/support/factory_bot.rs20
-rw-r--r--tests/support/mod.rs1
3 files changed, 31 insertions, 2 deletions
diff --git a/tests/support/common.rs b/tests/support/common.rs
new file mode 100644
index 00000000..8db5c52b
--- /dev/null
+++ b/tests/support/common.rs
@@ -0,0 +1,12 @@
+use std::sync::Once;
+
+static INIT: Once = Once::new();
+
+pub fn setup() {
+ INIT.call_once(|| {
+ tracing_subscriber::fmt()
+ .with_test_writer()
+ .with_max_level(tracing::Level::WARN)
+ .init();
+ });
+}
diff --git a/tests/support/factory_bot.rs b/tests/support/factory_bot.rs
index 007f0cb7..ba0d9c38 100644
--- a/tests/support/factory_bot.rs
+++ b/tests/support/factory_bot.rs
@@ -3,6 +3,7 @@ use envoy_types::pb::envoy::service::auth::v3::AttributeContext;
use envoy_types::pb::envoy::service::auth::v3::attribute_context::{HttpRequest, Request};
use std::collections::HashMap;
use std::net::SocketAddr;
+use std::str::FromStr;
use tonic::transport::Channel;
#[allow(dead_code)]
@@ -36,10 +37,10 @@ pub fn build_headers(headers: Vec<(String, String)>) -> HashMap<String, String>
})
}
-pub fn build_cedar_authorizer() -> authzd::CedarAuthorizer {
+pub fn build_cedar_authorizer(entities: cedar_policy::Entities) -> authzd::CedarAuthorizer {
let realpath = std::fs::canonicalize("./etc/authzd").unwrap();
let path = realpath.as_path();
- authzd::CedarAuthorizer::new_from(path, cedar_policy::Entities::empty())
+ authzd::CedarAuthorizer::new_from(path, entities)
}
pub async fn build_channel(addr: SocketAddr) -> Channel {
@@ -56,3 +57,18 @@ where
{
f(build_channel(addr).await)
}
+
+pub fn build_user(
+ id: &str,
+ attrs: std::collections::HashMap<String, cedar_policy::RestrictedExpression>,
+) -> cedar_policy::Entity {
+ cedar_policy::Entity::new(
+ cedar_policy::EntityUid::from_type_name_and_id(
+ cedar_policy::EntityTypeName::from_str("User").unwrap(),
+ cedar_policy::EntityId::from_str(id).unwrap(),
+ ),
+ attrs,
+ std::collections::HashSet::new(),
+ )
+ .unwrap()
+}
diff --git a/tests/support/mod.rs b/tests/support/mod.rs
index 5e2a6d78..c46f39e5 100644
--- a/tests/support/mod.rs
+++ b/tests/support/mod.rs
@@ -1 +1,2 @@
+pub mod common;
pub mod factory_bot;