- fix tests and linter issues
This commit is contained in:
parent
147344afa3
commit
3baa6919dc
|
@ -34,7 +34,7 @@ func TestClients(t *testing.T) {
|
||||||
IP: "1.2.3.5",
|
IP: "1.2.3.5",
|
||||||
Name: "client1",
|
Name: "client1",
|
||||||
}
|
}
|
||||||
b, e = clientAdd(c)
|
b, _ = clientAdd(c)
|
||||||
if b {
|
if b {
|
||||||
t.Fatalf("clientAdd - name in use")
|
t.Fatalf("clientAdd - name in use")
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ func TestClients(t *testing.T) {
|
||||||
|
|
||||||
// failed add - ip exists
|
// failed add - ip exists
|
||||||
b, e = clientAddHost("1.1.1.1", "host", ClientSourceHostsFile)
|
b, e = clientAddHost("1.1.1.1", "host", ClientSourceHostsFile)
|
||||||
if b {
|
if b || e != nil {
|
||||||
t.Fatalf("clientAddHost - ip exists")
|
t.Fatalf("clientAddHost - ip exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ func TestDHCP(t *testing.T) {
|
||||||
var lease *Lease
|
var lease *Lease
|
||||||
var opt dhcp4.Options
|
var opt dhcp4.Options
|
||||||
|
|
||||||
|
s.reset()
|
||||||
s.leaseStart = []byte{1, 1, 1, 1}
|
s.leaseStart = []byte{1, 1, 1, 1}
|
||||||
s.leaseStop = []byte{1, 1, 1, 2}
|
s.leaseStop = []byte{1, 1, 1, 2}
|
||||||
s.leaseTime = 5 * time.Second
|
s.leaseTime = 5 * time.Second
|
||||||
|
@ -132,6 +133,7 @@ func TestDB(t *testing.T) {
|
||||||
var hw1, hw2 net.HardwareAddr
|
var hw1, hw2 net.HardwareAddr
|
||||||
var lease *Lease
|
var lease *Lease
|
||||||
|
|
||||||
|
s.reset()
|
||||||
s.leaseStart = []byte{1, 1, 1, 1}
|
s.leaseStart = []byte{1, 1, 1, 1}
|
||||||
s.leaseStop = []byte{1, 1, 1, 2}
|
s.leaseStop = []byte{1, 1, 1, 2}
|
||||||
s.leaseTime = 5 * time.Second
|
s.leaseTime = 5 * time.Second
|
||||||
|
|
|
@ -54,7 +54,11 @@ func main() {
|
||||||
GatewayIP: "192.168.7.1",
|
GatewayIP: "192.168.7.1",
|
||||||
}
|
}
|
||||||
log.Printf("Starting DHCP server")
|
log.Printf("Starting DHCP server")
|
||||||
err = server.Start(&config)
|
err = server.Init(config)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
err = server.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -66,12 +70,12 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
log.Printf("Starting DHCP server")
|
log.Printf("Starting DHCP server")
|
||||||
err = server.Start(&config)
|
err = server.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
log.Printf("Starting DHCP server while it's already running")
|
log.Printf("Starting DHCP server while it's already running")
|
||||||
err = server.Start(&config)
|
err = server.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
2
dns.go
2
dns.go
|
@ -136,7 +136,7 @@ func asyncRDNSLoop() {
|
||||||
delete(dnsctx.rdnsIP, ip)
|
delete(dnsctx.rdnsIP, ip)
|
||||||
dnsctx.rdnsLock.Unlock()
|
dnsctx.rdnsLock.Unlock()
|
||||||
|
|
||||||
clientAddHost(ip, host, ClientSourceRDNS)
|
_, _ = clientAddHost(ip, host, ClientSourceRDNS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,9 @@ package main
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestResolveRDNS(t *testing.T) {
|
func TestResolveRDNS(t *testing.T) {
|
||||||
if r := resolveRDNS("1.1.1.1", "1.1.1.1"); r != "one.one.one.one" {
|
config.DNS.BindHost = "1.1.1.1"
|
||||||
|
initDNSServer(".")
|
||||||
|
if r := resolveRDNS("1.1.1.1"); r != "one.one.one.one" {
|
||||||
t.Errorf("resolveRDNS(): %s", r)
|
t.Errorf("resolveRDNS(): %s", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,17 +35,6 @@ const defaultParentalServer = "pctrl.adguard.com"
|
||||||
const defaultParentalURL = "%s://%s/check-parental-control-hash?prefixes=%s&sensitivity=%d"
|
const defaultParentalURL = "%s://%s/check-parental-control-hash?prefixes=%s&sensitivity=%d"
|
||||||
const maxDialCacheSize = 2 // the number of host names for safebrowsing and parental control
|
const maxDialCacheSize = 2 // the number of host names for safebrowsing and parental control
|
||||||
|
|
||||||
// ErrInvalidSyntax is returned by AddRule when the rule is invalid
|
|
||||||
var ErrInvalidSyntax = errors.New("dnsfilter: invalid rule syntax")
|
|
||||||
|
|
||||||
// ErrAlreadyExists is returned by AddRule when the rule was already added to the filter
|
|
||||||
var ErrAlreadyExists = errors.New("dnsfilter: rule was already added")
|
|
||||||
|
|
||||||
const shortcutLength = 6 // used for rule search optimization, 6 hits the sweet spot
|
|
||||||
|
|
||||||
const enableFastLookup = true // flag for debugging, must be true in production for faster performance
|
|
||||||
const enableDelayedCompilation = true // flag for debugging, must be true in production for faster performance
|
|
||||||
|
|
||||||
// Custom filtering settings
|
// Custom filtering settings
|
||||||
type RequestFilteringSettings struct {
|
type RequestFilteringSettings struct {
|
||||||
FilteringEnabled bool
|
FilteringEnabled bool
|
||||||
|
@ -636,7 +625,10 @@ func searchInDialCache(host string) string {
|
||||||
|
|
||||||
// Add "hostname" -> "IP address" entry to cache
|
// Add "hostname" -> "IP address" entry to cache
|
||||||
func addToDialCache(host, ip string) {
|
func addToDialCache(host, ip string) {
|
||||||
dialCache.Set(host, ip)
|
err := dialCache.Set(host, ip)
|
||||||
|
if err != nil {
|
||||||
|
log.Debug("dialCache.Set: %s", err)
|
||||||
|
}
|
||||||
log.Debug("Added to cache: %s -> %s", host, ip)
|
log.Debug("Added to cache: %s -> %s", host, ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -318,10 +318,12 @@ func TestSafeSearchCacheGoogle(t *testing.T) {
|
||||||
t.Fatalf("Failed to lookup for %s", safeDomain)
|
t.Fatalf("Failed to lookup for %s", safeDomain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Logf("IP addresses: %v", ips)
|
||||||
ip := ips[0]
|
ip := ips[0]
|
||||||
for _, i := range ips {
|
for _, i := range ips {
|
||||||
if len(i) == net.IPv6len && i.To4() != nil {
|
if i.To4() != nil {
|
||||||
ip = i
|
ip = i
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,7 +333,8 @@ func TestSafeSearchCacheGoogle(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.IP.String() != ip.String() {
|
if result.IP.String() != ip.String() {
|
||||||
t.Fatalf("Wrong IP for %s safesearch: %s", domain, result.IP.String())
|
t.Fatalf("Wrong IP for %s safesearch: %s. Should be: %s",
|
||||||
|
domain, result.IP.String(), ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check cache
|
// Check cache
|
||||||
|
|
|
@ -15,12 +15,10 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
||||||
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -177,7 +175,7 @@ func TestSafeSearch(t *testing.T) {
|
||||||
|
|
||||||
ip := ips[0]
|
ip := ips[0]
|
||||||
for _, i := range ips {
|
for _, i := range ips {
|
||||||
if len(i) == net.IPv6len && i.To4() != nil {
|
if i.To4() != nil {
|
||||||
ip = i
|
ip = i
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -460,12 +458,8 @@ func createTestServer(t *testing.T) *Server {
|
||||||
s.conf.FilteringConfig.SafeBrowsingEnabled = true
|
s.conf.FilteringConfig.SafeBrowsingEnabled = true
|
||||||
s.conf.Filters = make([]dnsfilter.Filter, 0)
|
s.conf.Filters = make([]dnsfilter.Filter, 0)
|
||||||
|
|
||||||
rules := []string{
|
rules := "||nxdomain.example.org^\n||null.example.org^\n127.0.0.1 host.example.org\n"
|
||||||
"||nxdomain.example.org^",
|
filter := dnsfilter.Filter{ID: 1, Data: []byte(rules)}
|
||||||
"||null.example.org^",
|
|
||||||
"127.0.0.1 host.example.org",
|
|
||||||
}
|
|
||||||
filter := dnsfilter.Filter{ID: 1, Rules: rules}
|
|
||||||
s.conf.Filters = append(s.conf.Filters, filter)
|
s.conf.Filters = append(s.conf.Filters, filter)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue