Files
gluetun/internal/openvpn/custom/modify_test.go
Quentin McGaw (desktop) bec8ff27ae Feat: OPENVPN_INTERFACE defaulting to tun0
- Fix: custom config with custom network interface name for firewall
- Keep VPN tunnel interface in firewall state
- Vul fix: only allow traffic through vpn interface when needed
- Adapt code to adapt to network interface name
- Remove outdated TUN and TAP constants
2021-08-19 23:22:55 +00:00

81 lines
1.7 KiB
Go

package custom
import (
"net"
"testing"
"github.com/qdm12/gluetun/internal/configuration"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models"
"github.com/stretchr/testify/assert"
)
func Test_modifyCustomConfig(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
lines []string
settings configuration.OpenVPN
connection models.Connection
intf string
modified []string
}{
"mixed": {
lines: []string{
"up bla",
"proto tcp",
"remote 5.5.5.5",
"cipher bla",
"tun-ipv6",
"keep me here",
"auth bla",
},
settings: configuration.OpenVPN{
User: "user",
Cipher: "cipher",
Auth: "auth",
MSSFix: 1000,
ProcUser: "procuser",
},
connection: models.Connection{
IP: net.IPv4(1, 2, 3, 4),
Port: 1194,
Protocol: constants.UDP,
},
intf: "tun3",
modified: []string{
"keep me here",
"proto udp",
"remote 1.2.3.4 1194",
"dev tun3",
"mute-replay-warnings",
"auth-nocache",
"pull-filter ignore \"auth-token\"",
"auth-retry nointeract",
"suppress-timestamps",
"auth-user-pass /etc/openvpn/auth.conf",
"verb 0",
"data-ciphers-fallback cipher",
"data-ciphers cipher",
"auth auth",
"mssfix 1000",
"pull-filter ignore \"route-ipv6\"",
"pull-filter ignore \"ifconfig-ipv6\"",
"user procuser",
},
},
}
for name, testCase := range testCases {
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
modified := modifyCustomConfig(testCase.lines,
testCase.settings, testCase.connection, testCase.intf)
assert.Equal(t, testCase.modified, modified)
})
}
}