chore(storage): omit empty fields in servers.json
This commit is contained in:
@@ -5,188 +5,188 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CyberghostServer struct {
|
type CyberghostServer struct {
|
||||||
Country string `json:"country"`
|
Country string `json:"country,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp,omitempty"`
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExpressvpnServer struct {
|
type ExpressvpnServer struct {
|
||||||
Country string `json:"country"`
|
Country string `json:"country,omitempty"`
|
||||||
City string `json:"city,omitempty"`
|
City string `json:"city,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp,omitempty"`
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FastestvpnServer struct {
|
type FastestvpnServer struct {
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp,omitempty"`
|
||||||
Country string `json:"country"`
|
Country string `json:"country,omitempty"`
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type HideMyAssServer struct {
|
type HideMyAssServer struct {
|
||||||
Country string `json:"country"`
|
Country string `json:"country,omitempty"`
|
||||||
Region string `json:"region"`
|
Region string `json:"region,omitempty"`
|
||||||
City string `json:"city"`
|
City string `json:"city,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp,omitempty"`
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type IpvanishServer struct {
|
type IpvanishServer struct {
|
||||||
Country string `json:"country"`
|
Country string `json:"country,omitempty"`
|
||||||
City string `json:"city"`
|
City string `json:"city,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp,omitempty"`
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type IvpnServer struct {
|
type IvpnServer struct {
|
||||||
VPN string `json:"vpn"`
|
VPN string `json:"vpn,omitempty"`
|
||||||
Country string `json:"country"`
|
Country string `json:"country,omitempty"`
|
||||||
City string `json:"city"`
|
City string `json:"city,omitempty"`
|
||||||
ISP string `json:"isp"`
|
ISP string `json:"isp,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
WgPubKey string `json:"wgpubkey,omitempty"`
|
WgPubKey string `json:"wgpubkey,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp,omitempty"`
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MullvadServer struct {
|
type MullvadServer struct {
|
||||||
VPN string `json:"vpn"`
|
VPN string `json:"vpn,omitempty"`
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
IPsV6 []net.IP `json:"ipsv6"`
|
IPsV6 []net.IP `json:"ipsv6,omitempty"`
|
||||||
Country string `json:"country"`
|
Country string `json:"country,omitempty"`
|
||||||
City string `json:"city"`
|
City string `json:"city,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
ISP string `json:"isp"`
|
ISP string `json:"isp,omitempty"`
|
||||||
Owned bool `json:"owned"`
|
Owned bool `json:"owned,omitempty"`
|
||||||
WgPubKey string `json:"wgpubkey,omitempty"`
|
WgPubKey string `json:"wgpubkey,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NordvpnServer struct { //nolint:maligned
|
type NordvpnServer struct { //nolint:maligned
|
||||||
Region string `json:"region"`
|
Region string `json:"region,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
Number uint16 `json:"number"`
|
Number uint16 `json:"number,omitempty"`
|
||||||
IP net.IP `json:"ip"`
|
IP net.IP `json:"ip,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PerfectprivacyServer struct {
|
type PerfectprivacyServer struct {
|
||||||
City string `json:"city"` // primary key
|
City string `json:"city,omitempty"` // primary key
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PrivadoServer struct {
|
type PrivadoServer struct {
|
||||||
Country string `json:"country"`
|
Country string `json:"country,omitempty"`
|
||||||
Region string `json:"region"`
|
Region string `json:"region,omitempty"`
|
||||||
City string `json:"city"`
|
City string `json:"city,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
IP net.IP `json:"ip"`
|
IP net.IP `json:"ip,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PIAServer struct {
|
type PIAServer struct {
|
||||||
Region string `json:"region"`
|
Region string `json:"region,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
ServerName string `json:"server_name"`
|
ServerName string `json:"server_name,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp,omitempty"`
|
||||||
PortForward bool `json:"port_forward"`
|
PortForward bool `json:"port_forward,omitempty"`
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PrivatevpnServer struct {
|
type PrivatevpnServer struct {
|
||||||
Country string `json:"country"`
|
Country string `json:"country,omitempty"`
|
||||||
City string `json:"city"`
|
City string `json:"city,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
IPs []net.IP `json:"ip"`
|
IPs []net.IP `json:"ip,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProtonvpnServer struct {
|
type ProtonvpnServer struct {
|
||||||
Country string `json:"country"`
|
Country string `json:"country,omitempty"`
|
||||||
Region string `json:"region"`
|
Region string `json:"region,omitempty"`
|
||||||
City string `json:"city"`
|
City string `json:"city,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
EntryIP net.IP `json:"entry_ip"`
|
EntryIP net.IP `json:"entry_ip,omitempty"`
|
||||||
ExitIPs []net.IP `json:"exit_ip"` // TODO verify it matches with public IP once connected
|
ExitIPs []net.IP `json:"exit_ip,omitempty"` // TODO verify it matches with public IP once connected
|
||||||
}
|
}
|
||||||
|
|
||||||
type PurevpnServer struct {
|
type PurevpnServer struct {
|
||||||
Country string `json:"country"`
|
Country string `json:"country,omitempty"`
|
||||||
Region string `json:"region"`
|
Region string `json:"region,omitempty"`
|
||||||
City string `json:"city"`
|
City string `json:"city,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp,omitempty"`
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SurfsharkServer struct {
|
type SurfsharkServer struct {
|
||||||
Region string `json:"region"`
|
Region string `json:"region,omitempty"`
|
||||||
Country string `json:"country"` // Country is also used for multi-hop
|
Country string `json:"country,omitempty"` // Country is also used for multi-hop
|
||||||
City string `json:"city"`
|
City string `json:"city,omitempty"`
|
||||||
RetroLoc string `json:"retroloc"` // TODO remove in v4
|
RetroLoc string `json:"retroloc,omitempty"` // TODO remove in v4
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
MultiHop bool `json:"multihop"`
|
MultiHop bool `json:"multihop,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp,omitempty"`
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TorguardServer struct {
|
type TorguardServer struct {
|
||||||
Country string `json:"country"`
|
Country string `json:"country,omitempty"`
|
||||||
City string `json:"city"`
|
City string `json:"city,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp,omitempty"`
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type VPNUnlimitedServer struct {
|
type VPNUnlimitedServer struct {
|
||||||
Country string `json:"country"`
|
Country string `json:"country,omitempty"`
|
||||||
City string `json:"city"`
|
City string `json:"city,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
Free bool `json:"free"`
|
Free bool `json:"free,omitempty"`
|
||||||
Stream bool `json:"stream"`
|
Stream bool `json:"stream,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp,omitempty"`
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type VyprvpnServer struct {
|
type VyprvpnServer struct {
|
||||||
Region string `json:"region"`
|
Region string `json:"region,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"` // only support for UDP
|
UDP bool `json:"udp,omitempty"` // only support for UDP
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WevpnServer struct {
|
type WevpnServer struct {
|
||||||
City string `json:"city"`
|
City string `json:"city,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
TCP bool `json:"tcp"`
|
TCP bool `json:"tcp,omitempty"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp,omitempty"`
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WindscribeServer struct {
|
type WindscribeServer struct {
|
||||||
VPN string `json:"vpn"`
|
VPN string `json:"vpn,omitempty"`
|
||||||
Region string `json:"region"`
|
Region string `json:"region,omitempty"`
|
||||||
City string `json:"city"`
|
City string `json:"city,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname,omitempty"`
|
||||||
OvpnX509 string `json:"x509,omitempty"`
|
OvpnX509 string `json:"x509,omitempty"`
|
||||||
WgPubKey string `json:"wgpubkey,omitempty"`
|
WgPubKey string `json:"wgpubkey,omitempty"`
|
||||||
IPs []net.IP `json:"ips"`
|
IPs []net.IP `json:"ips,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
|
||||||
"encoding/hex"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,143 +14,3 @@ func Test_parseHardcodedServers(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotEmpty(t, len(servers.Cyberghost.Servers))
|
require.NotEmpty(t, len(servers.Cyberghost.Servers))
|
||||||
}
|
}
|
||||||
|
|
||||||
func digestServerModelVersion(t *testing.T, server interface{}, version uint16) string {
|
|
||||||
t.Helper()
|
|
||||||
bytes, err := json.Marshal(server)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
bytes = append(bytes, []byte(fmt.Sprintf("%d", version))...)
|
|
||||||
arr := sha256.Sum256(bytes)
|
|
||||||
hexString := hex.EncodeToString(arr[:])
|
|
||||||
if len(hexString) > 8 {
|
|
||||||
hexString = hexString[:8]
|
|
||||||
}
|
|
||||||
return hexString
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_versions(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
allServers, err := parseHardcodedServers()
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
const format = "you forgot to update the version for %s"
|
|
||||||
testCases := map[string]struct {
|
|
||||||
model interface{}
|
|
||||||
version uint16
|
|
||||||
digest string
|
|
||||||
}{
|
|
||||||
"Cyberghost": {
|
|
||||||
model: models.CyberghostServer{},
|
|
||||||
version: allServers.Cyberghost.Version,
|
|
||||||
digest: "9ce64729",
|
|
||||||
},
|
|
||||||
"Expressvpn": {
|
|
||||||
model: models.ExpressvpnServer{},
|
|
||||||
version: allServers.Expressvpn.Version,
|
|
||||||
digest: "6e54a351",
|
|
||||||
},
|
|
||||||
"Fastestvpn": {
|
|
||||||
model: models.FastestvpnServer{},
|
|
||||||
version: allServers.Fastestvpn.Version,
|
|
||||||
digest: "8825919b",
|
|
||||||
},
|
|
||||||
"HideMyAss": {
|
|
||||||
model: models.HideMyAssServer{},
|
|
||||||
version: allServers.HideMyAss.Version,
|
|
||||||
digest: "a93b4057",
|
|
||||||
},
|
|
||||||
"Ipvanish": {
|
|
||||||
model: models.IpvanishServer{},
|
|
||||||
version: allServers.Ipvanish.Version,
|
|
||||||
digest: "2eb80d28",
|
|
||||||
},
|
|
||||||
"Ivpn": {
|
|
||||||
model: models.IvpnServer{},
|
|
||||||
version: allServers.Ivpn.Version,
|
|
||||||
digest: "88074ceb",
|
|
||||||
},
|
|
||||||
"Mullvad": {
|
|
||||||
model: models.MullvadServer{},
|
|
||||||
version: allServers.Mullvad.Version,
|
|
||||||
digest: "ec56f19d",
|
|
||||||
},
|
|
||||||
"Nordvpn": {
|
|
||||||
model: models.NordvpnServer{},
|
|
||||||
version: allServers.Nordvpn.Version,
|
|
||||||
digest: "a8043704",
|
|
||||||
},
|
|
||||||
"Perfect privacy": {
|
|
||||||
model: models.PerfectprivacyServer{},
|
|
||||||
version: allServers.Perfectprivacy.Version,
|
|
||||||
digest: "233f0dd4",
|
|
||||||
},
|
|
||||||
"Privado": {
|
|
||||||
model: models.PrivadoServer{},
|
|
||||||
version: allServers.Privado.Version,
|
|
||||||
digest: "dba6736c",
|
|
||||||
},
|
|
||||||
"Private Internet Access": {
|
|
||||||
model: models.PIAServer{},
|
|
||||||
version: allServers.Pia.Version,
|
|
||||||
digest: "91db9bc9",
|
|
||||||
},
|
|
||||||
"Privatevpn": {
|
|
||||||
model: models.PrivatevpnServer{},
|
|
||||||
version: allServers.Privatevpn.Version,
|
|
||||||
digest: "cba13d78",
|
|
||||||
},
|
|
||||||
"Protonvpn": {
|
|
||||||
model: models.ProtonvpnServer{},
|
|
||||||
version: allServers.Protonvpn.Version,
|
|
||||||
digest: "4cb74c3a",
|
|
||||||
},
|
|
||||||
"Purevpn": {
|
|
||||||
model: models.PurevpnServer{},
|
|
||||||
version: allServers.Purevpn.Version,
|
|
||||||
digest: "23f2d422",
|
|
||||||
},
|
|
||||||
"Surfshark": {
|
|
||||||
model: models.SurfsharkServer{},
|
|
||||||
version: allServers.Surfshark.Version,
|
|
||||||
digest: "3ccaa772",
|
|
||||||
},
|
|
||||||
"Torguard": {
|
|
||||||
model: models.TorguardServer{},
|
|
||||||
version: allServers.Torguard.Version,
|
|
||||||
digest: "6eb9028e",
|
|
||||||
},
|
|
||||||
"VPN Unlimited": {
|
|
||||||
model: models.VPNUnlimitedServer{},
|
|
||||||
version: allServers.VPNUnlimited.Version,
|
|
||||||
digest: "5cb51319",
|
|
||||||
},
|
|
||||||
"Vyprvpn": {
|
|
||||||
model: models.VyprvpnServer{},
|
|
||||||
version: allServers.Vyprvpn.Version,
|
|
||||||
digest: "58de06d8",
|
|
||||||
},
|
|
||||||
"Wevpn": {
|
|
||||||
model: models.WevpnServer{},
|
|
||||||
version: allServers.Wevpn.Version,
|
|
||||||
digest: "f4daa186",
|
|
||||||
},
|
|
||||||
"Windscribe": {
|
|
||||||
model: models.WindscribeServer{},
|
|
||||||
version: allServers.Windscribe.Version,
|
|
||||||
digest: "4bd0fc4f",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for name, testCase := range testCases {
|
|
||||||
name := name
|
|
||||||
testCase := testCase
|
|
||||||
t.Run(name, func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
digest := digestServerModelVersion(t, testCase.model, testCase.version)
|
|
||||||
failureMessage := fmt.Sprintf(format, name)
|
|
||||||
assert.Equal(t, testCase.digest, digest, failureMessage)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user