2019-08-26 11:54:38 +03:00
|
|
|
package querylog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"testing"
|
2019-09-16 17:07:18 +03:00
|
|
|
"time"
|
2019-08-26 11:54:38 +03:00
|
|
|
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestQueryLog(t *testing.T) {
|
|
|
|
conf := Config{
|
|
|
|
Interval: 1,
|
|
|
|
}
|
|
|
|
l := New(conf)
|
|
|
|
|
|
|
|
q := dns.Msg{}
|
|
|
|
q.Question = append(q.Question, dns.Question{
|
|
|
|
Name: "example.org.",
|
|
|
|
Qtype: dns.TypeA,
|
|
|
|
Qclass: dns.ClassINET,
|
|
|
|
})
|
|
|
|
|
|
|
|
a := dns.Msg{}
|
|
|
|
a.Question = append(a.Question, q.Question[0])
|
|
|
|
answer := new(dns.A)
|
|
|
|
answer.Hdr = dns.RR_Header{
|
|
|
|
Name: q.Question[0].Name,
|
|
|
|
Rrtype: dns.TypeA,
|
|
|
|
Class: dns.ClassINET,
|
|
|
|
}
|
|
|
|
answer.A = net.IP{1, 2, 3, 4}
|
|
|
|
a.Answer = append(a.Answer, answer)
|
|
|
|
|
|
|
|
res := dnsfilter.Result{}
|
|
|
|
l.Add(&q, &a, &res, 0, nil, "upstream")
|
|
|
|
|
2019-09-16 17:07:18 +03:00
|
|
|
params := GetDataParams{
|
|
|
|
OlderThan: time.Now(),
|
|
|
|
}
|
|
|
|
d := l.GetData(params)
|
2019-08-26 11:54:38 +03:00
|
|
|
m := d[0]
|
|
|
|
mq := m["question"].(map[string]interface{})
|
|
|
|
assert.True(t, mq["host"].(string) == "example.org")
|
|
|
|
}
|