Maint: upgrade qdm12 dependencies
- Upgrade qdm12/golibs - Upgrade qdm12/dns to v1.11.0
This commit is contained in:
@@ -28,9 +28,8 @@ func newReader(env params.Env, logger logging.Logger) reader {
|
||||
|
||||
func (r *reader) onRetroActive(oldKey, newKey string) {
|
||||
r.logger.Warn(
|
||||
"You are using the old environment variable %s, please consider changing it to %s",
|
||||
oldKey, newKey,
|
||||
)
|
||||
"You are using the old environment variable " + oldKey +
|
||||
", please consider changing it to " + newKey)
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
80
internal/configuration/unbound_test.go
Normal file
80
internal/configuration/unbound_test.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package configuration
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/qdm12/dns/pkg/provider"
|
||||
"github.com/qdm12/dns/pkg/unbound"
|
||||
"github.com/qdm12/golibs/params/mock_params"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_DNS_readUnboundProviders(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := map[string]struct {
|
||||
envValue string
|
||||
envErr error
|
||||
expected DNS
|
||||
err error
|
||||
}{
|
||||
"bad value": {
|
||||
envValue: "invalid",
|
||||
err: errors.New(`invalid DNS over TLS provider: cannot parse provider: "invalid"`),
|
||||
},
|
||||
"env error": {
|
||||
envErr: errors.New("env error"),
|
||||
err: errors.New("environment variable DOT_PROVIDERS: env error"),
|
||||
},
|
||||
"multiple valid values": {
|
||||
envValue: "cloudflare,google",
|
||||
expected: DNS{
|
||||
Unbound: unbound.Settings{
|
||||
Providers: []provider.Provider{
|
||||
provider.Cloudflare(),
|
||||
provider.Google(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"one invalid value in two": {
|
||||
envValue: "cloudflare,invalid",
|
||||
expected: DNS{
|
||||
Unbound: unbound.Settings{
|
||||
Providers: []provider.Provider{
|
||||
provider.Cloudflare(),
|
||||
},
|
||||
},
|
||||
},
|
||||
err: errors.New(`invalid DNS over TLS provider: cannot parse provider: "invalid"`),
|
||||
},
|
||||
}
|
||||
|
||||
for name, testCase := range testCases {
|
||||
testCase := testCase
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctrl := gomock.NewController(t)
|
||||
|
||||
env := mock_params.NewMockEnv(ctrl)
|
||||
env.EXPECT().Get("DOT_PROVIDERS", gomock.Any()).
|
||||
Return(testCase.envValue, testCase.envErr)
|
||||
|
||||
var settings DNS
|
||||
err := settings.readUnboundProviders(env)
|
||||
|
||||
if testCase.err != nil {
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, testCase.err.Error(), err.Error())
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
assert.Equal(t, testCase.expected, settings)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ type Configurator interface {
|
||||
}
|
||||
|
||||
type Config struct { //nolint:maligned
|
||||
commander command.Commander
|
||||
runner command.Runner
|
||||
logger logging.Logger
|
||||
routing routing.Routing
|
||||
iptablesMutex sync.Mutex
|
||||
@@ -47,15 +47,15 @@ type Config struct { //nolint:maligned
|
||||
}
|
||||
|
||||
// NewConfig creates a new Config instance.
|
||||
func NewConfig(logger logging.Logger, cmder command.Commander,
|
||||
func NewConfig(logger logging.Logger, runner command.Runner,
|
||||
routing routing.Routing, defaultInterface string, defaultGateway net.IP,
|
||||
localNetworks []routing.LocalNetwork, localIP net.IP) *Config {
|
||||
return &Config{
|
||||
commander: cmder,
|
||||
runner: runner,
|
||||
logger: logger,
|
||||
routing: routing,
|
||||
allowedInputPorts: make(map[uint16]string),
|
||||
ip6Tables: ip6tablesSupported(context.Background(), cmder),
|
||||
ip6Tables: ip6tablesSupported(context.Background(), runner),
|
||||
customRulesPath: "/iptables/post-rules.txt",
|
||||
// Obtained from routing
|
||||
defaultInterface: defaultInterface,
|
||||
|
||||
@@ -15,9 +15,9 @@ var (
|
||||
ErrIP6NotSupported = errors.New("ip6tables not supported")
|
||||
)
|
||||
|
||||
func ip6tablesSupported(ctx context.Context, commander command.Commander) (supported bool) {
|
||||
func ip6tablesSupported(ctx context.Context, runner command.Runner) (supported bool) {
|
||||
cmd := exec.CommandContext(ctx, "ip6tables", "-L")
|
||||
if _, err := commander.Run(cmd); err != nil {
|
||||
if _, err := runner.Run(cmd); err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -43,7 +43,7 @@ func (c *Config) runIP6tablesInstruction(ctx context.Context, instruction string
|
||||
|
||||
flags := strings.Fields(instruction)
|
||||
cmd := exec.CommandContext(ctx, "ip6tables", flags...)
|
||||
if output, err := c.commander.Run(cmd); err != nil {
|
||||
if output, err := c.runner.Run(cmd); err != nil {
|
||||
return fmt.Errorf("%w: \"ip6tables %s\": %s: %s", ErrIP6Tables, instruction, output, err)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -47,9 +47,9 @@ func flipRule(rule string) string {
|
||||
}
|
||||
|
||||
// Version obtains the version of the installed iptables.
|
||||
func Version(ctx context.Context, commander command.Commander) (string, error) {
|
||||
func Version(ctx context.Context, runner command.Runner) (string, error) {
|
||||
cmd := exec.CommandContext(ctx, "iptables", "--version")
|
||||
output, err := commander.Run(cmd)
|
||||
output, err := runner.Run(cmd)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func (c *Config) runIptablesInstruction(ctx context.Context, instruction string)
|
||||
|
||||
flags := strings.Fields(instruction)
|
||||
cmd := exec.CommandContext(ctx, "iptables", flags...)
|
||||
if output, err := c.commander.Run(cmd); err != nil {
|
||||
if output, err := c.runner.Run(cmd); err != nil {
|
||||
return fmt.Errorf("%w \"iptables %s\": %s: %s", ErrIPTables, instruction, output, err)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -60,7 +60,7 @@ func (c *Config) RemoveAllowedPort(ctx context.Context, port uint16) (err error)
|
||||
return nil
|
||||
}
|
||||
|
||||
c.logger.Info("removing allowed port "+strconv.Itoa(int(port))+" through firewall...", port)
|
||||
c.logger.Info("removing allowed port " + strconv.Itoa(int(port)) + " through firewall...")
|
||||
|
||||
intf, ok := c.allowedInputPorts[port]
|
||||
if !ok {
|
||||
|
||||
@@ -37,7 +37,7 @@ func (c *configurator) Start(ctx context.Context, version string, flags []string
|
||||
cmd := exec.CommandContext(ctx, bin, args...)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
|
||||
return c.commander.Start(cmd)
|
||||
return c.cmder.Start(cmd)
|
||||
}
|
||||
|
||||
func (c *configurator) Version24(ctx context.Context) (version string, err error) {
|
||||
@@ -52,7 +52,7 @@ var ErrVersionTooShort = errors.New("version output is too short")
|
||||
|
||||
func (c *configurator) version(ctx context.Context, binName string) (version string, err error) {
|
||||
cmd := exec.CommandContext(ctx, binName, "--version")
|
||||
output, err := c.commander.Run(cmd)
|
||||
output, err := c.cmder.Run(cmd)
|
||||
if err != nil && err.Error() != "exit status 1" {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -23,17 +23,17 @@ type Configurator interface {
|
||||
|
||||
type configurator struct {
|
||||
logger logging.Logger
|
||||
commander command.Commander
|
||||
cmder command.RunStarter
|
||||
unix unix.Unix
|
||||
authFilePath string
|
||||
tunDevPath string
|
||||
}
|
||||
|
||||
func NewConfigurator(logger logging.Logger, unix unix.Unix,
|
||||
cmder command.Commander) Configurator {
|
||||
cmder command.RunStarter) Configurator {
|
||||
return &configurator{
|
||||
logger: logger,
|
||||
commander: cmder,
|
||||
cmder: cmder,
|
||||
unix: unix,
|
||||
authFilePath: constants.OpenVPNAuthConf,
|
||||
tunDevPath: constants.TunnelDevice,
|
||||
|
||||
Reference in New Issue
Block a user