summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/authorization/cedar_authorizer_test.rs15
-rw-r--r--tests/support/factory_bot.rs13
2 files changed, 16 insertions, 12 deletions
diff --git a/tests/authorization/cedar_authorizer_test.rs b/tests/authorization/cedar_authorizer_test.rs
index 88357058..8add9868 100644
--- a/tests/authorization/cedar_authorizer_test.rs
+++ b/tests/authorization/cedar_authorizer_test.rs
@@ -5,7 +5,6 @@ mod tests {
use authzd::Authorizer;
use envoy_types::pb::envoy::service::auth::v3::attribute_context::HttpRequest;
use std::collections::HashMap;
- use std::str::FromStr;
fn subject() -> authzd::CedarAuthorizer {
common::setup();
@@ -73,7 +72,7 @@ mod tests {
// * delete sparkles: `:delete, gid://sparkle/Sparkle/*`
// * delete single sparkle: `:delete, gid://sparkle/Sparkle/:id`
#[test]
- fn test_authenticated_sparkle_endpoints() {
+ fn test_authenticated_create_sparkle() {
let request = build_request(|item: &mut HttpRequest| {
item.method = "GET".to_string();
item.path = "/sparkles".to_string();
@@ -86,16 +85,8 @@ mod tests {
]);
});
- let user = cedar_policy::Entity::new(
- cedar_policy::EntityUid::from_type_name_and_id(
- cedar_policy::EntityTypeName::from_str("User").unwrap(),
- cedar_policy::EntityId::from_str("1675940").unwrap(),
- ),
- std::collections::HashMap::new(),
- std::collections::HashSet::new(),
- );
-
- let entities = cedar_policy::Entities::from_entities([user.unwrap()], None).unwrap();
+ let user = build_user("1675940");
+ let entities = cedar_policy::Entities::from_entities([user], None).unwrap();
let authorizer = subject_with(entities);
assert!(authorizer.authorize(request));
}
diff --git a/tests/support/factory_bot.rs b/tests/support/factory_bot.rs
index 14969f87..969080a3 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)]
@@ -56,3 +57,15 @@ where
{
f(build_channel(addr).await)
}
+
+pub fn build_user(id: &str) -> 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(),
+ ),
+ std::collections::HashMap::new(),
+ std::collections::HashSet::new(),
+ )
+ .unwrap()
+}