chore(vpn): add check for empty public key for Wireguard

This commit is contained in:
Quentin McGaw
2022-06-12 15:41:02 +00:00
parent d4c6a9bdb5
commit 89b6a031b0
5 changed files with 17 additions and 4 deletions

View File

@@ -72,7 +72,7 @@ func Test_Provider_GetConnection(t *testing.T) {
}, },
"default Wireguard port": { "default Wireguard port": {
filteredServers: []models.Server{ 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{ selection: settings.ServerSelection{
VPN: vpn.Wireguard, VPN: vpn.Wireguard,
@@ -82,6 +82,7 @@ func Test_Provider_GetConnection(t *testing.T) {
IP: net.IPv4(1, 1, 1, 1), IP: net.IPv4(1, 1, 1, 1),
Port: 58237, Port: 58237,
Protocol: constants.UDP, Protocol: constants.UDP,
PubKey: "x",
}, },
}, },
} }

View File

@@ -72,7 +72,7 @@ func Test_Provider_GetConnection(t *testing.T) {
}, },
"default Wireguard port": { "default Wireguard port": {
filteredServers: []models.Server{ 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{ selection: settings.ServerSelection{
VPN: vpn.Wireguard, VPN: vpn.Wireguard,
@@ -82,6 +82,7 @@ func Test_Provider_GetConnection(t *testing.T) {
IP: net.IPv4(1, 1, 1, 1), IP: net.IPv4(1, 1, 1, 1),
Port: 51820, Port: 51820,
Protocol: constants.UDP, Protocol: constants.UDP,
PubKey: "x",
}, },
}, },
} }

View File

@@ -1,6 +1,7 @@
package utils package utils
import ( import (
"errors"
"fmt" "fmt"
"math/rand" "math/rand"
@@ -29,6 +30,10 @@ type Storage interface {
servers []models.Server, err error) servers []models.Server, err error)
} }
var (
ErrWireguardPublicKeyMissing = errors.New("wireguard public key is missing")
)
func GetConnection(provider string, func GetConnection(provider string,
storage Storage, storage Storage,
selection settings.ServerSelection, selection settings.ServerSelection,
@@ -52,6 +57,11 @@ func GetConnection(provider string,
continue 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 hostname := server.Hostname
if selection.VPN == vpn.OpenVPN && server.OvpnX509 != "" { if selection.VPN == vpn.OpenVPN && server.OvpnX509 != "" {
// For Windscribe where hostname and // For Windscribe where hostname and

View File

@@ -72,7 +72,7 @@ func Test_Provider_GetConnection(t *testing.T) {
}, },
"default Wireguard port": { "default Wireguard port": {
filteredServers: []models.Server{ 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{ selection: settings.ServerSelection{
VPN: vpn.Wireguard, VPN: vpn.Wireguard,

View File

@@ -73,7 +73,7 @@ func Test_Provider_GetConnection(t *testing.T) {
}, },
"default Wireguard port": { "default Wireguard port": {
filteredServers: []models.Server{ 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{ selection: settings.ServerSelection{
VPN: vpn.Wireguard, VPN: vpn.Wireguard,
@@ -83,6 +83,7 @@ func Test_Provider_GetConnection(t *testing.T) {
IP: net.IPv4(1, 1, 1, 1), IP: net.IPv4(1, 1, 1, 1),
Port: 1194, Port: 1194,
Protocol: constants.UDP, Protocol: constants.UDP,
PubKey: "x",
}, },
}, },
} }