From f4d519092b4050a42fa3ec6060461dc1ac47f3eb Mon Sep 17 00:00:00 2001 From: Frank Denis <124872+jedisct1@users.noreply.github.com> Date: Wed, 10 Jun 2020 20:24:41 +0200 Subject: [PATCH] sources_test: set bit 16 of the port instead of adding zeros (#1358) Ok @welwood08 --- dnscrypt-proxy/sources_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dnscrypt-proxy/sources_test.go b/dnscrypt-proxy/sources_test.go index 98b953d9..8e738b6f 100644 --- a/dnscrypt-proxy/sources_test.go +++ b/dnscrypt-proxy/sources_test.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "fmt" "io/ioutil" "net/http" "net/http/httptest" @@ -300,6 +301,7 @@ func prepSourceTestDownload(t *testing.T, d *SourceTestData, e *SourceTestExpect } for _, state := range downloadTest { path := "/" + strconv.FormatUint(uint64(state), 10) + "/" + source + serverURL := d.server.URL switch state { case TestStateMissing, TestStateMissingSig: e.err = "404 Not Found" @@ -308,16 +310,20 @@ func prepSourceTestDownload(t *testing.T, d *SourceTestData, e *SourceTestExpect case TestStateReadErr, TestStateReadSigErr: e.err = "unexpected EOF" case TestStateOpenErr, TestStateOpenSigErr: - path = "00000" + path // high numeric port should be parsed but then fail to connect + if u, err := url.Parse(serverURL + path); err == nil { + host, port := ExtractHostAndPort(u.Host, -1) + u.Host = fmt.Sprintf("%s:%d", host, port|0x10000) + serverURL = u.String() + } // Win10 treats an invalid port as part of the hostname, then tries DNS lookup and magic http->https upgrades simultaneously e.err = "invalid port|no such host|too many colons in address" case TestStatePathErr: path = "..." + path // non-numeric port fails URL parsing } - if u, err := url.Parse(d.server.URL + path); err == nil { + if u, err := url.Parse(serverURL + path); err == nil { e.Source.urls = append(e.Source.urls, u) } - e.urls = append(e.urls, d.server.URL+path) + e.urls = append(e.urls, serverURL+path) if e.success { continue }