33 lines
1000 B
Rust
33 lines
1000 B
Rust
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
|
|
|
use crate::client::{OutboundHttpPolicy, ip_match_hosts};
|
|
|
|
#[test]
|
|
fn denied_resolved_ip_overrides_explicitly_allowed_hostname() {
|
|
let policy = OutboundHttpPolicy::try_new_with_limits(
|
|
vec!["api.example.test".to_owned()],
|
|
vec!["169.254.169.254".to_owned()],
|
|
4 * 1024 * 1024,
|
|
4 * 1024 * 1024,
|
|
)
|
|
.unwrap();
|
|
|
|
assert!(policy.is_explicitly_allowed("api.example.test"));
|
|
assert!(policy.is_denied_ip(IpAddr::V4(Ipv4Addr::new(169, 254, 169, 254))));
|
|
}
|
|
|
|
#[test]
|
|
fn denied_resolved_ip_checks_ipv4_mapped_ipv6_alias() {
|
|
let policy = OutboundHttpPolicy::try_new_with_limits(
|
|
vec!["api.example.test".to_owned()],
|
|
vec!["127.0.0.1".to_owned()],
|
|
4 * 1024 * 1024,
|
|
4 * 1024 * 1024,
|
|
)
|
|
.unwrap();
|
|
let mapped = IpAddr::V6(Ipv6Addr::from(0xffff_7f00_0001u128));
|
|
|
|
assert!(ip_match_hosts(mapped).contains(&"127.0.0.1".to_owned()));
|
|
assert!(policy.is_denied_ip(mapped));
|
|
}
|