Feature: Improve DNS settings start log
This commit is contained in:
@@ -24,37 +24,59 @@ type DNS struct { //nolint:maligned
|
||||
}
|
||||
|
||||
func (d *DNS) String() string {
|
||||
if !d.Enabled {
|
||||
return fmt.Sprintf("DNS over TLS disabled, using plaintext DNS %s", d.PlaintextAddress)
|
||||
return strings.Join(d.lines(), "\n")
|
||||
}
|
||||
blockMalicious, blockSurveillance, blockAds := disabled, disabled, disabled
|
||||
|
||||
func (d *DNS) lines() (lines []string) {
|
||||
if !d.Enabled {
|
||||
return []string{"DNS over TLS disabled, using plaintext DNS " + d.PlaintextAddress.String()}
|
||||
}
|
||||
|
||||
const prefix = " |--"
|
||||
|
||||
lines = append(lines, "DNS settings:")
|
||||
|
||||
lines = append(lines, prefix+"Unbound:")
|
||||
for _, line := range d.Unbound.Lines() {
|
||||
indent := " " + prefix
|
||||
if strings.HasPrefix(line, prefix) {
|
||||
indent = " "
|
||||
}
|
||||
lines = append(lines, indent+line)
|
||||
}
|
||||
|
||||
blockMalicious := disabled
|
||||
if d.BlockMalicious {
|
||||
blockMalicious = enabled
|
||||
}
|
||||
if d.BlockSurveillance {
|
||||
blockSurveillance = enabled
|
||||
}
|
||||
lines = append(lines, prefix+"Block malicious: "+blockMalicious)
|
||||
|
||||
blockAds := disabled
|
||||
if d.BlockAds {
|
||||
blockAds = enabled
|
||||
}
|
||||
lines = append(lines, prefix+"Block ads: "+blockAds)
|
||||
|
||||
blockSurveillance := disabled
|
||||
if d.BlockSurveillance {
|
||||
blockSurveillance = enabled
|
||||
}
|
||||
lines = append(lines, prefix+"Block surveillance: "+blockSurveillance)
|
||||
|
||||
update := "deactivated"
|
||||
if d.UpdatePeriod > 0 {
|
||||
update = fmt.Sprintf("every %s", d.UpdatePeriod)
|
||||
update = "every " + d.UpdatePeriod.String()
|
||||
}
|
||||
lines = append(lines, prefix+"Update: "+update)
|
||||
|
||||
keepNameserver := "no"
|
||||
if d.KeepNameserver {
|
||||
keepNameserver = "yes"
|
||||
}
|
||||
settingsList := []string{
|
||||
"DNS settings:",
|
||||
"Block malicious: " + blockMalicious,
|
||||
"Block surveillance: " + blockSurveillance,
|
||||
"Block ads: " + blockAds,
|
||||
"Update: " + update,
|
||||
"Keep nameserver (disabled blocking): " + keepNameserver,
|
||||
"Unbound settings: " + "\n |--" + strings.Join(d.Unbound.Lines(), "\n |--"),
|
||||
}
|
||||
return strings.Join(settingsList, "\n |--")
|
||||
lines = append(lines,
|
||||
prefix+"Keep nameserver (disabled blocking): "+keepNameserver)
|
||||
|
||||
return lines
|
||||
}
|
||||
|
||||
// GetDNSSettings obtains DNS over TLS settings from environment variables using the params package.
|
||||
|
||||
60
internal/settings/dns_test.go
Normal file
60
internal/settings/dns_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_DNS_Lines(t *testing.T) {
|
||||
t.Parallel()
|
||||
testCases := map[string]struct {
|
||||
settings DNS
|
||||
lines []string
|
||||
}{
|
||||
"disabled DOT": {
|
||||
settings: DNS{
|
||||
PlaintextAddress: net.IP{1, 1, 1, 1},
|
||||
},
|
||||
lines: []string{
|
||||
"DNS over TLS disabled, using plaintext DNS 1.1.1.1",
|
||||
},
|
||||
},
|
||||
"enabled DOT": {
|
||||
settings: DNS{
|
||||
Enabled: true,
|
||||
},
|
||||
lines: []string{
|
||||
"DNS settings:",
|
||||
" |--Unbound:",
|
||||
" |--DNS over TLS provider:",
|
||||
" |--Listening port: 0",
|
||||
" |--Access control:",
|
||||
" |--Allowed:",
|
||||
" |--Caching: disabled",
|
||||
" |--IPv4 resolution: disabled",
|
||||
" |--IPv6 resolution: disabled",
|
||||
" |--Verbosity level: 0/5",
|
||||
" |--Verbosity details level: 0/4",
|
||||
" |--Validation log level: 0/2",
|
||||
" |--Blocked hostnames:",
|
||||
" |--Blocked IP addresses:",
|
||||
" |--Allowed hostnames:",
|
||||
" |--Block malicious: disabled",
|
||||
" |--Block ads: disabled",
|
||||
" |--Block surveillance: disabled",
|
||||
" |--Update: deactivated",
|
||||
" |--Keep nameserver (disabled blocking): no",
|
||||
},
|
||||
},
|
||||
}
|
||||
for name, testCase := range testCases {
|
||||
testCase := testCase
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
lines := testCase.settings.lines()
|
||||
assert.Equal(t, testCase.lines, lines)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user