Fix IsSubDomain
This commit is contained in:
parent
6aee81ad74
commit
1dffbeeee1
|
@ -19,34 +19,18 @@ func TestClientSync(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func helloMiek(w RequestWriter, r *Msg) {
|
||||
w.Send(r)
|
||||
reply, _ := w.Receive()
|
||||
w.Write(reply)
|
||||
}
|
||||
|
||||
func TestClientASync(t *testing.T) {
|
||||
HandleQueryFunc("miek.nl.", helloMiek) // All queries for miek.nl will be handled by HelloMiek
|
||||
ListenAndQuery(nil) // Detect if this isn't running
|
||||
|
||||
m := new(Msg)
|
||||
m.SetQuestion("miek.nl.", TypeSOA)
|
||||
|
||||
c := new(Client)
|
||||
c.Do(m, "85.223.71.124:53")
|
||||
|
||||
forever:
|
||||
for {
|
||||
select {
|
||||
case n := <-c.Reply:
|
||||
if n.Reply != nil && n.Reply.Rcode != RcodeSuccess {
|
||||
t.Log("Failed to get an valid answer")
|
||||
t.Fail()
|
||||
t.Logf("%v\n", n.Reply)
|
||||
}
|
||||
break forever
|
||||
c.Do(m, "85.223.71.124:53", nil, func(m, r *Msg, e error, d interface{}) {
|
||||
if r != nil && r.Rcode != RcodeSuccess {
|
||||
t.Log("Failed to get an valid answer")
|
||||
t.Fail()
|
||||
t.Logf("%v\n", r)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestClientEDNS0(t *testing.T) {
|
||||
|
|
|
@ -284,7 +284,7 @@ func IsDomainName(s string) (uint8, uint8, bool) { // copied from net package.
|
|||
// IsSubDomain checks if child is indeed a child of the parent.
|
||||
func IsSubDomain(parent, child string) bool {
|
||||
// Entire child is contained in parent
|
||||
return CompareLabels(child, parent) == LenLabels(child)
|
||||
return CompareLabels(parent, child) == LenLabels(parent)
|
||||
}
|
||||
|
||||
// IsFqdn checks if a domain name is fully qualified.
|
||||
|
|
|
@ -75,6 +75,8 @@ func TestBailiwick(t *testing.T) {
|
|||
for parent, child := range yes {
|
||||
if !IsSubDomain(parent, child) {
|
||||
t.Logf("%s should be child of %s\n", child, parent)
|
||||
t.Logf("comparelabels %d", CompareLabels(parent, child))
|
||||
t.Logf("lenlabels %d %d", LenLabels(parent), LenLabels(child))
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +87,8 @@ func TestBailiwick(t *testing.T) {
|
|||
for parent, child := range no {
|
||||
if IsSubDomain(parent, child) {
|
||||
t.Logf("%s should not be child of %s\n", child, parent)
|
||||
t.Logf("comparelabels %d", CompareLabels(parent, child))
|
||||
t.Logf("lenlabels %d %d", LenLabels(parent), LenLabels(child))
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue