From e3fec7bf38d6070c9fb547ab08670e556ec974ab Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 20 Jun 2025 10:37:56 -0600 Subject: refactor: experiment with rust generics --- src/authorization/cedar_authorizer.rs | 38 +++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'src/authorization/cedar_authorizer.rs') diff --git a/src/authorization/cedar_authorizer.rs b/src/authorization/cedar_authorizer.rs index 2efbda28..ff4c3c5b 100644 --- a/src/authorization/cedar_authorizer.rs +++ b/src/authorization/cedar_authorizer.rs @@ -41,11 +41,22 @@ mod tests { use envoy_types::pb::envoy::service::auth::v3::{AttributeContext, attribute_context}; use std::collections::HashMap; + fn build() -> T { + T::default() + } + + fn build_with(initializer: impl std::ops::FnOnce(T) -> T) -> T { + let item = build::(); + initializer(item) + } + fn create_test_request_with_headers(headers: HashMap) -> CheckRequest { - let http_request = attribute_context::HttpRequest { - headers, - ..Default::default() - }; + let http_request = build_with::( + |mut item: attribute_context::HttpRequest| { + item.headers = headers; + item + }, + ); let request_context = attribute_context::Request { http: Some(http_request), @@ -100,4 +111,23 @@ mod tests { let result = authorizer.authorize(request); assert!(!result); } + + // test css passthrough + // test javascript passthrough + // test ico passthrough + // test png,jpg,bmp passthrough + // test html passthrough + // #[test] + // fn authorize_test_css_passthrough() { + // let authorizer = CedarAuthorizer::new(); + + // let request = CheckRequest { + // attributes: Some(AttributeContext { + // ..Default::default() + // }), + // }; + // let result = authorizer.authorize(request); + + // assert!(result) + // } } -- cgit v1.2.3