]> git.lizzy.rs Git - rust.git/commitdiff
For issue 53957: revise unit tests to focus on underlying bug of 23076.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Fri, 20 Mar 2020 15:36:57 +0000 (11:36 -0400)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Fri, 20 Mar 2020 17:56:25 +0000 (13:56 -0400)
Namely, this version focuses on the end-to-end behavior that the attempt to
create the UDP binding will fail, regardless of the semantics of how particular
DNS servers handle junk inputs.

(I spent some time trying to create a second more-focused test that would
sidestep the DNS resolution, but this is not possible without more invasive
changes to the internal infrastructure of `ToSocketAddrs` and what not. It is
not worth it.)

src/libstd/net/addr.rs

index 57cba6b1f7a1be6949bb0d85dd8d5a15e43f2d57..de6360cf020f5740cd3a31a5ff80a5d6748be1da 100644 (file)
@@ -989,11 +989,26 @@ fn to_socket_addr_string() {
         // s has been moved into the tsa call
     }
 
-    // FIXME: figure out why this fails on openbsd and fix it
     #[test]
-    #[cfg(not(any(windows, target_os = "openbsd")))]
-    fn to_socket_addr_str_bad() {
-        assert!(tsa("1200::AB00:1234::2552:7777:1313:34300").is_err());
+    fn bind_udp_socket_bad() {
+        // rust-lang/rust#53957: This is a regression test for a parsing problem
+        // discovered as part of issue rust-lang/rust#23076, where we were
+        // incorrectly parsing invalid input and then that would result in a
+        // successful `UdpSocket` binding when we would expect failure.
+        //
+        // At one time, this test was written as a call to `tsa` with
+        // INPUT_23076. However, that structure yields an unreliable test,
+        // because it ends up passing junk input to the DNS server, and some DNS
+        // servers will respond with `Ok` to such input, with the ip address of
+        // the DNS server itself.
+        //
+        // This form of the test is more robust: even when the DNS server
+        // returns its own address, it is still an error to bind a UDP socket to
+        // a non-local address, and so we still get an error here in that case.
+
+        const INPUT_23076: &'static str = "1200::AB00:1234::2552:7777:1313:34300";
+
+        assert!(crate::net::UdpSocket::bind(INPUT_23076).is_err())
     }
 
     #[test]