diff options
| author | mo khan <mo@mokhan.ca> | 2025-06-27 14:53:48 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-06-27 14:53:48 -0600 |
| commit | 2309a49fddd189e5dc9da1e7bf979864f02701e0 (patch) | |
| tree | d60300d727ab6de68c0e69cecc35b54e252b7642 /tests/support/factory_bot.rs | |
| parent | f2e1cc278bedb63ba0b0b8d9a82e28f0e10fe048 (diff) | |
test: rename common module to support
Diffstat (limited to 'tests/support/factory_bot.rs')
| -rw-r--r-- | tests/support/factory_bot.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/support/factory_bot.rs b/tests/support/factory_bot.rs new file mode 100644 index 00000000..c64b53a2 --- /dev/null +++ b/tests/support/factory_bot.rs @@ -0,0 +1,41 @@ +use envoy_types::ext_authz::v3::pb::CheckRequest; +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; + +#[allow(dead_code)] +pub fn build<T: Default>() -> T { + return please::build(); +} + +pub fn build_with<T, F>(initializer: F) -> T +where + T: Default, + F: std::ops::FnOnce(&mut T), +{ + return please::build_with(initializer); +} + +pub fn build_request(f: impl std::ops::FnOnce(&mut HttpRequest)) -> CheckRequest { + build_with(|item: &mut CheckRequest| { + item.attributes = Some(please::build_with(|item: &mut AttributeContext| { + item.request = Some(please::build_with(|item: &mut Request| { + item.http = Some(please::build_with(|item: &mut HttpRequest| f(item))); + })); + })); + }) +} + +pub fn build_headers(headers: Vec<(String, String)>) -> HashMap<String, String> { + return build_with(|item: &mut HashMap<String, String>| { + for (key, value) in headers { + item.insert(key, value); + } + }); +} + +pub fn build_cedar_authorizer() -> authzd::CedarAuthorizer { + let realpath = std::fs::canonicalize("./etc/authzd").unwrap(); + let path = realpath.as_path(); + authzd::CedarAuthorizer::new_from(path) +} |
