This repository was archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
This repository was archived by the owner on Aug 1, 2023. It is now read-only.
Write tests for parse_and_validate_args #1
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Description
Some tests for parse_and_validate_args would be quite nice.
Lines 61 to 102 in 2d08c76
| /// Parse and validate the arguments | |
| /// | |
| /// The first argument must be `--proxy-addr=127.70.74.[0-9]{1,3}` or `--help`. | |
| /// All other arguments are optional. Currently supported are `--blocklist=[A-Za-z0-9._-]+` and | |
| /// `--whitelist=[A-Za-z0-9._-]+` in any order and number. | |
| fn parse_and_validate_args<T: Iterator<Item = String>>(args: &mut T) -> (String, Vec<String>) { | |
| // validate first commandline arg (--proxy-addr) | |
| let proxy_addr = { | |
| let arg_1 = args | |
| .next() | |
| .expect("No command-line arguments given. --proxy-addr must be given."); | |
| if arg_1 == "--help" { | |
| help() | |
| } | |
| if arg_1.starts_with("--proxy-addr=127.70.74.") | |
| && arg_1[23..].chars().all(|c| c.is_ascii_digit()) | |
| && 24 <= arg_1.len() | |
| && arg_1.len() <= 26 | |
| { | |
| arg_1 | |
| } else { | |
| panic!( | |
| "Invalid first argument, must be --help or --proxy-addr with a allowed IP-address." | |
| ); | |
| } | |
| }; | |
| // parse left over commandline args, keep only '--whitelist=[A-Za-z0-9._-]*' | |
| // and '--blocklist=[A-Za-z0-9._-]*' | |
| let fdns_args = args | |
| .filter(|arg| { | |
| (arg.starts_with("--blocklist=") || arg.starts_with("--whitelist=")) | |
| && arg[12..] | |
| .chars() | |
| .all(|c| c.is_ascii_alphanumeric() || c == '.' || c == '-' || c == '_') | |
| }) | |
| .collect::<Vec<_>>(); | |
| (proxy_addr, fdns_args) | |
| } |
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed