mirror of
https://github.com/miekg/dns.git
synced 2025-12-17 09:41:20 +01:00
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) {
|
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 := new(Msg)
|
||||||
m.SetQuestion("miek.nl.", TypeSOA)
|
m.SetQuestion("miek.nl.", TypeSOA)
|
||||||
|
|
||||||
c := new(Client)
|
c := new(Client)
|
||||||
c.Do(m, "85.223.71.124:53")
|
c.Do(m, "85.223.71.124:53", nil, func(m, r *Msg, e error, d interface{}) {
|
||||||
|
if r != nil && r.Rcode != RcodeSuccess {
|
||||||
forever:
|
t.Log("Failed to get an valid answer")
|
||||||
for {
|
t.Fail()
|
||||||
select {
|
t.Logf("%v\n", r)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClientEDNS0(t *testing.T) {
|
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.
|
// IsSubDomain checks if child is indeed a child of the parent.
|
||||||
func IsSubDomain(parent, child string) bool {
|
func IsSubDomain(parent, child string) bool {
|
||||||
// Entire child is contained in parent
|
// 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.
|
// IsFqdn checks if a domain name is fully qualified.
|
||||||
|
|||||||
@ -75,6 +75,8 @@ func TestBailiwick(t *testing.T) {
|
|||||||
for parent, child := range yes {
|
for parent, child := range yes {
|
||||||
if !IsSubDomain(parent, child) {
|
if !IsSubDomain(parent, child) {
|
||||||
t.Logf("%s should be child of %s\n", child, parent)
|
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()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,6 +87,8 @@ func TestBailiwick(t *testing.T) {
|
|||||||
for parent, child := range no {
|
for parent, child := range no {
|
||||||
if IsSubDomain(parent, child) {
|
if IsSubDomain(parent, child) {
|
||||||
t.Logf("%s should not be child of %s\n", child, parent)
|
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()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user