feat(config): allow invalid server filters (#2419)

- Disallow setting a server filter when there is no choice available
- Allow setting an invalid server filter when there is at least one choice available
- Log at warn level when an invalid server filter is set
- Fix #2337
This commit is contained in:
Quentin McGaw
2024-08-17 12:01:26 +02:00
committed by GitHub
parent 4a128677dd
commit 897a9d7f57
8 changed files with 68 additions and 26 deletions

View File

@@ -36,7 +36,8 @@ type Storage interface {
// Validate validates all the settings and returns an error
// if one of them is not valid.
// TODO v4 remove pointer for receiver (because of Surfshark).
func (s *Settings) Validate(storage Storage, ipv6Supported bool) (err error) {
func (s *Settings) Validate(storage Storage, ipv6Supported bool,
warner Warner) (err error) {
nameToValidation := map[string]func() error{
"control server": s.ControlServer.validate,
"dns": s.DNS.validate,
@@ -51,7 +52,7 @@ func (s *Settings) Validate(storage Storage, ipv6Supported bool) (err error) {
"version": s.Version.validate,
// Pprof validation done in pprof constructor
"VPN": func() error {
return s.VPN.Validate(storage, ipv6Supported)
return s.VPN.Validate(storage, ipv6Supported, warner)
},
}
@@ -84,7 +85,7 @@ func (s *Settings) copy() (copied Settings) {
}
func (s *Settings) OverrideWith(other Settings,
storage Storage, ipv6Supported bool) (err error) {
storage Storage, ipv6Supported bool, warner Warner) (err error) {
patchedSettings := s.copy()
patchedSettings.ControlServer.overrideWith(other.ControlServer)
patchedSettings.DNS.overrideWith(other.DNS)
@@ -99,7 +100,7 @@ func (s *Settings) OverrideWith(other Settings,
patchedSettings.Version.overrideWith(other.Version)
patchedSettings.VPN.OverrideWith(other.VPN)
patchedSettings.Pprof.OverrideWith(other.Pprof)
err = patchedSettings.Validate(storage, ipv6Supported)
err = patchedSettings.Validate(storage, ipv6Supported, warner)
if err != nil {
return err
}