diff --git a/internal/configuration/settings/openvpn.go b/internal/configuration/settings/openvpn.go index f940710e..e4b7752a 100644 --- a/internal/configuration/settings/openvpn.go +++ b/internal/configuration/settings/openvpn.go @@ -2,6 +2,7 @@ package settings import ( "fmt" + "regexp" "strings" "github.com/qdm12/gluetun/internal/configuration/settings/helpers" @@ -73,6 +74,8 @@ type OpenVPN struct { Flags []string } +var ivpnAccountID = regexp.MustCompile(`^(i|ivpn)\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{4}$`) + func (o OpenVPN) validate(vpnProvider string) (err error) { // Validate version validVersions := []string{constants.Openvpn24, constants.Openvpn25} @@ -87,7 +90,10 @@ func (o OpenVPN) validate(vpnProvider string) (err error) { return ErrOpenVPNUserIsEmpty } - if !isCustom && o.Password == "" { + passwordRequired := !isCustom && + (vpnProvider != constants.Ivpn || !ivpnAccountID.MatchString(o.User)) + + if passwordRequired && o.Password == "" { return ErrOpenVPNPasswordIsEmpty } diff --git a/internal/configuration/settings/openvpn_test.go b/internal/configuration/settings/openvpn_test.go new file mode 100644 index 00000000..09610f19 --- /dev/null +++ b/internal/configuration/settings/openvpn_test.go @@ -0,0 +1,44 @@ +package settings + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_ivpnAccountID(t *testing.T) { + t.Parallel() + + testCases := []struct { + s string + match bool + }{ + {}, + {s: "abc"}, + {s: "i"}, + {s: "ivpn"}, + {s: "ivpn-aaaa"}, + {s: "ivpn-aaaa-aaaa"}, + {s: "ivpn-aaaa-aaaa-aaa"}, + {s: "ivpn-aaaa-aaaa-aaaa", match: true}, + {s: "ivpn-aaaa-aaaa-aaaaa"}, + {s: "ivpn-a6B7-fP91-Zh6Y", match: true}, + {s: "i-aaaa"}, + {s: "i-aaaa-aaaa"}, + {s: "i-aaaa-aaaa-aaa"}, + {s: "i-aaaa-aaaa-aaaa", match: true}, + {s: "i-aaaa-aaaa-aaaaa"}, + {s: "i-a6B7-fP91-Zh6Y", match: true}, + } + + for _, testCase := range testCases { + testCase := testCase + t.Run(testCase.s, func(t *testing.T) { + t.Parallel() + + match := ivpnAccountID.MatchString(testCase.s) + + assert.Equal(t, testCase.match, match) + }) + } +}