diff options
| -rw-r--r-- | src/authorization/cedar_authorizer.rs | 10 | ||||
| -rw-r--r-- | tests/common/factory_bot.rs | 6 | ||||
| -rw-r--r-- | tests/integration_tests.rs | 2 |
3 files changed, 8 insertions, 10 deletions
diff --git a/src/authorization/cedar_authorizer.rs b/src/authorization/cedar_authorizer.rs index 4ec3b34d..c2c594fe 100644 --- a/src/authorization/cedar_authorizer.rs +++ b/src/authorization/cedar_authorizer.rs @@ -6,7 +6,6 @@ use cedar_policy::{ use envoy_types::ext_authz::v3::pb::CheckRequest; use std::collections::HashMap; use std::fs; -use std::path::Path; use std::str::FromStr; #[derive(Debug)] @@ -23,12 +22,11 @@ impl CedarAuthorizer { } } - pub fn new_from(dir_path: &str) -> CedarAuthorizer { - Self::new(Self::load_from(dir_path).unwrap_or_else(|_| PolicySet::default())) + pub fn new_from(path: &std::path::Path) -> CedarAuthorizer { + Self::new(Self::load_from(path).unwrap_or_else(|_| PolicySet::default())) } - fn load_from(dir_path: &str) -> Result<PolicySet, Box<dyn std::error::Error>> { - let path = Path::new(dir_path); + fn load_from(path: &std::path::Path) -> Result<PolicySet, Box<dyn std::error::Error>> { if !path.exists() || !path.is_dir() { return Ok(PolicySet::default()); } @@ -55,7 +53,7 @@ impl CedarAuthorizer { } impl Default for CedarAuthorizer { fn default() -> Self { - Self::new_from("/etc/authzd") + Self::new_from(fs::canonicalize("/etc/authzd").unwrap().as_path()) } } diff --git a/tests/common/factory_bot.rs b/tests/common/factory_bot.rs index 3c3810a7..6e45a01a 100644 --- a/tests/common/factory_bot.rs +++ b/tests/common/factory_bot.rs @@ -39,7 +39,7 @@ pub fn create_token() -> String { } pub fn build_cedar_authorizer() -> authzd::CedarAuthorizer { - authzd::CedarAuthorizer::new_from( - "/home/mokhax/src/gitlab.com/gitlab-org/software-supply-chain-security/authorization/authzd/etc/authzd", - ) + let realpath = std::fs::canonicalize("./etc/authzd").unwrap(); + let path = realpath.as_path(); + authzd::CedarAuthorizer::new_from(path) } diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 63aaaadc..6e181f26 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1,4 +1,4 @@ -use authzd::{CedarAuthorizer, CheckService}; +use authzd::CheckService; use common::*; use envoy_types::ext_authz::v3::pb::Authorization; use envoy_types::pb::envoy::service::auth::v3::attribute_context::HttpRequest; |
