mirror of
https://github.com/qdm12/gluetun.git
synced 2026-06-25 13:27:31 +02:00
Fix test to use a random port and not 443
This commit is contained in:
@@ -17,6 +17,7 @@ type Client struct {
|
||||
firewall Firewall
|
||||
outboundInterface string
|
||||
dohServers []provider.DoHServer
|
||||
httpsPort uint16
|
||||
}
|
||||
|
||||
func New(firewall Firewall, defaultInterface string, ipv6Supported bool,
|
||||
@@ -27,11 +28,13 @@ func New(firewall Firewall, defaultInterface string, ipv6Supported bool,
|
||||
dohServers[i] = upstreamResolver.DoH
|
||||
}
|
||||
|
||||
const defaultHTTPSPort = 443
|
||||
return &Client{
|
||||
firewall: firewall,
|
||||
outboundInterface: defaultInterface,
|
||||
ipv6Supported: ipv6Supported,
|
||||
dohServers: dohServers,
|
||||
httpsPort: defaultHTTPSPort,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -38,11 +38,12 @@ func Test_Client_OpenHTTPS(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
|
||||
netConfig := net.ListenConfig{}
|
||||
listener, err := netConfig.Listen(ctx, "tcp", "127.0.0.1:443")
|
||||
listener, err := netConfig.Listen(ctx, "tcp", "127.0.0.1:0")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
_ = listener.Close()
|
||||
})
|
||||
listeningPort := uint16(listener.Addr().(*net.TCPAddr).Port) //nolint:gosec,forcetypeassert
|
||||
go func() {
|
||||
connection, acceptErr := listener.Accept()
|
||||
if acceptErr == nil {
|
||||
@@ -53,7 +54,7 @@ func Test_Client_OpenHTTPS(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
firewall := NewMockFirewall(ctrl)
|
||||
|
||||
destination := netip.MustParseAddrPort("127.0.0.1:443")
|
||||
destination := netip.AddrPortFrom(netip.MustParseAddr("127.0.0.1"), listeningPort)
|
||||
sourceMatcher := listenAddrPortMatcher{}
|
||||
firewall.EXPECT().AcceptOutputFromIPPortToIPPort(
|
||||
ctx, "tcp", "eth0", sourceMatcher, destination, false,
|
||||
@@ -71,6 +72,7 @@ func Test_Client_OpenHTTPS(t *testing.T) {
|
||||
upstreamResolvers := []provider.Provider{provider.Google()}
|
||||
client, err := New(firewall, "eth0", ipv6Supported, upstreamResolvers)
|
||||
require.NoError(t, err)
|
||||
client.httpsPort = listeningPort
|
||||
|
||||
httpClient, cleanup, err := client.OpenHTTPS(ctx, "api.example.com", netip.MustParseAddr("127.0.0.1"))
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -24,8 +24,7 @@ func (c *Client) OpenHTTPS(ctx context.Context, destinationTLSName string, desti
|
||||
return nil, nil, fmt.Errorf("binding source port: %w", err)
|
||||
}
|
||||
|
||||
const httpsPort = 443
|
||||
destinationAddrPort := netip.AddrPortFrom(destinationIP, httpsPort)
|
||||
destinationAddrPort := netip.AddrPortFrom(destinationIP, c.httpsPort)
|
||||
|
||||
const remove = false
|
||||
err = c.firewall.AcceptOutputFromIPPortToIPPort(ctx, "tcp", c.outboundInterface,
|
||||
|
||||
Reference in New Issue
Block a user