Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion saturn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ tracing-subscriber = { workspace = true }
thiserror = { workspace = true }

itertools = "0.13.0"
cedar-policy = "3.3.0"
cedar-policy = "4.0.0"
10 changes: 5 additions & 5 deletions saturn/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cedar_policy::{
Authorizer, Context, Decision, Diagnostics, HumanSchemaError, ParseErrors, PolicySet,
Authorizer, CedarSchemaError, Context, Decision, Diagnostics, ParseErrors, PolicySet,
PolicySetError, Request, Schema, SchemaError, ValidationMode, Validator,
};
use itertools::Itertools;
Expand All @@ -24,7 +24,7 @@ pub enum ContextError {
#[error("Error Parsing Json Schema: {0}")]
JsonSchema(#[from] SchemaError),
#[error("Error Parsing Human-readable Schema: {0}")]
CedarSchema(#[from] HumanSchemaError),
CedarSchema(#[from] CedarSchemaError),
#[error("Error Parsing PolicySet: {0}")]
Policy(#[from] ParseErrors),
#[error("Error Processing PolicySet: {0}")]
Expand Down Expand Up @@ -91,9 +91,9 @@ impl AppContext {
) -> Result<(), Error> {
let es = self.entities.as_entities(&self.schema);
let q = Request::new(
Some(principal.as_ref().clone().into()),
Some(action.as_ref().clone().into()),
Some(resource.as_ref().clone().into()),
principal.as_ref().clone().into(),
action.as_ref().clone().into(),
resource.as_ref().clone().into(),
context,
Some(&self.schema),
)
Expand Down
28 changes: 15 additions & 13 deletions saturn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod util;

#[cfg(test)]
mod test {
use std::fs;
use std::{fs, sync::Once};

use cedar_policy::{Authorizer, Context, Entities, PolicySet, Request};

Expand All @@ -15,6 +15,16 @@ mod test {
util::EntityUid,
};

static INIT: Once = Once::new();

fn init_tracing() {
INIT.call_once(|| {
tracing_subscriber::fmt()
.pretty()
.init();
});
}

#[test]
fn test_without_entity() {
const POLICY_SRC: &str = r#"
Expand All @@ -25,14 +35,7 @@ mod test {
let action = r#"Action::"view""#.parse().unwrap();
let alice = r#"User::"alice""#.parse().unwrap();
let file = r#"File::"93""#.parse().unwrap();
let request = Request::new(
Some(alice),
Some(action),
Some(file),
Context::empty(),
None,
)
.unwrap();
let request = Request::new(alice, action, file, Context::empty(), None).unwrap();

let entities = Entities::empty();
let authorizer = Authorizer::new();
Expand All @@ -44,8 +47,7 @@ mod test {
let action = r#"Action::"view""#.parse().unwrap();
let bob = r#"User::"bob""#.parse().unwrap();
let file = r#"File::"93""#.parse().unwrap();
let request =
Request::new(Some(bob), Some(action), Some(file), Context::empty(), None).unwrap();
let request = Request::new(bob, action, file, Context::empty(), None).unwrap();

let answer = authorizer.is_authorized(&request, &policy, &entities);

Expand All @@ -59,7 +61,7 @@ mod test {

#[test]
fn test_project_path_policy() {
tracing_subscriber::fmt().pretty().init();
init_tracing();
let entities_path = "./test/project/.mega.json";
let entities_file = fs::File::open(entities_path).unwrap();
let entities = serde_json::from_reader(entities_file).unwrap();
Expand Down Expand Up @@ -128,7 +130,7 @@ mod test {

#[test]
fn test_private_path_policy() {
tracing_subscriber::fmt().pretty().init();
init_tracing();
let parent_entities_file = fs::File::open("./test/project/.mega.json").unwrap();
let parent_entities: EntityStore = serde_json::from_reader(parent_entities_file).unwrap();

Expand Down