-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from RobDWaller/0.2.0-rc
0.2.0 rc
- Loading branch information
Showing
10 changed files
with
218 additions
and
98 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
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use crate::domains::Item; | ||
|
||
// Find the domains associated with the CSP directive | ||
pub fn find(directive: &str, domains: &[Item]) -> Vec<String> { | ||
let mut domains_found: Vec<String> = vec![]; | ||
|
||
for domain in domains { | ||
if domain.directives.contains(&directive.to_string()) { | ||
domains_found.push(domain.domain.to_string()); | ||
} | ||
} | ||
|
||
domains_found | ||
} | ||
|
||
// ----- | ||
// Tests | ||
// ----- | ||
#[cfg(test)] | ||
mod domains_test { | ||
use crate::domains::{Collection, Item}; | ||
|
||
#[test] | ||
fn test_find() { | ||
let item1 = Item { | ||
domain: "foo".to_string(), | ||
directives: vec!["img-src".to_string()], | ||
}; | ||
let item2 = Item { | ||
domain: "bar".to_string(), | ||
directives: vec!["img-src".to_string()], | ||
}; | ||
|
||
let domains: Collection = vec![item1, item2]; | ||
|
||
let directive = "img-src"; | ||
|
||
let result: Vec<String> = super::find(&directive, &domains); | ||
|
||
assert_eq!(result.len(), 2); | ||
assert_eq!(result[0], "foo".to_string()); | ||
assert_eq!(result[1], "bar".to_string()); | ||
} | ||
|
||
#[test] | ||
fn test_find_one() { | ||
let item1 = Item { | ||
domain: "foo".to_string(), | ||
directives: vec!["script-src".to_string()], | ||
}; | ||
let item2 = Item { | ||
domain: "bar".to_string(), | ||
directives: vec!["img-src".to_string()], | ||
}; | ||
|
||
let domains: Collection = vec![item1, item2]; | ||
|
||
let directive = "script-src"; | ||
|
||
let result: Vec<String> = super::find(&directive, &domains); | ||
|
||
assert_eq!(result.len(), 1); | ||
assert_eq!(result[0], "foo".to_string()); | ||
} | ||
|
||
#[test] | ||
fn test_find_none() { | ||
let item1 = Item { | ||
domain: "foo".to_string(), | ||
directives: vec!["script-src".to_string()], | ||
}; | ||
let item2 = Item { | ||
domain: "bar".to_string(), | ||
directives: vec!["img-src".to_string()], | ||
}; | ||
|
||
let domains: Collection = vec![item1, item2]; | ||
|
||
let directive = "connect-src"; | ||
|
||
let result: Vec<String> = super::find(&directive, &domains); | ||
|
||
assert!(result.is_empty()); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.