chore(constants): internal/constants/vpn package

This commit is contained in:
Quentin McGaw
2022-04-18 09:15:20 +00:00
parent d51514015f
commit 934fafb64b
25 changed files with 193 additions and 183 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/openvpn/extract"
"github.com/qdm12/gluetun/internal/provider/utils"
@@ -19,9 +20,9 @@ var (
func (p *Provider) GetConnection(selection settings.ServerSelection) (
connection models.Connection, err error) {
switch selection.VPN {
case constants.OpenVPN:
case vpn.OpenVPN:
return getOpenVPNConnection(p.extractor, selection)
case constants.Wireguard:
case vpn.Wireguard:
return getWireguardConnection(selection), nil
default:
return connection, fmt.Errorf("%w: %s", ErrVPNTypeNotSupported, selection.VPN)
@@ -44,7 +45,7 @@ func getWireguardConnection(selection settings.ServerSelection) (
connection models.Connection) {
port := getPort(*selection.Wireguard.EndpointPort, selection)
return models.Connection{
Type: constants.Wireguard,
Type: vpn.Wireguard,
IP: selection.Wireguard.EndpointIP,
Port: port,
Protocol: constants.UDP,

View File

@@ -9,6 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -35,7 +36,7 @@ func Test_Provider_GetConnection(t *testing.T) {
},
selection: settings.ServerSelection{}.WithDefaults(providers.Expressvpn),
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(1, 1, 1, 1),
Port: 1195,
Protocol: constants.UDP,
@@ -51,7 +52,7 @@ func Test_Provider_GetConnection(t *testing.T) {
{IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
},
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(2, 2, 2, 2),
Port: 1195,
Protocol: constants.UDP,
@@ -67,7 +68,7 @@ func Test_Provider_GetConnection(t *testing.T) {
{Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
},
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(2, 2, 2, 2),
Port: 1195,
Protocol: constants.UDP,

View File

@@ -9,6 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -29,13 +30,13 @@ func Test_Ivpn_GetConnection(t *testing.T) {
},
"no filter": {
servers: []models.Server{
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
},
selection: settings.ServerSelection{}.WithDefaults(providers.Ivpn),
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(1, 1, 1, 1),
Port: 1194,
Protocol: constants.UDP,
@@ -46,12 +47,12 @@ func Test_Ivpn_GetConnection(t *testing.T) {
TargetIP: net.IPv4(2, 2, 2, 2),
}.WithDefaults(providers.Ivpn),
servers: []models.Server{
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
},
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(2, 2, 2, 2),
Port: 1194,
Protocol: constants.UDP,
@@ -62,12 +63,12 @@ func Test_Ivpn_GetConnection(t *testing.T) {
Hostnames: []string{"b"},
}.WithDefaults(providers.Ivpn),
servers: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
{VPN: constants.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
{VPN: vpn.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
{VPN: vpn.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
{VPN: vpn.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
},
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(2, 2, 2, 2),
Port: 1194,
Protocol: constants.UDP,

View File

@@ -6,8 +6,8 @@ import (
"testing"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -30,15 +30,15 @@ func Test_Ivpn_filterServers(t *testing.T) {
},
"no filter": {
servers: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a", UDP: true},
{VPN: constants.OpenVPN, Hostname: "b", UDP: true},
{VPN: constants.OpenVPN, Hostname: "c", UDP: true},
{VPN: vpn.OpenVPN, Hostname: "a", UDP: true},
{VPN: vpn.OpenVPN, Hostname: "b", UDP: true},
{VPN: vpn.OpenVPN, Hostname: "c", UDP: true},
},
selection: settings.ServerSelection{}.WithDefaults(providers.Ivpn),
filtered: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a", UDP: true},
{VPN: constants.OpenVPN, Hostname: "b", UDP: true},
{VPN: constants.OpenVPN, Hostname: "c", UDP: true},
{VPN: vpn.OpenVPN, Hostname: "a", UDP: true},
{VPN: vpn.OpenVPN, Hostname: "b", UDP: true},
{VPN: vpn.OpenVPN, Hostname: "c", UDP: true},
},
},
"filter by country": {
@@ -46,12 +46,12 @@ func Test_Ivpn_filterServers(t *testing.T) {
Countries: []string{"b"},
}.WithDefaults(providers.Ivpn),
servers: []models.Server{
{VPN: constants.OpenVPN, Country: "a", UDP: true},
{VPN: constants.OpenVPN, Country: "b", UDP: true},
{VPN: constants.OpenVPN, Country: "c", UDP: true},
{VPN: vpn.OpenVPN, Country: "a", UDP: true},
{VPN: vpn.OpenVPN, Country: "b", UDP: true},
{VPN: vpn.OpenVPN, Country: "c", UDP: true},
},
filtered: []models.Server{
{VPN: constants.OpenVPN, Country: "b", UDP: true},
{VPN: vpn.OpenVPN, Country: "b", UDP: true},
},
},
"filter by city": {
@@ -59,12 +59,12 @@ func Test_Ivpn_filterServers(t *testing.T) {
Cities: []string{"b"},
}.WithDefaults(providers.Ivpn),
servers: []models.Server{
{VPN: constants.OpenVPN, City: "a", UDP: true},
{VPN: constants.OpenVPN, City: "b", UDP: true},
{VPN: constants.OpenVPN, City: "c", UDP: true},
{VPN: vpn.OpenVPN, City: "a", UDP: true},
{VPN: vpn.OpenVPN, City: "b", UDP: true},
{VPN: vpn.OpenVPN, City: "c", UDP: true},
},
filtered: []models.Server{
{VPN: constants.OpenVPN, City: "b", UDP: true},
{VPN: vpn.OpenVPN, City: "b", UDP: true},
},
},
"filter by ISP": {
@@ -72,12 +72,12 @@ func Test_Ivpn_filterServers(t *testing.T) {
ISPs: []string{"b"},
}.WithDefaults(providers.Ivpn),
servers: []models.Server{
{VPN: constants.OpenVPN, ISP: "a", UDP: true},
{VPN: constants.OpenVPN, ISP: "b", UDP: true},
{VPN: constants.OpenVPN, ISP: "c", UDP: true},
{VPN: vpn.OpenVPN, ISP: "a", UDP: true},
{VPN: vpn.OpenVPN, ISP: "b", UDP: true},
{VPN: vpn.OpenVPN, ISP: "c", UDP: true},
},
filtered: []models.Server{
{VPN: constants.OpenVPN, ISP: "b", UDP: true},
{VPN: vpn.OpenVPN, ISP: "b", UDP: true},
},
},
"filter by hostname": {
@@ -85,12 +85,12 @@ func Test_Ivpn_filterServers(t *testing.T) {
Hostnames: []string{"b"},
}.WithDefaults(providers.Ivpn),
servers: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a", UDP: true},
{VPN: constants.OpenVPN, Hostname: "b", UDP: true},
{VPN: constants.OpenVPN, Hostname: "c", UDP: true},
{VPN: vpn.OpenVPN, Hostname: "a", UDP: true},
{VPN: vpn.OpenVPN, Hostname: "b", UDP: true},
{VPN: vpn.OpenVPN, Hostname: "c", UDP: true},
},
filtered: []models.Server{
{VPN: constants.OpenVPN, Hostname: "b", UDP: true},
{VPN: vpn.OpenVPN, Hostname: "b", UDP: true},
},
},
"filter by protocol": {
@@ -100,12 +100,12 @@ func Test_Ivpn_filterServers(t *testing.T) {
},
}.WithDefaults(providers.Ivpn),
servers: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a", UDP: true},
{VPN: constants.OpenVPN, Hostname: "b", UDP: true, TCP: true},
{VPN: constants.OpenVPN, Hostname: "c", UDP: true},
{VPN: vpn.OpenVPN, Hostname: "a", UDP: true},
{VPN: vpn.OpenVPN, Hostname: "b", UDP: true, TCP: true},
{VPN: vpn.OpenVPN, Hostname: "c", UDP: true},
},
filtered: []models.Server{
{VPN: constants.OpenVPN, Hostname: "b", UDP: true, TCP: true},
{VPN: vpn.OpenVPN, Hostname: "b", UDP: true, TCP: true},
},
},
}

View File

@@ -9,6 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -29,13 +30,13 @@ func Test_Mullvad_GetConnection(t *testing.T) {
},
"no filter": {
servers: []models.Server{
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
},
selection: settings.ServerSelection{}.WithDefaults(providers.Mullvad),
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(1, 1, 1, 1),
Port: 1194,
Protocol: constants.UDP,
@@ -46,12 +47,12 @@ func Test_Mullvad_GetConnection(t *testing.T) {
TargetIP: net.IPv4(2, 2, 2, 2),
}.WithDefaults(providers.Mullvad),
servers: []models.Server{
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
},
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(2, 2, 2, 2),
Port: 1194,
Protocol: constants.UDP,
@@ -62,12 +63,12 @@ func Test_Mullvad_GetConnection(t *testing.T) {
Hostnames: []string{"b"},
}.WithDefaults(providers.Mullvad),
servers: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{VPN: constants.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
{VPN: vpn.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{VPN: vpn.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
{VPN: vpn.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
},
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(2, 2, 2, 2),
Port: 1194,
Protocol: constants.UDP,

View File

@@ -6,8 +6,8 @@ import (
"testing"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -30,28 +30,28 @@ func Test_Mullvad_filterServers(t *testing.T) {
},
"no filter": {
servers: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a"},
{VPN: constants.OpenVPN, Hostname: "b"},
{VPN: constants.OpenVPN, Hostname: "c"},
{VPN: vpn.OpenVPN, Hostname: "a"},
{VPN: vpn.OpenVPN, Hostname: "b"},
{VPN: vpn.OpenVPN, Hostname: "c"},
},
selection: settings.ServerSelection{}.WithDefaults(providers.Mullvad),
filtered: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a"},
{VPN: constants.OpenVPN, Hostname: "b"},
{VPN: constants.OpenVPN, Hostname: "c"},
{VPN: vpn.OpenVPN, Hostname: "a"},
{VPN: vpn.OpenVPN, Hostname: "b"},
{VPN: vpn.OpenVPN, Hostname: "c"},
},
},
"filter OpenVPN out": {
selection: settings.ServerSelection{
VPN: constants.Wireguard,
VPN: vpn.Wireguard,
}.WithDefaults(providers.Mullvad),
servers: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a"},
{VPN: constants.Wireguard, Hostname: "b"},
{VPN: constants.OpenVPN, Hostname: "c"},
{VPN: vpn.OpenVPN, Hostname: "a"},
{VPN: vpn.Wireguard, Hostname: "b"},
{VPN: vpn.OpenVPN, Hostname: "c"},
},
filtered: []models.Server{
{VPN: constants.Wireguard, Hostname: "b"},
{VPN: vpn.Wireguard, Hostname: "b"},
},
},
"filter by country": {
@@ -59,12 +59,12 @@ func Test_Mullvad_filterServers(t *testing.T) {
Countries: []string{"b"},
}.WithDefaults(providers.Mullvad),
servers: []models.Server{
{VPN: constants.OpenVPN, Country: "a"},
{VPN: constants.OpenVPN, Country: "b"},
{VPN: constants.OpenVPN, Country: "c"},
{VPN: vpn.OpenVPN, Country: "a"},
{VPN: vpn.OpenVPN, Country: "b"},
{VPN: vpn.OpenVPN, Country: "c"},
},
filtered: []models.Server{
{VPN: constants.OpenVPN, Country: "b"},
{VPN: vpn.OpenVPN, Country: "b"},
},
},
"filter by city": {
@@ -72,12 +72,12 @@ func Test_Mullvad_filterServers(t *testing.T) {
Cities: []string{"b"},
}.WithDefaults(providers.Mullvad),
servers: []models.Server{
{VPN: constants.OpenVPN, City: "a"},
{VPN: constants.OpenVPN, City: "b"},
{VPN: constants.OpenVPN, City: "c"},
{VPN: vpn.OpenVPN, City: "a"},
{VPN: vpn.OpenVPN, City: "b"},
{VPN: vpn.OpenVPN, City: "c"},
},
filtered: []models.Server{
{VPN: constants.OpenVPN, City: "b"},
{VPN: vpn.OpenVPN, City: "b"},
},
},
"filter by ISP": {
@@ -85,12 +85,12 @@ func Test_Mullvad_filterServers(t *testing.T) {
ISPs: []string{"b"},
}.WithDefaults(providers.Mullvad),
servers: []models.Server{
{VPN: constants.OpenVPN, ISP: "a"},
{VPN: constants.OpenVPN, ISP: "b"},
{VPN: constants.OpenVPN, ISP: "c"},
{VPN: vpn.OpenVPN, ISP: "a"},
{VPN: vpn.OpenVPN, ISP: "b"},
{VPN: vpn.OpenVPN, ISP: "c"},
},
filtered: []models.Server{
{VPN: constants.OpenVPN, ISP: "b"},
{VPN: vpn.OpenVPN, ISP: "b"},
},
},
"filter by hostname": {
@@ -98,12 +98,12 @@ func Test_Mullvad_filterServers(t *testing.T) {
Hostnames: []string{"b"},
}.WithDefaults(providers.Mullvad),
servers: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a"},
{VPN: constants.OpenVPN, Hostname: "b"},
{VPN: constants.OpenVPN, Hostname: "c"},
{VPN: vpn.OpenVPN, Hostname: "a"},
{VPN: vpn.OpenVPN, Hostname: "b"},
{VPN: vpn.OpenVPN, Hostname: "c"},
},
filtered: []models.Server{
{VPN: constants.OpenVPN, Hostname: "b"},
{VPN: vpn.OpenVPN, Hostname: "b"},
},
},
"filter by owned": {
@@ -111,12 +111,12 @@ func Test_Mullvad_filterServers(t *testing.T) {
OwnedOnly: boolPtr(true),
}.WithDefaults(providers.Mullvad),
servers: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a"},
{VPN: constants.OpenVPN, Hostname: "b", Owned: true},
{VPN: constants.OpenVPN, Hostname: "c"},
{VPN: vpn.OpenVPN, Hostname: "a"},
{VPN: vpn.OpenVPN, Hostname: "b", Owned: true},
{VPN: vpn.OpenVPN, Hostname: "c"},
},
filtered: []models.Server{
{VPN: constants.OpenVPN, Hostname: "b", Owned: true},
{VPN: vpn.OpenVPN, Hostname: "b", Owned: true},
},
},
}

View File

@@ -7,7 +7,7 @@ import (
"net"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
)
@@ -25,7 +25,7 @@ func PickConnection(connections []models.Connection,
return connection, ErrNoConnectionToPickFrom
}
if len(selection.TargetIP) > 0 && selection.VPN == constants.Wireguard {
if len(selection.TargetIP) > 0 && selection.VPN == vpn.Wireguard {
// we need the right public key
return getTargetIPConnection(connections, selection.TargetIP)
}

View File

@@ -2,13 +2,13 @@ package utils
import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
)
func GetPort(selection settings.ServerSelection,
defaultOpenVPNTCP, defaultOpenVPNUDP, defaultWireguard uint16) (port uint16) {
switch selection.VPN {
case constants.Wireguard:
case vpn.Wireguard:
customPort := *selection.Wireguard.EndpointPort
if customPort > 0 {
return customPort

View File

@@ -4,7 +4,7 @@ import (
"testing"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/stretchr/testify/assert"
)
@@ -30,7 +30,7 @@ func Test_GetPort(t *testing.T) {
},
"OpenVPN UDP": {
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
VPN: vpn.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(0),
TCP: boolPtr(false),
@@ -40,7 +40,7 @@ func Test_GetPort(t *testing.T) {
},
"OpenVPN TCP": {
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
VPN: vpn.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(0),
TCP: boolPtr(true),
@@ -50,7 +50,7 @@ func Test_GetPort(t *testing.T) {
},
"OpenVPN custom port": {
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
VPN: vpn.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(1234),
},
@@ -59,13 +59,13 @@ func Test_GetPort(t *testing.T) {
},
"Wireguard": {
selection: settings.ServerSelection{
VPN: constants.Wireguard,
VPN: vpn.Wireguard,
}.WithDefaults(""),
port: defaultWireguard,
},
"Wireguard custom port": {
selection: settings.ServerSelection{
VPN: constants.Wireguard,
VPN: vpn.Wireguard,
Wireguard: settings.WireguardSelection{
EndpointPort: uint16Ptr(1234),
},

View File

@@ -3,10 +3,11 @@ package utils
import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
)
func GetProtocol(selection settings.ServerSelection) (protocol string) {
if selection.VPN == constants.OpenVPN && *selection.OpenVPN.TCP {
if selection.VPN == vpn.OpenVPN && *selection.OpenVPN.TCP {
return constants.TCP
}
return constants.UDP
@@ -15,7 +16,7 @@ func GetProtocol(selection settings.ServerSelection) (protocol string) {
func FilterByProtocol(selection settings.ServerSelection,
serverTCP, serverUDP bool) (filtered bool) {
switch selection.VPN {
case constants.Wireguard:
case vpn.Wireguard:
return !serverUDP
default: // OpenVPN
wantTCP := *selection.OpenVPN.TCP

View File

@@ -5,6 +5,7 @@ import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/stretchr/testify/assert"
)
@@ -20,7 +21,7 @@ func Test_GetProtocol(t *testing.T) {
},
"OpenVPN UDP": {
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
VPN: vpn.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
TCP: boolPtr(false),
},
@@ -29,7 +30,7 @@ func Test_GetProtocol(t *testing.T) {
},
"OpenVPN TCP": {
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
VPN: vpn.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
TCP: boolPtr(true),
},
@@ -38,7 +39,7 @@ func Test_GetProtocol(t *testing.T) {
},
"Wireguard": {
selection: settings.ServerSelection{
VPN: constants.Wireguard,
VPN: vpn.Wireguard,
},
protocol: constants.UDP,
},
@@ -67,21 +68,21 @@ func Test_FilterByProtocol(t *testing.T) {
}{
"Wireguard and server has UDP": {
selection: settings.ServerSelection{
VPN: constants.Wireguard,
VPN: vpn.Wireguard,
},
serverUDP: true,
filtered: false,
},
"Wireguard and server has not UDP": {
selection: settings.ServerSelection{
VPN: constants.Wireguard,
VPN: vpn.Wireguard,
},
serverUDP: false,
filtered: true,
},
"OpenVPN UDP and server has UDP": {
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
VPN: vpn.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
TCP: boolPtr(false),
},
@@ -91,7 +92,7 @@ func Test_FilterByProtocol(t *testing.T) {
},
"OpenVPN UDP and server has not UDP": {
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
VPN: vpn.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
TCP: boolPtr(false),
},
@@ -101,7 +102,7 @@ func Test_FilterByProtocol(t *testing.T) {
},
"OpenVPN TCP and server has TCP": {
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
VPN: vpn.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
TCP: boolPtr(true),
},
@@ -111,7 +112,7 @@ func Test_FilterByProtocol(t *testing.T) {
},
"OpenVPN TCP and server has not TCP": {
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
VPN: vpn.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
TCP: boolPtr(true),
},

View File

@@ -9,6 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -25,7 +26,7 @@ func Test_Wevpn_GetConnection(t *testing.T) {
}{
"no server available": {
selection: settings.ServerSelection{
VPN: constants.OpenVPN,
VPN: vpn.OpenVPN,
}.WithDefaults(providers.Wevpn),
err: errors.New("no server found: for VPN openvpn; protocol udp"),
},
@@ -37,7 +38,7 @@ func Test_Wevpn_GetConnection(t *testing.T) {
},
selection: settings.ServerSelection{}.WithDefaults(providers.Wevpn),
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(1, 1, 1, 1),
Port: 1194,
Protocol: constants.UDP,
@@ -53,7 +54,7 @@ func Test_Wevpn_GetConnection(t *testing.T) {
{UDP: true, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
},
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(2, 2, 2, 2),
Port: 1194,
Protocol: constants.UDP,
@@ -69,7 +70,7 @@ func Test_Wevpn_GetConnection(t *testing.T) {
{UDP: true, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
},
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(2, 2, 2, 2),
Port: 1194,
Protocol: constants.UDP,

View File

@@ -9,6 +9,7 @@ import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -29,13 +30,13 @@ func Test_Windscribe_GetConnection(t *testing.T) {
},
"no filter": {
servers: []models.Server{
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
},
selection: settings.ServerSelection{}.WithDefaults(providers.Windscribe),
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(1, 1, 1, 1),
Port: 1194,
Protocol: constants.UDP,
@@ -46,12 +47,12 @@ func Test_Windscribe_GetConnection(t *testing.T) {
TargetIP: net.IPv4(2, 2, 2, 2),
}.WithDefaults(providers.Windscribe),
servers: []models.Server{
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
{VPN: constants.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
{VPN: vpn.OpenVPN, IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
},
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(2, 2, 2, 2),
Port: 1194,
Protocol: constants.UDP,
@@ -62,12 +63,12 @@ func Test_Windscribe_GetConnection(t *testing.T) {
Hostnames: []string{"b"},
}.WithDefaults(providers.Windscribe),
servers: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{VPN: constants.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
{VPN: constants.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
{VPN: vpn.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{VPN: vpn.OpenVPN, Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}},
{VPN: vpn.OpenVPN, Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}},
},
connection: models.Connection{
Type: constants.OpenVPN,
Type: vpn.OpenVPN,
IP: net.IPv4(2, 2, 2, 2),
Port: 1194,
Protocol: constants.UDP,

View File

@@ -6,8 +6,8 @@ import (
"testing"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -28,28 +28,28 @@ func Test_Windscribe_filterServers(t *testing.T) {
},
"no filter": {
servers: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a"},
{VPN: constants.OpenVPN, Hostname: "b"},
{VPN: constants.OpenVPN, Hostname: "c"},
{VPN: vpn.OpenVPN, Hostname: "a"},
{VPN: vpn.OpenVPN, Hostname: "b"},
{VPN: vpn.OpenVPN, Hostname: "c"},
},
selection: settings.ServerSelection{}.WithDefaults(providers.Windscribe),
filtered: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a"},
{VPN: constants.OpenVPN, Hostname: "b"},
{VPN: constants.OpenVPN, Hostname: "c"},
{VPN: vpn.OpenVPN, Hostname: "a"},
{VPN: vpn.OpenVPN, Hostname: "b"},
{VPN: vpn.OpenVPN, Hostname: "c"},
},
},
"filter OpenVPN out": {
selection: settings.ServerSelection{
VPN: constants.Wireguard,
VPN: vpn.Wireguard,
}.WithDefaults(providers.Windscribe),
servers: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a"},
{VPN: constants.Wireguard, Hostname: "b"},
{VPN: constants.OpenVPN, Hostname: "c"},
{VPN: vpn.OpenVPN, Hostname: "a"},
{VPN: vpn.Wireguard, Hostname: "b"},
{VPN: vpn.OpenVPN, Hostname: "c"},
},
filtered: []models.Server{
{VPN: constants.Wireguard, Hostname: "b"},
{VPN: vpn.Wireguard, Hostname: "b"},
},
},
"filter by region": {
@@ -57,12 +57,12 @@ func Test_Windscribe_filterServers(t *testing.T) {
Regions: []string{"b"},
}.WithDefaults(providers.Windscribe),
servers: []models.Server{
{VPN: constants.OpenVPN, Region: "a"},
{VPN: constants.OpenVPN, Region: "b"},
{VPN: constants.OpenVPN, Region: "c"},
{VPN: vpn.OpenVPN, Region: "a"},
{VPN: vpn.OpenVPN, Region: "b"},
{VPN: vpn.OpenVPN, Region: "c"},
},
filtered: []models.Server{
{VPN: constants.OpenVPN, Region: "b"},
{VPN: vpn.OpenVPN, Region: "b"},
},
},
"filter by city": {
@@ -70,12 +70,12 @@ func Test_Windscribe_filterServers(t *testing.T) {
Cities: []string{"b"},
}.WithDefaults(providers.Windscribe),
servers: []models.Server{
{VPN: constants.OpenVPN, City: "a"},
{VPN: constants.OpenVPN, City: "b"},
{VPN: constants.OpenVPN, City: "c"},
{VPN: vpn.OpenVPN, City: "a"},
{VPN: vpn.OpenVPN, City: "b"},
{VPN: vpn.OpenVPN, City: "c"},
},
filtered: []models.Server{
{VPN: constants.OpenVPN, City: "b"},
{VPN: vpn.OpenVPN, City: "b"},
},
},
"filter by hostname": {
@@ -83,12 +83,12 @@ func Test_Windscribe_filterServers(t *testing.T) {
Hostnames: []string{"b"},
}.WithDefaults(providers.Windscribe),
servers: []models.Server{
{VPN: constants.OpenVPN, Hostname: "a"},
{VPN: constants.OpenVPN, Hostname: "b"},
{VPN: constants.OpenVPN, Hostname: "c"},
{VPN: vpn.OpenVPN, Hostname: "a"},
{VPN: vpn.OpenVPN, Hostname: "b"},
{VPN: vpn.OpenVPN, Hostname: "c"},
},
filtered: []models.Server{
{VPN: constants.OpenVPN, Hostname: "b"},
{VPN: vpn.OpenVPN, Hostname: "b"},
},
},
}