2016-09-07 11:10:16 +01:00
|
|
|
package edns
|
2016-04-09 11:13:04 +01:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
|
)
|
|
|
|
|
|
2016-09-07 11:10:16 +01:00
|
|
|
func TestVersion(t *testing.T) {
|
2016-04-09 11:13:04 +01:00
|
|
|
m := ednsMsg()
|
|
|
|
|
m.Extra[0].(*dns.OPT).SetVersion(2)
|
|
|
|
|
|
2022-12-01 16:07:13 +02:00
|
|
|
r, err := Version(m)
|
2016-04-09 11:13:04 +01:00
|
|
|
if err == nil {
|
2018-06-02 19:48:39 +01:00
|
|
|
t.Errorf("Expected wrong version, but got OK")
|
2016-04-09 11:13:04 +01:00
|
|
|
}
|
2022-12-01 16:07:13 +02:00
|
|
|
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")
|
|
|
|
|
}
|
2016-04-09 11:13:04 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-07 11:10:16 +01:00
|
|
|
func TestVersionNoEdns(t *testing.T) {
|
2016-04-09 11:13:04 +01:00
|
|
|
m := ednsMsg()
|
|
|
|
|
m.Extra = nil
|
|
|
|
|
|
2022-12-01 16:07:13 +02:00
|
|
|
r, err := Version(m)
|
2016-04-09 11:13:04 +01:00
|
|
|
if err != nil {
|
2018-06-02 19:48:39 +01:00
|
|
|
t.Errorf("Expected no error, but got one: %s", err)
|
2016-04-09 11:13:04 +01:00
|
|
|
}
|
2022-12-01 16:07:13 +02:00
|
|
|
if r != nil {
|
|
|
|
|
t.Errorf("Expected nil since not an EDNS0 request, but did not got nil")
|
|
|
|
|
}
|
2016-04-09 11:13:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|