From f59c24589af439e0e22f43a2e42595cf88973ccf Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 27 Jun 2025 12:45:13 -0600 Subject: test: extract factory_bot factory for cedar authorizer --- tests/authorization/cedar_authorizer_test.rs | 17 +++++------------ tests/authorization/check_service_test.rs | 5 +---- 2 files changed, 6 insertions(+), 16 deletions(-) (limited to 'tests/authorization') diff --git a/tests/authorization/cedar_authorizer_test.rs b/tests/authorization/cedar_authorizer_test.rs index 3073417d..656e0060 100644 --- a/tests/authorization/cedar_authorizer_test.rs +++ b/tests/authorization/cedar_authorizer_test.rs @@ -2,16 +2,9 @@ mod tests { use crate::common::factory_bot::*; use authzd::Authorizer; - use authzd::CedarAuthorizer; use envoy_types::pb::envoy::service::auth::v3::attribute_context::HttpRequest; use std::collections::HashMap; - fn authorizer() -> CedarAuthorizer { - CedarAuthorizer::new_from( - "/home/mokhax/src/gitlab.com/gitlab-org/software-supply-chain-security/authorization/authzd/etc/authzd", - ) - } - #[test] fn test_cedar_authorizer_allows_valid_token() { let request = create_request(|item: &mut HttpRequest| { @@ -23,7 +16,7 @@ mod tests { }); }); - assert!(authorizer().authorize(request)); + assert!(build_cedar_authorizer().authorize(request)); } #[test] @@ -37,7 +30,7 @@ mod tests { }); }); - assert!(!authorizer().authorize(request)); + assert!(!build_cedar_authorizer().authorize(request)); } #[test] @@ -46,7 +39,7 @@ mod tests { item.headers = HashMap::new(); }); - assert!(!authorizer().authorize(request)); + assert!(!build_cedar_authorizer().authorize(request)); } #[test] @@ -57,7 +50,7 @@ mod tests { }); }); - assert!(authorizer().authorize(request)); + assert!(build_cedar_authorizer().authorize(request)); } #[test] @@ -68,6 +61,6 @@ mod tests { item.headers = headers; }); - assert!(authorizer().authorize(request)); + assert!(build_cedar_authorizer().authorize(request)); } } diff --git a/tests/authorization/check_service_test.rs b/tests/authorization/check_service_test.rs index c101850c..cddbb6b0 100644 --- a/tests/authorization/check_service_test.rs +++ b/tests/authorization/check_service_test.rs @@ -1,7 +1,6 @@ #[cfg(test)] mod tests { use crate::common::factory_bot::*; - use authzd::CedarAuthorizer; use authzd::CheckService; use envoy_types::ext_authz::v3::pb::Authorization; use envoy_types::pb::envoy::service::auth::v3::attribute_context::HttpRequest; @@ -9,9 +8,7 @@ mod tests { use std::sync::Arc; fn authorizer() -> Arc { - Arc::new(CedarAuthorizer::new_from( - "/home/mokhax/src/gitlab.com/gitlab-org/software-supply-chain-security/authorization/authzd/etc/authzd", - )) + Arc::new(build_cedar_authorizer()) } #[tokio::test] -- cgit v1.2.3