-
-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
6,017 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ body: | |
- IVPN | ||
- Mullvad | ||
- NordVPN | ||
- OVPN | ||
- Privado | ||
- Private Internet Access | ||
- PrivateVPN | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package ovpn | ||
|
||
import ( | ||
"github.com/qdm12/gluetun/internal/configuration/settings" | ||
"github.com/qdm12/gluetun/internal/models" | ||
"github.com/qdm12/gluetun/internal/provider/utils" | ||
) | ||
|
||
func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) ( | ||
connection models.Connection, err error, | ||
) { | ||
defaults := utils.NewConnectionDefaults(443, 1194, 9929) //nolint:mnd | ||
return utils.GetConnection(p.Name(), | ||
p.storage, selection, defaults, ipv6Supported, p.randSource) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package ovpn | ||
|
||
import ( | ||
"errors" | ||
"math/rand" | ||
"net/http" | ||
"net/netip" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"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/qdm12/gluetun/internal/provider/common" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_Provider_GetConnection(t *testing.T) { | ||
t.Parallel() | ||
|
||
const provider = providers.Ovpn | ||
|
||
errTest := errors.New("test error") | ||
|
||
testCases := map[string]struct { | ||
filteredServers []models.Server | ||
storageErr error | ||
selection settings.ServerSelection | ||
ipv6Supported bool | ||
connection models.Connection | ||
errWrapped error | ||
errMessage string | ||
}{ | ||
"error": { | ||
storageErr: errTest, | ||
errWrapped: errTest, | ||
errMessage: "filtering servers: test error", | ||
}, | ||
"default_openvpn_tcp_port": { | ||
filteredServers: []models.Server{ | ||
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}}, | ||
}, | ||
selection: settings.ServerSelection{ | ||
OpenVPN: settings.OpenVPNSelection{ | ||
Protocol: constants.TCP, | ||
}, | ||
}.WithDefaults(provider), | ||
connection: models.Connection{ | ||
Type: vpn.OpenVPN, | ||
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}), | ||
Port: 443, | ||
Protocol: constants.TCP, | ||
}, | ||
}, | ||
"default_openvpn_udp_port": { | ||
filteredServers: []models.Server{ | ||
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}}, | ||
}, | ||
selection: settings.ServerSelection{ | ||
OpenVPN: settings.OpenVPNSelection{ | ||
Protocol: constants.UDP, | ||
}, | ||
}.WithDefaults(provider), | ||
connection: models.Connection{ | ||
Type: vpn.OpenVPN, | ||
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}), | ||
Port: 1194, | ||
Protocol: constants.UDP, | ||
}, | ||
}, | ||
"default_wireguard_port": { | ||
filteredServers: []models.Server{ | ||
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}, WgPubKey: "x"}, | ||
}, | ||
selection: settings.ServerSelection{ | ||
VPN: vpn.Wireguard, | ||
}.WithDefaults(provider), | ||
connection: models.Connection{ | ||
Type: vpn.Wireguard, | ||
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}), | ||
Port: 9929, | ||
Protocol: constants.UDP, | ||
PubKey: "x", | ||
}, | ||
}, | ||
"default_multihop_port": { | ||
filteredServers: []models.Server{ | ||
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}, WgPubKey: "x", PortsUDP: []uint16{30044}}, | ||
}, | ||
selection: settings.ServerSelection{ | ||
VPN: vpn.Wireguard, | ||
}.WithDefaults(provider), | ||
connection: models.Connection{ | ||
Type: vpn.Wireguard, | ||
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}), | ||
Port: 30044, | ||
Protocol: constants.UDP, | ||
PubKey: "x", | ||
}, | ||
}, | ||
} | ||
|
||
for name, testCase := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
ctrl := gomock.NewController(t) | ||
|
||
storage := common.NewMockStorage(ctrl) | ||
storage.EXPECT().FilterServers(provider, testCase.selection). | ||
Return(testCase.filteredServers, testCase.storageErr) | ||
randSource := rand.NewSource(0) | ||
|
||
client := (*http.Client)(nil) | ||
provider := New(storage, randSource, client) | ||
|
||
connection, err := provider.GetConnection(testCase.selection, testCase.ipv6Supported) | ||
|
||
assert.ErrorIs(t, err, testCase.errWrapped) | ||
if testCase.errWrapped != nil { | ||
assert.EqualError(t, err, testCase.errMessage) | ||
} | ||
|
||
assert.Equal(t, testCase.connection, connection) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ovpn | ||
|
||
import ( | ||
"github.com/qdm12/gluetun/internal/configuration/settings" | ||
"github.com/qdm12/gluetun/internal/constants/openvpn" | ||
"github.com/qdm12/gluetun/internal/models" | ||
"github.com/qdm12/gluetun/internal/provider/utils" | ||
) | ||
|
||
func (p *Provider) OpenVPNConfig(connection models.Connection, | ||
settings settings.OpenVPN, ipv6Supported bool, | ||
) (lines []string) { | ||
providerSettings := utils.OpenVPNProviderSettings{ | ||
AuthUserPass: true, | ||
Ciphers: []string{ | ||
openvpn.Chacha20Poly1305, | ||
openvpn.AES256gcm, | ||
openvpn.AES256cbc, | ||
openvpn.AES128gcm, | ||
}, | ||
} | ||
return utils.OpenVPNConfig(providerSettings, connection, settings, ipv6Supported) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ovpn | ||
|
||
import ( | ||
"math/rand" | ||
"net/http" | ||
|
||
"github.com/qdm12/gluetun/internal/constants/providers" | ||
"github.com/qdm12/gluetun/internal/provider/common" | ||
"github.com/qdm12/gluetun/internal/provider/ovpn/updater" | ||
) | ||
|
||
type Provider struct { | ||
storage common.Storage | ||
randSource rand.Source | ||
common.Fetcher | ||
} | ||
|
||
func New(storage common.Storage, randSource rand.Source, | ||
client *http.Client, | ||
) *Provider { | ||
return &Provider{ | ||
storage: storage, | ||
randSource: randSource, | ||
Fetcher: updater.New(client), | ||
} | ||
} | ||
|
||
func (p *Provider) Name() string { | ||
return providers.Ovpn | ||
} |
Oops, something went wrong.