From 5d7f37c6508c7308c17659630cff35f4ead6dae4 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 10 Jul 2025 14:58:52 -0600 Subject: fix: allow authenticated+authorized users to create Sparkles --- tests/authorization/cedar_authorizer_test.rs | 14 ++++++++++++-- tests/support/factory_bot.rs | 7 +++++-- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/authorization/cedar_authorizer_test.rs b/tests/authorization/cedar_authorizer_test.rs index f2dfebd4..f056c8c7 100644 --- a/tests/authorization/cedar_authorizer_test.rs +++ b/tests/authorization/cedar_authorizer_test.rs @@ -91,12 +91,22 @@ mod tests { ]); }); - let user = build_user("1675940"); + let mut attrs = std::collections::HashMap::new(); + attrs.insert( + "username".to_string(), + cedar_policy::RestrictedExpression::new_string("tanuki".to_string()), + ); + let user = build_user("1675940", attrs); let entities = cedar_policy::Entities::from_entities([user], None).unwrap(); let authorizer = subject_with(entities); assert!(authorizer.authorize(request.clone())); - let user = build_user("1"); + let mut attrs = std::collections::HashMap::new(); + attrs.insert( + "username".to_string(), + cedar_policy::RestrictedExpression::new_string("root".to_string()), + ); + let user = build_user("1", attrs); let entities = cedar_policy::Entities::from_entities([user], None).unwrap(); let authorizer = subject_with(entities); assert!(!authorizer.authorize(request.clone())); diff --git a/tests/support/factory_bot.rs b/tests/support/factory_bot.rs index 969080a3..ba0d9c38 100644 --- a/tests/support/factory_bot.rs +++ b/tests/support/factory_bot.rs @@ -58,13 +58,16 @@ where f(build_channel(addr).await) } -pub fn build_user(id: &str) -> cedar_policy::Entity { +pub fn build_user( + id: &str, + attrs: std::collections::HashMap, +) -> 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(), + attrs, std::collections::HashSet::new(), ) .unwrap() -- cgit v1.2.3