-
Notifications
You must be signed in to change notification settings - Fork 58
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 #7 from RobDWaller/0.2.0-beta.1
0.2.0 beta.1
- Loading branch information
Showing
9 changed files
with
69 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ jobs: | |
- run: rustup component add rustfmt | ||
- run: cargo build | ||
- run: cargo test | ||
- run: cargo fmt -- --check | ||
- run: cargo clippy --all-targets --all-features -- -D warnings | ||
- run: cargo lint | ||
- run: cargo analyse | ||
- name: Code Coverage | ||
uses: actions-rs/[email protected] | ||
with: | ||
|
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "csp_generator" | ||
description = "Consume a JSON formatted list of domains and CSP directives and output a correctly formatted Content Security Policy string." | ||
version = "0.2.0-beta" | ||
version = "0.2.0-beta.1" | ||
authors = ["Rob Waller <[email protected]>"] | ||
edition = "2018" | ||
keywords = ["csp", "json", "content-security", "csp-generator", "security"] | ||
|
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 |
---|---|---|
@@ -1,42 +1,80 @@ | ||
#[derive(Serialize, Deserialize, Clone)] | ||
#[derive(Deserialize, Serialize, Clone)] | ||
pub struct Item { | ||
pub domain: String, | ||
pub directive: Vec<String>, | ||
pub directives: Vec<String>, | ||
} | ||
|
||
pub type Collection = Vec<Item>; | ||
|
||
pub trait ToJson { | ||
fn to_json(&self) -> String; | ||
} | ||
|
||
impl ToJson for Collection { | ||
fn to_json(&self) -> String { | ||
let mut json = "[".to_string(); | ||
|
||
for item in self { | ||
json.push_str(serde_json::to_string(&item).unwrap().as_str()); | ||
} | ||
|
||
json.push_str("]"); | ||
|
||
json | ||
} | ||
} | ||
|
||
// ----- | ||
// Tests | ||
// ----- | ||
#[cfg(test)] | ||
mod item_test { | ||
use super::{Collection, Item, ToJson}; | ||
|
||
#[test] | ||
fn test_item_struct() { | ||
let directives: Vec<String> = vec![String::from("connect-src"), String::from("script-src")]; | ||
|
||
let item = super::Item { | ||
let item = Item { | ||
domain: String::from("*.example.com"), | ||
directive: directives, | ||
directives, | ||
}; | ||
|
||
assert_eq!(item.domain, "*.example.com"); | ||
assert_eq!(item.directive[1], "script-src"); | ||
assert_eq!(item.directives[1], "script-src"); | ||
} | ||
|
||
#[test] | ||
fn test_collection() { | ||
let directives: Vec<String> = vec![String::from("connect-src"), String::from("script-src")]; | ||
|
||
let item = super::Item { | ||
let item = Item { | ||
domain: String::from("*.example.com"), | ||
directive: directives, | ||
directives, | ||
}; | ||
|
||
let mut domains: super::Collection = vec![]; | ||
let mut domains: Collection = Collection::new(); | ||
domains.push(item); | ||
|
||
assert_eq!(domains[0].domain, "*.example.com"); | ||
assert_eq!(domains[0].directive[1], "script-src"); | ||
assert_eq!(domains[0].directives[1], "script-src"); | ||
} | ||
|
||
#[test] | ||
fn test_to_json() { | ||
let directives: Vec<String> = vec![String::from("connect-src"), String::from("script-src")]; | ||
|
||
let item = super::Item { | ||
domain: String::from("*.example.com"), | ||
directives, | ||
}; | ||
|
||
let mut domains: Collection = Collection::new(); | ||
domains.push(item); | ||
|
||
assert_eq!( | ||
domains.to_json(), | ||
r#"[{"domain":"*.example.com","directives":["connect-src","script-src"]}]"# | ||
); | ||
} | ||
} |
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