Skip to content

Commit

Permalink
switch back to PolicyId
Browse files Browse the repository at this point in the history
  • Loading branch information
khieta committed Jun 3, 2024
1 parent 4d4045d commit 3cfc30e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 36 deletions.
5 changes: 0 additions & 5 deletions cedar-policy-core/src/ast/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,11 +1718,6 @@ impl PolicyID {
pub fn from_smolstr(id: SmolStr) -> Self {
Self(id)
}

/// Get the underlying `SmolStr`
pub fn into_smolstr(self) -> SmolStr {
self.0
}
}

impl std::fmt::Display for PolicyID {
Expand Down
5 changes: 0 additions & 5 deletions cedar-policy/src/api/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,6 @@ impl PolicyId {
pub fn new(id: impl AsRef<str>) -> Self {
Self(ast::PolicyID::from_string(id.as_ref()))
}

/// Get the underlying `SmolStr`
pub(crate) fn into_smolstr(self) -> SmolStr {
self.0.into_smolstr()
}
}

impl FromStr for PolicyId {
Expand Down
15 changes: 7 additions & 8 deletions cedar-policy/src/ffi/is_authorized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! This module contains the `is_authorized` entry points that other language
//! FFIs can call
#![allow(clippy::module_name_repetitions)]
use super::utils::*;
use super::utils::{DetailedError, JsonValueWithNoDuplicateKeys, PolicySet, Schema, WithWarnings};
use crate::{
Authorizer, Context, Decision, Entities, EntityId, EntityTypeName, EntityUid, PolicyId,
Request, SlotId,
Expand All @@ -26,7 +26,6 @@ use itertools::Itertools;
use miette::{miette, Diagnostic, WrapErr};
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, MapPreventDuplicates};
use smol_str::ToSmolStr;
use std::collections::{HashMap, HashSet};
#[cfg(feature = "partial-eval")]
use std::convert::Infallible;
Expand Down Expand Up @@ -253,7 +252,7 @@ impl From<crate::AuthorizationError> for AuthorizationError {
fn from(e: crate::AuthorizationError) -> Self {
match e {
crate::AuthorizationError::PolicyEvaluationError(e) => {
Self::new(e.id().to_smolstr(), e.into_inner())
Self::new(e.id().clone(), e.into_inner())
}
}
}
Expand Down Expand Up @@ -624,7 +623,7 @@ impl AuthorizationCall {
b = b.resource(resource);
}
b = b.context(context);
let request = if self.enable_request_validation {
let request = if self.validate_request {
match schema.as_ref() {
Some(schema_ref) => match b.schema(schema_ref).build() {
Ok(req) => Some(req),
Expand Down Expand Up @@ -1856,7 +1855,7 @@ mod test {
"schema": {
"human": "entity User, Photo; action view appliesTo { principal: User, resource: Photo };"
},
"enableRequestValidation": false,
"validateRequest": false,
});

assert_is_authorized_json(good_call);
Expand Down Expand Up @@ -1905,12 +1904,12 @@ mod partial_test {
assert_eq!(response.decision(), None);
let errors: Vec<_> = response.errored().collect();
assert_eq!(errors.len(), 0, "{errors:?}");
let actual_residuals: HashSet<&str> = response.nontrivial_residual_ids().map(|id| id.as_str()).collect();
let actual_residuals: HashSet<_> = response.nontrivial_residual_ids().collect();
for id in &expected_residuals {
assert!(actual_residuals.contains(id), "expected nontrivial residual for {id}, but it's missing")
assert!(actual_residuals.contains(&PolicyId::from_str(id).ok().unwrap()), "expected nontrivial residual for {id}, but it's missing")
}
for id in &actual_residuals {
assert!(expected_residuals.contains(id), "found unexpected nontrivial residual for {id}")
assert!(expected_residuals.contains(id.to_string().as_str()),"found unexpected nontrivial residual for {id}")
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions cedar-policy/src/ffi/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ pub fn validate(call: ValidationCall) -> ValidationAnswer {
.into_errors_and_warnings();
let validation_errors: Vec<ValidationError> = validation_errors
.map(|error| ValidationError {
policy_id: *error.policy_id(),
policy_id: error.policy_id().clone(),
error: miette::Report::new(error).into(),
})
.collect();
let validation_warnings: Vec<ValidationError> = validation_warnings
.map(|error| ValidationError {
policy_id: *error.policy_id(),
policy_id: error.policy_id().clone(),
error: miette::Report::new(error).into(),
})
.collect();
Expand Down
9 changes: 2 additions & 7 deletions cedar-testing/src/cedar_test_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use cedar_policy_core::extensions::Extensions;
use cedar_policy_validator::{ValidationMode, Validator, ValidatorSchema};
use miette::miette;
use serde::{Deserialize, Serialize};
use smol_str::ToSmolStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -282,11 +281,7 @@ impl CedarTestImplementation for RustEngine {
let response = cedar_policy::Response::from(response);
let response = ffi::Response::new(
response.decision(),
response
.diagnostics()
.reason()
.map(|id| id.to_smolstr())
.collect(),
response.diagnostics().reason().cloned().collect(),
response
.diagnostics()
.errors()
Expand All @@ -295,7 +290,7 @@ impl CedarTestImplementation for RustEngine {
// `ErrorComparisonMode::PolicyIds` mode.
let policy_id = e.id();
ffi::AuthorizationError::new_from_report(
policy_id.to_smolstr(),
policy_id.clone(),
miette!("{policy_id}"),
)
})
Expand Down
10 changes: 2 additions & 8 deletions cedar-testing/src/integration_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use std::{
collections::HashSet,
env,
path::{Path, PathBuf},
str::FromStr,
};

/// JSON representation of our integration test file format
Expand Down Expand Up @@ -323,12 +322,7 @@ pub fn perform_integration_test(
&json_request.description
);
// check reason
let reason: HashSet<PolicyId> = response
.response
.diagnostics()
.reason()
.map(|id| PolicyId::from_str(id).unwrap())
.collect();
let reason: HashSet<PolicyId> = response.response.diagnostics().reason().cloned().collect();
assert_eq!(
reason,
json_request.reason.into_iter().collect(),
Expand All @@ -345,7 +339,7 @@ pub fn perform_integration_test(
.response
.diagnostics()
.errors()
.map(|err| PolicyId::from_str(&err.policy_id).unwrap())
.map(|err| err.policy_id.clone())
.collect();
assert_eq!(
errors,
Expand Down
2 changes: 1 addition & 1 deletion cedar-testing/tests/cedar-policy-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn perform_integration_test_from_json(jsonfile: impl AsRef<Path>) {
entity_args.push("--action".to_string());
entity_args.push(value_to_euid_string(s.into()).unwrap());
}
if !json_request.enable_request_validation {
if !json_request.validate_request {
entity_args.push("--request-validation=false".to_string());
}

Expand Down

0 comments on commit 3cfc30e

Please sign in to comment.