Move the tools' arguments and the host rules to proto
Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
//! Host names and patterns, shared by `brokerd` and `toolkit`'s egress proxy. The full tables are
|
||||
//! in `crates/brokerd/tests/args.rs`, which reaches these through `brokerd::args`. Do not edit.
|
||||
|
||||
use proto::hosts::{host_matches, valid_host, valid_host_pattern};
|
||||
|
||||
#[test]
|
||||
fn hosts() {
|
||||
for good in ["example.com", "a.b.example.com", "x-1.example.org", "a.b"] {
|
||||
assert!(valid_host(good), "{good}");
|
||||
}
|
||||
for bad in [
|
||||
"",
|
||||
"example",
|
||||
"Example.com",
|
||||
"-a.com",
|
||||
"a-.com",
|
||||
"a..com",
|
||||
".a.com",
|
||||
"a.com.",
|
||||
"127.0.0.1",
|
||||
"127.1",
|
||||
"1.2.3.4x",
|
||||
"[::1]",
|
||||
"a_b.com",
|
||||
"a.com:443",
|
||||
"*.a.com",
|
||||
] {
|
||||
assert!(!valid_host(bad), "{bad}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn patterns() {
|
||||
assert!(valid_host_pattern("example.com"));
|
||||
assert!(valid_host_pattern("*.example.com"));
|
||||
for bad in ["*", "*.", "*.*.a.com", "a.*.com", "**.a.com", "*a.com"] {
|
||||
assert!(!valid_host_pattern(bad), "{bad}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn matching() {
|
||||
assert!(host_matches("example.com", "example.com"));
|
||||
assert!(!host_matches("example.com", "www.example.com"));
|
||||
assert!(host_matches("*.example.com", "www.example.com"));
|
||||
assert!(host_matches("*.example.com", "a.b.example.com"));
|
||||
assert!(!host_matches("*.example.com", "example.com"));
|
||||
assert!(!host_matches("*.example.com", "badexample.com"));
|
||||
assert!(!host_matches("*.example.com", ".example.com"));
|
||||
}
|
||||
Reference in New Issue
Block a user