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 {
|
func (d *DNS) String() string {
|
||||||
|
return strings.Join(d.lines(), "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DNS) lines() (lines []string) {
|
||||||
if !d.Enabled {
|
if !d.Enabled {
|
||||||
return fmt.Sprintf("DNS over TLS disabled, using plaintext DNS %s", d.PlaintextAddress)
|
return []string{"DNS over TLS disabled, using plaintext DNS " + d.PlaintextAddress.String()}
|
||||||
}
|
}
|
||||||
blockMalicious, blockSurveillance, blockAds := disabled, disabled, disabled
|
|
||||||
|
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 {
|
if d.BlockMalicious {
|
||||||
blockMalicious = enabled
|
blockMalicious = enabled
|
||||||
}
|
}
|
||||||
if d.BlockSurveillance {
|
lines = append(lines, prefix+"Block malicious: "+blockMalicious)
|
||||||
blockSurveillance = enabled
|
|
||||||
}
|
blockAds := disabled
|
||||||
if d.BlockAds {
|
if d.BlockAds {
|
||||||
blockAds = enabled
|
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"
|
update := "deactivated"
|
||||||
if d.UpdatePeriod > 0 {
|
if d.UpdatePeriod > 0 {
|
||||||
update = fmt.Sprintf("every %s", d.UpdatePeriod)
|
update = "every " + d.UpdatePeriod.String()
|
||||||
}
|
}
|
||||||
|
lines = append(lines, prefix+"Update: "+update)
|
||||||
|
|
||||||
keepNameserver := "no"
|
keepNameserver := "no"
|
||||||
if d.KeepNameserver {
|
if d.KeepNameserver {
|
||||||
keepNameserver = "yes"
|
keepNameserver = "yes"
|
||||||
}
|
}
|
||||||
settingsList := []string{
|
lines = append(lines,
|
||||||
"DNS settings:",
|
prefix+"Keep nameserver (disabled blocking): "+keepNameserver)
|
||||||
"Block malicious: " + blockMalicious,
|
|
||||||
"Block surveillance: " + blockSurveillance,
|
return lines
|
||||||
"Block ads: " + blockAds,
|
|
||||||
"Update: " + update,
|
|
||||||
"Keep nameserver (disabled blocking): " + keepNameserver,
|
|
||||||
"Unbound settings: " + "\n |--" + strings.Join(d.Unbound.Lines(), "\n |--"),
|
|
||||||
}
|
|
||||||
return strings.Join(settingsList, "\n |--")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDNSSettings obtains DNS over TLS settings from environment variables using the params package.
|
// 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