blob: 1976779bda2609781bbea6250105e7d843b69b4a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package edns
import (
"testing"
"github.com/miekg/dns"
)
func TestVersion(t *testing.T) {
m := ednsMsg()
m.Extra[0].(*dns.OPT).SetVersion(2)
r, err := Version(m)
if err == nil {
t.Errorf("Expected wrong version, but got OK")
}
if r.Question == nil {
t.Errorf("Expected question section, but got nil")
}
if r.Rcode != dns.RcodeBadVers {
t.Errorf("Expected Rcode to be of BADVER (16), but got %d", r.Rcode)
}
if r.Extra == nil {
t.Errorf("Expected OPT section, but got nil")
}
}
func TestVersionNoEdns(t *testing.T) {
m := ednsMsg()
m.Extra = nil
r, err := Version(m)
if err != nil {
t.Errorf("Expected no error, but got one: %s", err)
}
if r != nil {
t.Errorf("Expected nil since not an EDNS0 request, but did not got nil")
}
}
func ednsMsg() *dns.Msg {
m := new(dns.Msg)
m.SetQuestion("example.com.", dns.TypeA)
o := new(dns.OPT)
o.Hdr.Name = "."
o.Hdr.Rrtype = dns.TypeOPT
m.Extra = append(m.Extra, o)
return m
}
|