diff --git a/internal/provider/ivpn/connection_test.go b/internal/provider/ivpn/connection_test.go index e7ea9d37..3fd1fe4c 100644 --- a/internal/provider/ivpn/connection_test.go +++ b/internal/provider/ivpn/connection_test.go @@ -72,7 +72,7 @@ func Test_Provider_GetConnection(t *testing.T) { }, "default Wireguard port": { filteredServers: []models.Server{ - {IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, + {IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, WgPubKey: "x"}, }, selection: settings.ServerSelection{ VPN: vpn.Wireguard, @@ -82,6 +82,7 @@ func Test_Provider_GetConnection(t *testing.T) { IP: net.IPv4(1, 1, 1, 1), Port: 58237, Protocol: constants.UDP, + PubKey: "x", }, }, } diff --git a/internal/provider/mullvad/connection_test.go b/internal/provider/mullvad/connection_test.go index 93cb6c61..3eabab16 100644 --- a/internal/provider/mullvad/connection_test.go +++ b/internal/provider/mullvad/connection_test.go @@ -72,7 +72,7 @@ func Test_Provider_GetConnection(t *testing.T) { }, "default Wireguard port": { filteredServers: []models.Server{ - {IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, + {IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, WgPubKey: "x"}, }, selection: settings.ServerSelection{ VPN: vpn.Wireguard, @@ -82,6 +82,7 @@ func Test_Provider_GetConnection(t *testing.T) { IP: net.IPv4(1, 1, 1, 1), Port: 51820, Protocol: constants.UDP, + PubKey: "x", }, }, } diff --git a/internal/provider/utils/connection.go b/internal/provider/utils/connection.go index 24887a61..b3420045 100644 --- a/internal/provider/utils/connection.go +++ b/internal/provider/utils/connection.go @@ -1,6 +1,7 @@ package utils import ( + "errors" "fmt" "math/rand" @@ -29,6 +30,10 @@ type Storage interface { servers []models.Server, err error) } +var ( + ErrWireguardPublicKeyMissing = errors.New("wireguard public key is missing") +) + func GetConnection(provider string, storage Storage, selection settings.ServerSelection, @@ -52,6 +57,11 @@ func GetConnection(provider string, continue } + if selection.VPN == vpn.Wireguard && server.WgPubKey == "" { + return connection, fmt.Errorf("%w: for server hostname %s and ip %s", + ErrWireguardPublicKeyMissing, server.Hostname, ip) + } + hostname := server.Hostname if selection.VPN == vpn.OpenVPN && server.OvpnX509 != "" { // For Windscribe where hostname and diff --git a/internal/provider/wevpn/connection_test.go b/internal/provider/wevpn/connection_test.go index 979b53ca..02253b67 100644 --- a/internal/provider/wevpn/connection_test.go +++ b/internal/provider/wevpn/connection_test.go @@ -72,7 +72,7 @@ func Test_Provider_GetConnection(t *testing.T) { }, "default Wireguard port": { filteredServers: []models.Server{ - {IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, + {IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, WgPubKey: "x"}, }, selection: settings.ServerSelection{ VPN: vpn.Wireguard, diff --git a/internal/provider/windscribe/connection_test.go b/internal/provider/windscribe/connection_test.go index aac4a787..9c9e193d 100644 --- a/internal/provider/windscribe/connection_test.go +++ b/internal/provider/windscribe/connection_test.go @@ -73,7 +73,7 @@ func Test_Provider_GetConnection(t *testing.T) { }, "default Wireguard port": { filteredServers: []models.Server{ - {IPs: []net.IP{net.IPv4(1, 1, 1, 1)}}, + {IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, WgPubKey: "x"}, }, selection: settings.ServerSelection{ VPN: vpn.Wireguard, @@ -83,6 +83,7 @@ func Test_Provider_GetConnection(t *testing.T) { IP: net.IPv4(1, 1, 1, 1), Port: 1194, Protocol: constants.UDP, + PubKey: "x", }, }, }