Skip to content

Commit 2f70789

Browse files
committed
test: include test for zero-port number
1 parent 7a88d40 commit 2f70789

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/uri/authority.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,15 @@ mod tests {
736736
assert_eq!(err.0, ErrorKind::InvalidAuthority);
737737
}
738738

739+
#[test]
740+
fn allows_from_simplest_ipv4() {
741+
let localhost0 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 0);
742+
743+
let auth1: Authority = Authority::from_sockaddr(localhost0).unwrap();
744+
assert_eq!(auth1.port(), None);
745+
assert_eq!(auth1.host(), "127.0.0.1");
746+
}
747+
739748
#[test]
740749
fn allows_from_simple_ipv4() {
741750
let localhost8080 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
@@ -755,6 +764,19 @@ mod tests {
755764
assert_eq!(auth1.host(), "[2001:db8::1]");
756765
}
757766

767+
#[test]
768+
fn allows_from_scoped_ipv6() {
769+
let example0scope2 = SocketAddrV6::new(Ipv6Addr::new(0x2001, 0x0db8, 0,0,
770+
0,0,0,1),
771+
0, /* port number */
772+
0, /* flowid */
773+
2 /* scopeid */);
774+
let auth1: Authority = Authority::from_sockaddr(std::net::SocketAddr::V6(example0scope2)).unwrap();
775+
assert_eq!(auth1.port(), None);
776+
assert_eq!(auth1.host(), "[2001:db8::1%2]");
777+
778+
}
779+
758780
#[test]
759781
fn allows_from_complex_ipv6() {
760782
let example8080scope1 = SocketAddrV6::new(Ipv6Addr::new(0x2001, 0x0db8, 0,0,

0 commit comments

Comments
 (0)