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