diff --git a/pkg/pmapi/dialer_proxy.go b/pkg/pmapi/dialer_proxy.go index 137fbca3..f39ea86a 100644 --- a/pkg/pmapi/dialer_proxy.go +++ b/pkg/pmapi/dialer_proxy.go @@ -60,11 +60,16 @@ func formatAsAddress(rawURL string) string { panic(err) } + host := url.Host + if host == "" { + host = url.Path + } + port := "443" if url.Scheme == "http" { port = "80" } - return net.JoinHostPort(url.Host, port) + return net.JoinHostPort(host, port) } // DialTLS dials the given network/address. If it fails, it retries using a proxy. diff --git a/pkg/pmapi/dialer_proxy_provider.go b/pkg/pmapi/dialer_proxy_provider.go index 6cedef8a..1526bf2d 100644 --- a/pkg/pmapi/dialer_proxy_provider.go +++ b/pkg/pmapi/dialer_proxy_provider.go @@ -36,11 +36,16 @@ const ( proxyDoHTimeout = 20 * time.Second proxyCanReachTimeout = 20 * time.Second proxyQuery = "dMFYGSLTQOJXXI33ONVQWS3BOMNUA.protonpro.xyz" + + Quad9Provider = "https://dns11.quad9.net/dns-query" + Quad9PortProvider = "https://dns11.quad9.net:5053/dns-query" + GoogleProvider = "https://dns.google/dns-query" ) var dohProviders = []string{ //nolint[gochecknoglobals] - "https://dns11.quad9.net/dns-query", - "https://dns.google/dns-query", + Quad9Provider, + Quad9PortProvider, + GoogleProvider, } // proxyProvider manages known proxies. diff --git a/pkg/pmapi/dialer_proxy_provider_test.go b/pkg/pmapi/dialer_proxy_provider_test.go index a036f401..4fca808d 100644 --- a/pkg/pmapi/dialer_proxy_provider_test.go +++ b/pkg/pmapi/dialer_proxy_provider_test.go @@ -27,12 +27,6 @@ import ( "golang.org/x/net/http/httpproxy" ) -const ( - TestDoHQuery = "dMFYGSLTQOJXXI33ONVQWS3BOMNUA.protonpro.xyz" - TestQuad9Provider = "https://dns11.quad9.net/dns-query" - TestGoogleProvider = "https://dns.google/dns-query" -) - func TestProxyProvider_FindProxy(t *testing.T) { proxy := getTrustedServer() defer closeServer(proxy) @@ -142,17 +136,28 @@ func TestProxyProvider_FindProxy_CanReachTimeout(t *testing.T) { } func TestProxyProvider_DoHLookup_Quad9(t *testing.T) { - p := newProxyProvider(Config{}, []string{TestQuad9Provider, TestGoogleProvider}, TestDoHQuery) + p := newProxyProvider(Config{}, []string{Quad9Provider, GoogleProvider}, proxyQuery) - records, err := p.dohLookup(context.Background(), TestDoHQuery, TestQuad9Provider) + records, err := p.dohLookup(context.Background(), proxyQuery, Quad9Provider) + r.NoError(t, err) + r.NotEmpty(t, records) +} + +// DISABLEDTestProxyProvider_DoHLookup_Quad9Port cannot run on CI due to custom +// port filter. Basic functionality should be covered by other tests. Keeping +// code here to be able to run it locally if needed. +func DISABLEDTestProxyProviderDoHLookupQuad9Port(t *testing.T) { + p := newProxyProvider(Config{}, []string{Quad9PortProvider, GoogleProvider}, proxyQuery) + + records, err := p.dohLookup(context.Background(), proxyQuery, Quad9PortProvider) r.NoError(t, err) r.NotEmpty(t, records) } func TestProxyProvider_DoHLookup_Google(t *testing.T) { - p := newProxyProvider(Config{}, []string{TestQuad9Provider, TestGoogleProvider}, TestDoHQuery) + p := newProxyProvider(Config{}, []string{Quad9Provider, GoogleProvider}, proxyQuery) - records, err := p.dohLookup(context.Background(), TestDoHQuery, TestGoogleProvider) + records, err := p.dohLookup(context.Background(), proxyQuery, GoogleProvider) r.NoError(t, err) r.NotEmpty(t, records) } @@ -160,7 +165,7 @@ func TestProxyProvider_DoHLookup_Google(t *testing.T) { func TestProxyProvider_DoHLookup_FindProxy(t *testing.T) { skipIfProxyIsSet(t) - p := newProxyProvider(Config{}, []string{TestQuad9Provider, TestGoogleProvider}, TestDoHQuery) + p := newProxyProvider(Config{}, []string{Quad9Provider, GoogleProvider}, proxyQuery) url, err := p.findReachableServer() r.NoError(t, err) @@ -170,7 +175,7 @@ func TestProxyProvider_DoHLookup_FindProxy(t *testing.T) { func TestProxyProvider_DoHLookup_FindProxyFirstProviderUnreachable(t *testing.T) { skipIfProxyIsSet(t) - p := newProxyProvider(Config{}, []string{"https://unreachable", TestQuad9Provider, TestGoogleProvider}, TestDoHQuery) + p := newProxyProvider(Config{}, []string{"https://unreachable", Quad9Provider, GoogleProvider}, proxyQuery) url, err := p.findReachableServer() r.NoError(t, err) diff --git a/pkg/pmapi/dialer_proxy_test.go b/pkg/pmapi/dialer_proxy_test.go index aef64576..039a13ff 100644 --- a/pkg/pmapi/dialer_proxy_test.go +++ b/pkg/pmapi/dialer_proxy_test.go @@ -251,3 +251,18 @@ func TestProxyDialer_UseProxy_FindSecondAlternativeIfFirstFailsAndAPIIsStillBloc require.NoError(t, err) require.Equal(t, formatAsAddress(proxy2.URL), d.proxyAddress) } + +func TestFormatAsAddress(t *testing.T) { + r := require.New(t) + testData := map[string]string{ + "sub.domain.tld": "sub.domain.tld:443", + "http://sub.domain.tld": "sub.domain.tld:80", + "https://sub.domain.tld": "sub.domain.tld:443", + "ftp://sub.domain.tld": "sub.domain.tld:443", + "//sub.domain.tld": "sub.domain.tld:443", + } + + for rawURL, wantURL := range testData { + r.Equal(wantURL, formatAsAddress(rawURL)) + } +}