-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This still warns on ascii control characters and any non-ascii characters we previosly warned about. Signed-off-by: John Kastner <[email protected]>
- Loading branch information
1 parent
3166f9b
commit c601969
Showing
3 changed files
with
58 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,11 +78,15 @@ fn permissable_ident( | |
policy_id.clone(), | ||
s, | ||
)) | ||
} else if !s.chars().all(|c| c.identifier_allowed()) { | ||
} else if let Some(c) = s | ||
.chars() | ||
.find(|c| !c.is_ascii_graphic() && !c.identifier_allowed()) | ||
{ | ||
Some(ValidationWarning::confusable_identifier( | ||
loc.cloned(), | ||
policy_id.clone(), | ||
s, | ||
c, | ||
)) | ||
} else if !s.is_single_script() { | ||
Some(ValidationWarning::mixed_script_identifier( | ||
|
@@ -119,7 +123,9 @@ mod test { | |
use cedar_policy_core::{ | ||
ast::PolicySet, | ||
parser::{parse_policy, Loc}, | ||
test_utils::{expect_err, ExpectedErrorMessageBuilder}, | ||
}; | ||
use cool_asserts::assert_matches; | ||
use std::sync::Arc; | ||
#[test] | ||
fn strs() { | ||
|
@@ -148,14 +154,52 @@ mod test { | |
permissable_ident(None, &PolicyID::from_string("0"), "test"), | ||
None | ||
); | ||
match permissable_ident(None, &PolicyID::from_string("0"), "isAdmin") { | ||
Some(ValidationWarning::ConfusableIdentifier(_)) => (), | ||
o => panic!("should have produced ConfusableIdentifier: {:?}", o), | ||
}; | ||
match permissable_ident(None, &PolicyID::from_string("0"), "say_һello") { | ||
Some(ValidationWarning::MixedScriptIdentifier(_)) => (), | ||
o => panic!("should have produced MixedScriptIdentifier: {:?}", o), | ||
}; | ||
assert_eq!( | ||
permissable_ident( | ||
None, | ||
&PolicyID::from_string("0"), | ||
"https://www.example.com/test?foo=bar&bar=baz#buz" | ||
), | ||
None | ||
); | ||
assert_eq!( | ||
permissable_ident( | ||
None, | ||
&PolicyID::from_string("0"), | ||
"http://example.com/query{firstName}-{lastName}" | ||
), | ||
None | ||
); | ||
assert_eq!( | ||
permissable_ident( | ||
None, | ||
&PolicyID::from_string("0"), | ||
"[email protected]" | ||
), | ||
None | ||
); | ||
|
||
assert_matches!(permissable_ident(None, &PolicyID::from_string("0"), "isAdmin"), Some(warning) => { | ||
expect_err( | ||
"", | ||
&miette::Report::new(warning), | ||
&ExpectedErrorMessageBuilder::error(r#"for policy `0`, identifier `isAdmin` contains the character `\u{200b}` which falls outside of the General Security Profile for Identifiers"#) | ||
.build()); | ||
}); | ||
assert_matches!(permissable_ident(None, &PolicyID::from_string("0"), "🍌"), Some(warning) => { | ||
expect_err( | ||
"", | ||
&miette::Report::new(warning), | ||
&ExpectedErrorMessageBuilder::error(r#"for policy `0`, identifier `🍌` contains the character `🍌` which falls outside of the General Security Profile for Identifiers"#) | ||
.build()); | ||
}); | ||
assert_matches!(permissable_ident(None, &PolicyID::from_string("0"), "say_һello") , Some(warning) => { | ||
expect_err( | ||
"", | ||
&miette::Report::new(warning), | ||
&ExpectedErrorMessageBuilder::error(r#"for policy `0`, identifier `say_һello` contains mixed scripts"#) | ||
.build()); | ||
}); | ||
} | ||
|
||
#[test] | ||
|