This commit is contained in:
Yong Wen Chua 2019-03-19 09:58:08 +08:00
parent 0041f7a4aa
commit f9316a38e6
No known key found for this signature in database
GPG Key ID: A70BD30B21497EA9
1 changed files with 16 additions and 7 deletions

View File

@ -806,7 +806,6 @@ impl ParsedAllowedOrigins {
None => Ok(Default::default()), None => Ok(Default::default()),
}; };
let exact = exact?; let exact = exact?;
println!("{:#?}", exact);
// Let's check if they are Opaque // Let's check if they are Opaque
let (tuple, opaque): (Vec<_>, Vec<_>) = let (tuple, opaque): (Vec<_>, Vec<_>) =
@ -836,6 +835,7 @@ impl ParsedAllowedOrigins {
} }
fn verify(&self, origin: &Origin) -> bool { fn verify(&self, origin: &Origin) -> bool {
info_!("Verifying origin: {}", origin);
match origin { match origin {
Origin::Null => { Origin::Null => {
info_!("Origin is null. Allowing? {}", self.allow_null); info_!("Origin is null. Allowing? {}", self.allow_null);
@ -2128,15 +2128,25 @@ mod tests {
} }
#[test] #[test]
#[should_panic(
expected = r#"OpaqueAllowedOrigin(["chrome-extension://something", "moz-extension://something"])"#
)]
fn allowed_origins_errors_on_opaque_exact() { fn allowed_origins_errors_on_opaque_exact() {
let _ = parse_allowed_origins(&AllowedOrigins::some::<_, &str>( let error = parse_allowed_origins(&AllowedOrigins::some::<_, &str>(
&["chrome-extension://something", "moz-extension://something"], &["chrome-extension://something", "moz-extension://something"],
&[], &[],
)) ))
.unwrap(); .unwrap_err();
match error {
Error::OpaqueAllowedOrigin(mut origins) => {
origins.sort();
assert_eq!(
origins,
["chrome-extension://something", "moz-extension://something"]
);
}
others => {
panic!("Unexpected error: {:#?}", others);
}
};
} }
// The following tests check validation // The following tests check validation
@ -2201,7 +2211,6 @@ mod tests {
fn validate_origin_validates_opaque_origins() { fn validate_origin_validates_opaque_origins() {
let url = "moz-extension://8c7c4444-e29f-…cb8-1ade813dbd12/js/content.js:505"; let url = "moz-extension://8c7c4444-e29f-…cb8-1ade813dbd12/js/content.js:505";
let origin = not_err!(to_parsed_origin(&url)); let origin = not_err!(to_parsed_origin(&url));
println!("{:#?}", origin);
let allowed_origins = not_err!(parse_allowed_origins(&AllowedOrigins::some_regex(&[ let allowed_origins = not_err!(parse_allowed_origins(&AllowedOrigins::some_regex(&[
"moz-extension://.*" "moz-extension://.*"
]))); ])));