2021-08-18 20:18:49 +00:00
|
|
|
package custom
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2022-01-06 06:40:23 -05:00
|
|
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
2021-08-18 20:18:49 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/constants"
|
|
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
2022-01-06 06:40:23 -05:00
|
|
|
func intPtr(n int) *int { return &n }
|
|
|
|
|
func uint16Ptr(n uint16) *uint16 { return &n }
|
|
|
|
|
func stringPtr(s string) *string { return &s }
|
|
|
|
|
|
2021-09-13 11:30:14 -04:00
|
|
|
func Test_modifyConfig(t *testing.T) {
|
2021-08-18 20:18:49 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
testCases := map[string]struct {
|
|
|
|
|
lines []string
|
2022-01-06 06:40:23 -05:00
|
|
|
settings settings.OpenVPN
|
2021-08-19 14:09:41 +00:00
|
|
|
connection models.Connection
|
2021-08-18 20:18:49 +00:00
|
|
|
modified []string
|
|
|
|
|
}{
|
|
|
|
|
"mixed": {
|
|
|
|
|
lines: []string{
|
|
|
|
|
"up bla",
|
|
|
|
|
"proto tcp",
|
|
|
|
|
"remote 5.5.5.5",
|
|
|
|
|
"cipher bla",
|
2021-09-13 11:30:14 -04:00
|
|
|
"",
|
2021-08-18 20:18:49 +00:00
|
|
|
"tun-ipv6",
|
|
|
|
|
"keep me here",
|
|
|
|
|
"auth bla",
|
|
|
|
|
},
|
2022-01-06 06:40:23 -05:00
|
|
|
settings: settings.OpenVPN{
|
2022-01-27 23:34:19 +00:00
|
|
|
User: "user",
|
|
|
|
|
Ciphers: []string{"cipher"},
|
|
|
|
|
Auth: stringPtr("auth"),
|
|
|
|
|
MSSFix: uint16Ptr(1000),
|
|
|
|
|
ProcessUser: "procuser",
|
|
|
|
|
Interface: "tun3",
|
|
|
|
|
Verbosity: intPtr(0),
|
2022-01-06 06:40:23 -05:00
|
|
|
}.WithDefaults(constants.Custom),
|
2021-08-19 14:09:41 +00:00
|
|
|
connection: models.Connection{
|
2021-08-18 20:18:49 +00:00
|
|
|
IP: net.IPv4(1, 2, 3, 4),
|
|
|
|
|
Port: 1194,
|
|
|
|
|
Protocol: constants.UDP,
|
|
|
|
|
},
|
|
|
|
|
modified: []string{
|
2021-09-13 11:30:14 -04:00
|
|
|
"up bla",
|
2021-08-18 20:18:49 +00:00
|
|
|
"keep me here",
|
|
|
|
|
"proto udp",
|
|
|
|
|
"remote 1.2.3.4 1194",
|
2021-08-19 23:22:55 +00:00
|
|
|
"dev tun3",
|
2021-08-18 20:18:49 +00:00
|
|
|
"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",
|
2021-09-14 14:54:59 +00:00
|
|
|
"persist-tun",
|
2021-09-14 14:55:39 +00:00
|
|
|
"persist-key",
|
2021-09-13 11:30:14 -04:00
|
|
|
"",
|
2021-08-18 20:18:49 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for name, testCase := range testCases {
|
|
|
|
|
testCase := testCase
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
2021-09-13 11:30:14 -04:00
|
|
|
modified := modifyConfig(testCase.lines,
|
|
|
|
|
testCase.connection, testCase.settings)
|
2021-08-18 20:18:49 +00:00
|
|
|
|
|
|
|
|
assert.Equal(t, testCase.modified, modified)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|