-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
247 additions
and
5 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
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
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,72 @@ | ||
#[macro_use] | ||
#[allow(dead_code)] | ||
mod helper; | ||
|
||
use crate::helper::pfcli; | ||
use assert_matches::assert_matches; | ||
|
||
static ANCHOR_NAME: &str = "pfctl-rs.integration.testing.scrub-rules"; | ||
|
||
fn before_each() { | ||
pfctl::PfCtl::new() | ||
.unwrap() | ||
.try_add_anchor(ANCHOR_NAME, pfctl::AnchorKind::Scrub) | ||
.unwrap(); | ||
} | ||
|
||
fn after_each() { | ||
pfcli::flush_rules(ANCHOR_NAME, pfcli::FlushOptions::All); | ||
pfctl::PfCtl::new() | ||
.unwrap() | ||
.try_remove_anchor(ANCHOR_NAME, pfctl::AnchorKind::Scrub) | ||
.unwrap(); | ||
} | ||
|
||
fn scrub_rule() -> pfctl::ScrubRule { | ||
pfctl::ScrubRuleBuilder::default() | ||
.action(pfctl::ScrubRuleAction::Scrub) | ||
.build() | ||
.unwrap() | ||
} | ||
|
||
fn no_scrub_rule() -> pfctl::ScrubRule { | ||
pfctl::ScrubRuleBuilder::default() | ||
.action(pfctl::ScrubRuleAction::NoScrub) | ||
.build() | ||
.unwrap() | ||
} | ||
|
||
test!(flush_scrub_rules { | ||
let mut pf = pfctl::PfCtl::new().unwrap(); | ||
let test_rules = [scrub_rule(), no_scrub_rule()]; | ||
for rule in test_rules.iter() { | ||
assert_matches!(pf.add_scrub_rule(ANCHOR_NAME, rule), Ok(())); | ||
assert_eq!(pfcli::get_rules(ANCHOR_NAME).len(), 1); | ||
|
||
assert_matches!(pf.flush_rules(ANCHOR_NAME, pfctl::RulesetKind::Scrub), Ok(())); | ||
assert_eq!( | ||
pfcli::get_rules(ANCHOR_NAME), | ||
&[] as &[&str] | ||
); | ||
} | ||
}); | ||
|
||
test!(add_scrub_rule { | ||
let mut pf = pfctl::PfCtl::new().unwrap(); | ||
let rule = scrub_rule(); | ||
assert_matches!(pf.add_scrub_rule(ANCHOR_NAME, &rule), Ok(())); | ||
assert_eq!( | ||
pfcli::get_rules(ANCHOR_NAME), | ||
&["scrub all fragment reassemble"] | ||
); | ||
}); | ||
|
||
test!(add_no_scrub_rule { | ||
let mut pf = pfctl::PfCtl::new().unwrap(); | ||
let rule = no_scrub_rule(); | ||
assert_matches!(pf.add_scrub_rule(ANCHOR_NAME, &rule), Ok(())); | ||
assert_eq!( | ||
pfcli::get_rules(ANCHOR_NAME), | ||
&["no scrub all"] | ||
); | ||
}); |
Oops, something went wrong.