Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
c1d5b5d0
Commit
c1d5b5d0
authored
Mar 23, 2016
by
Miek Gieben
Browse files
Options
Browse Files
Download
Plain Diff
yes
parents
892c15d0
bae1fb7a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
42 deletions
+75
-42
middleware/etcd/lookup_test.go
middleware/etcd/lookup_test.go
+75
-42
No files found.
middleware/etcd/lookup_test.go
View file @
c1d5b5d0
// +build net
package
etcd
package
etcd
// etcd needs to be running on http://127.0.0.1:2379
// etcd needs to be running on http://127.0.0.1:2379
// *and* needs connectivity to the internet for remotely resolving
// names.
import
(
import
(
"encoding/json"
"encoding/json"
...
@@ -24,6 +28,14 @@ var (
...
@@ -24,6 +28,14 @@ var (
ctx
context
.
Context
ctx
context
.
Context
)
)
type
Section
int
const
(
Answer
Section
=
iota
Ns
Extra
)
func
init
()
{
func
init
()
{
ctx
=
context
.
TODO
()
ctx
=
context
.
TODO
()
...
@@ -74,6 +86,7 @@ func TestLookup(t *testing.T) {
...
@@ -74,6 +86,7 @@ func TestLookup(t *testing.T) {
code
,
err
:=
etc
.
ServeDNS
(
ctx
,
rec
,
m
)
code
,
err
:=
etc
.
ServeDNS
(
ctx
,
rec
,
m
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"expected no error, got %v
\n
"
,
err
)
t
.
Errorf
(
"expected no error, got %v
\n
"
,
err
)
return
}
}
resp
:=
rec
.
Reply
()
resp
:=
rec
.
Reply
()
code
=
code
// TODO(miek): test
code
=
code
// TODO(miek): test
...
@@ -85,21 +98,25 @@ func TestLookup(t *testing.T) {
...
@@ -85,21 +98,25 @@ func TestLookup(t *testing.T) {
if
resp
.
Rcode
!=
tc
.
Rcode
{
if
resp
.
Rcode
!=
tc
.
Rcode
{
t
.
Errorf
(
"rcode is %q, expected %q"
,
dns
.
RcodeToString
[
resp
.
Rcode
],
dns
.
RcodeToString
[
tc
.
Rcode
])
t
.
Errorf
(
"rcode is %q, expected %q"
,
dns
.
RcodeToString
[
resp
.
Rcode
],
dns
.
RcodeToString
[
tc
.
Rcode
])
continue
}
}
if
len
(
resp
.
Answer
)
!=
len
(
tc
.
Answer
)
{
if
len
(
resp
.
Answer
)
!=
len
(
tc
.
Answer
)
{
t
.
Errorf
(
"answer for %q contained %d results, %d expected"
,
tc
.
Qname
,
len
(
resp
.
Answer
),
len
(
tc
.
Answer
))
t
.
Errorf
(
"answer for %q contained %d results, %d expected"
,
tc
.
Qname
,
len
(
resp
.
Answer
),
len
(
tc
.
Answer
))
continue
}
}
if
len
(
resp
.
Ns
)
!=
len
(
tc
.
Ns
)
{
if
len
(
resp
.
Ns
)
!=
len
(
tc
.
Ns
)
{
t
.
Errorf
(
"authority for %q contained %d results, %d expected"
,
tc
.
Qname
,
len
(
resp
.
Ns
),
len
(
tc
.
Ns
))
t
.
Errorf
(
"authority for %q contained %d results, %d expected"
,
tc
.
Qname
,
len
(
resp
.
Ns
),
len
(
tc
.
Ns
))
continue
}
}
if
len
(
resp
.
Extra
)
!=
len
(
tc
.
Extra
)
{
if
len
(
resp
.
Extra
)
!=
len
(
tc
.
Extra
)
{
t
.
Errorf
(
"additional for %q contained %d results, %d expected"
,
tc
.
Qname
,
len
(
resp
.
Extra
),
len
(
tc
.
Extra
))
t
.
Errorf
(
"additional for %q contained %d results, %d expected"
,
tc
.
Qname
,
len
(
resp
.
Extra
),
len
(
tc
.
Extra
))
continue
}
}
checkSection
(
t
,
tc
,
resp
.
Answer
)
checkSection
(
t
,
tc
,
Answer
,
resp
.
Answer
)
checkSection
(
t
,
tc
,
resp
.
Ns
)
checkSection
(
t
,
tc
,
Ns
,
resp
.
Ns
)
checkSection
(
t
,
tc
,
resp
.
Extra
)
checkSection
(
t
,
tc
,
Extra
,
resp
.
Extra
)
}
}
}
}
...
@@ -118,7 +135,10 @@ var services = []*msg.Service{
...
@@ -118,7 +135,10 @@ var services = []*msg.Service{
{
Host
:
"10.0.0.1"
,
Port
:
8080
,
Key
:
"a.server1.prod.region1.skydns.test."
},
{
Host
:
"10.0.0.1"
,
Port
:
8080
,
Key
:
"a.server1.prod.region1.skydns.test."
},
{
Host
:
"10.0.0.2"
,
Port
:
8080
,
Key
:
"b.server1.prod.region1.skydns.test."
},
{
Host
:
"10.0.0.2"
,
Port
:
8080
,
Key
:
"b.server1.prod.region1.skydns.test."
},
{
Host
:
"::1"
,
Port
:
8080
,
Key
:
"b.server6.prod.region1.skydns.test."
},
{
Host
:
"::1"
,
Port
:
8080
,
Key
:
"b.server6.prod.region1.skydns.test."
},
{
Host
:
"server1"
,
Port
:
80
,
Priority
:
333
,
Key
:
"102.server4.dev.region6.skydns.test."
},
// CNAME dedup Test
{
Host
:
"www.miek.nl"
,
Key
:
"a.miek.nl.skydns.test."
},
{
Host
:
"www.miek.nl"
,
Key
:
"b.miek.nl.skydns.test."
},
}
}
var
dnsTestCases
=
[]
dnsTestCase
{
var
dnsTestCases
=
[]
dnsTestCase
{
...
@@ -151,19 +171,21 @@ var dnsTestCases = []dnsTestCase{
...
@@ -151,19 +171,21 @@ var dnsTestCases = []dnsTestCase{
newA
(
"server1.prod.region1.skydns.test. 300 A 10.0.0.2"
),
newA
(
"server1.prod.region1.skydns.test. 300 A 10.0.0.2"
),
},
},
},
},
/*
// Multi SRV with the same target, should be dedupped.
// Multi SRV with the same target, should be dedupped.
{
{
Qname: "*.cname2
.skydns.test.", Qtype: dns.TypeSRV,
Qname
:
"*.miek.nl
.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
newSRV("*.cname2
.skydns.test. 300 IN SRV 10 100 0 www.miek.nl."),
newSRV
(
"*.miek.nl
.skydns.test. 300 IN SRV 10 100 0 www.miek.nl."
),
},
},
// TODO(miek): bit stupid to rely on my home DNS setup for this...
Extra
:
[]
dns
.
RR
{
Extra
:
[]
dns
.
RR
{
newA("a.miek.nl. 300 IN A 139.162.196.78"),
// 303 ttl: don't care for the ttl on these RRs.
newAAAA("a.miek.nl. 300 IN AAAA 2a01:7e00::f03c:91ff:fef1:6735"),
newA
(
"a.miek.nl. 303 IN A 139.162.196.78"
),
newCNAME("www.miek.nl. 300 IN CNAME a.miek.nl."),
newAAAA
(
"a.miek.nl. 303 IN AAAA 2a01:7e00::f03c:91ff:fef1:6735"
),
newCNAME
(
"www.miek.nl. 303 IN CNAME a.miek.nl."
),
},
},
},
},
/*
// CNAME (unresolvable internal name)
// CNAME (unresolvable internal name)
{
{
Qname: "2.cname.skydns.test.", Qtype: dns.TypeA,
Qname: "2.cname.skydns.test.", Qtype: dns.TypeA,
...
@@ -286,66 +308,77 @@ func newPTR(rr string) *dns.PTR { r, _ := dns.NewRR(rr); return r.(*dns.PTR)
...
@@ -286,66 +308,77 @@ func newPTR(rr string) *dns.PTR { r, _ := dns.NewRR(rr); return r.(*dns.PTR)
func
newTXT
(
rr
string
)
*
dns
.
TXT
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
TXT
)
}
func
newTXT
(
rr
string
)
*
dns
.
TXT
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
TXT
)
}
func
newMX
(
rr
string
)
*
dns
.
MX
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
MX
)
}
func
newMX
(
rr
string
)
*
dns
.
MX
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
MX
)
}
func
checkSection
(
t
*
testing
.
T
,
tc
dnsTestCase
,
rr
[]
dns
.
RR
)
{
func
checkSection
(
t
*
testing
.
T
,
tc
dnsTestCase
,
sect
Section
,
rr
[]
dns
.
RR
)
{
section
:=
[]
dns
.
RR
{}
switch
sect
{
case
0
:
section
=
tc
.
Answer
case
1
:
section
=
tc
.
Ns
case
2
:
section
=
tc
.
Extra
}
for
i
,
a
:=
range
rr
{
for
i
,
a
:=
range
rr
{
if
a
.
Header
()
.
Name
!=
tc
.
Answer
[
i
]
.
Header
()
.
Name
{
if
a
.
Header
()
.
Name
!=
section
[
i
]
.
Header
()
.
Name
{
t
.
Errorf
(
"answer %d should have a Header Name of %q, but has %q"
,
i
,
tc
.
Answer
[
i
]
.
Header
()
.
Name
,
a
.
Header
()
.
Name
)
t
.
Errorf
(
"answer %d should have a Header Name of %q, but has %q"
,
i
,
section
[
i
]
.
Header
()
.
Name
,
a
.
Header
()
.
Name
)
continue
continue
}
}
if
a
.
Header
()
.
Ttl
!=
tc
.
Answer
[
i
]
.
Header
()
.
Ttl
{
// 303 signals: don't care what the ttl is.
t
.
Errorf
(
"Answer %d should have a Header TTL of %d, but has %d"
,
i
,
tc
.
Answer
[
i
]
.
Header
()
.
Ttl
,
a
.
Header
()
.
Ttl
)
if
section
[
i
]
.
Header
()
.
Ttl
!=
303
&&
a
.
Header
()
.
Ttl
!=
section
[
i
]
.
Header
()
.
Ttl
{
t
.
Errorf
(
"Answer %d should have a Header TTL of %d, but has %d"
,
i
,
section
[
i
]
.
Header
()
.
Ttl
,
a
.
Header
()
.
Ttl
)
continue
continue
}
}
if
a
.
Header
()
.
Rrtype
!=
tc
.
Answer
[
i
]
.
Header
()
.
Rrtype
{
if
a
.
Header
()
.
Rrtype
!=
section
[
i
]
.
Header
()
.
Rrtype
{
t
.
Errorf
(
"answer %d should have a header rr type of %d, but has %d
"
,
i
,
tc
.
Answer
[
i
]
.
Header
()
.
Rrtype
,
a
.
Header
()
.
Rrtype
)
t
.
Errorf
(
"answer %d should have a header rr type of %d, but has %d
n"
,
i
,
section
[
i
]
.
Header
()
.
Rrtype
,
a
.
Header
()
.
Rrtype
)
continue
continue
}
}
switch
x
:=
a
.
(
type
)
{
switch
x
:=
a
.
(
type
)
{
case
*
dns
.
SRV
:
case
*
dns
.
SRV
:
if
x
.
Priority
!=
tc
.
Answer
[
i
]
.
(
*
dns
.
SRV
)
.
Priority
{
if
x
.
Priority
!=
section
[
i
]
.
(
*
dns
.
SRV
)
.
Priority
{
t
.
Errorf
(
"answer %d should have a Priority of %d, but has %d"
,
i
,
tc
.
Answer
[
i
]
.
(
*
dns
.
SRV
)
.
Priority
,
x
.
Priority
)
t
.
Errorf
(
"answer %d should have a Priority of %d, but has %d"
,
i
,
section
[
i
]
.
(
*
dns
.
SRV
)
.
Priority
,
x
.
Priority
)
}
}
if
x
.
Weight
!=
tc
.
Answer
[
i
]
.
(
*
dns
.
SRV
)
.
Weight
{
if
x
.
Weight
!=
section
[
i
]
.
(
*
dns
.
SRV
)
.
Weight
{
t
.
Errorf
(
"answer %d should have a Weight of %d, but has %d"
,
i
,
tc
.
Answer
[
i
]
.
(
*
dns
.
SRV
)
.
Weight
,
x
.
Weight
)
t
.
Errorf
(
"answer %d should have a Weight of %d, but has %d"
,
i
,
section
[
i
]
.
(
*
dns
.
SRV
)
.
Weight
,
x
.
Weight
)
}
}
if
x
.
Port
!=
tc
.
Answer
[
i
]
.
(
*
dns
.
SRV
)
.
Port
{
if
x
.
Port
!=
section
[
i
]
.
(
*
dns
.
SRV
)
.
Port
{
t
.
Errorf
(
"answer %d should have a Port of %d, but has %d"
,
i
,
tc
.
Answer
[
i
]
.
(
*
dns
.
SRV
)
.
Port
,
x
.
Port
)
t
.
Errorf
(
"answer %d should have a Port of %d, but has %d"
,
i
,
section
[
i
]
.
(
*
dns
.
SRV
)
.
Port
,
x
.
Port
)
}
}
if
x
.
Target
!=
tc
.
Answer
[
i
]
.
(
*
dns
.
SRV
)
.
Target
{
if
x
.
Target
!=
section
[
i
]
.
(
*
dns
.
SRV
)
.
Target
{
t
.
Errorf
(
"answer %d should have a Target of %q, but has %q"
,
i
,
tc
.
Answer
[
i
]
.
(
*
dns
.
SRV
)
.
Target
,
x
.
Target
)
t
.
Errorf
(
"answer %d should have a Target of %q, but has %q"
,
i
,
section
[
i
]
.
(
*
dns
.
SRV
)
.
Target
,
x
.
Target
)
}
}
case
*
dns
.
A
:
case
*
dns
.
A
:
if
x
.
A
.
String
()
!=
tc
.
Answer
[
i
]
.
(
*
dns
.
A
)
.
A
.
String
()
{
if
x
.
A
.
String
()
!=
section
[
i
]
.
(
*
dns
.
A
)
.
A
.
String
()
{
t
.
Errorf
(
"answer %d should have a Address of %q, but has %q"
,
i
,
tc
.
Answer
[
i
]
.
(
*
dns
.
A
)
.
A
.
String
(),
x
.
A
.
String
())
t
.
Errorf
(
"answer %d should have a Address of %q, but has %q"
,
i
,
section
[
i
]
.
(
*
dns
.
A
)
.
A
.
String
(),
x
.
A
.
String
())
}
}
case
*
dns
.
AAAA
:
case
*
dns
.
AAAA
:
if
x
.
AAAA
.
String
()
!=
tc
.
Answer
[
i
]
.
(
*
dns
.
AAAA
)
.
AAAA
.
String
()
{
if
x
.
AAAA
.
String
()
!=
section
[
i
]
.
(
*
dns
.
AAAA
)
.
AAAA
.
String
()
{
t
.
Errorf
(
"answer %d should have a Address of %q, but has %q"
,
i
,
tc
.
Answer
[
i
]
.
(
*
dns
.
AAAA
)
.
AAAA
.
String
(),
x
.
AAAA
.
String
())
t
.
Errorf
(
"answer %d should have a Address of %q, but has %q"
,
i
,
section
[
i
]
.
(
*
dns
.
AAAA
)
.
AAAA
.
String
(),
x
.
AAAA
.
String
())
}
}
case
*
dns
.
TXT
:
case
*
dns
.
TXT
:
for
j
,
txt
:=
range
x
.
Txt
{
for
j
,
txt
:=
range
x
.
Txt
{
if
txt
!=
tc
.
Answer
[
i
]
.
(
*
dns
.
TXT
)
.
Txt
[
j
]
{
if
txt
!=
section
[
i
]
.
(
*
dns
.
TXT
)
.
Txt
[
j
]
{
t
.
Errorf
(
"answer %d should have a Txt of %q, but has %q"
,
i
,
tc
.
Answer
[
i
]
.
(
*
dns
.
TXT
)
.
Txt
[
j
],
txt
)
t
.
Errorf
(
"answer %d should have a Txt of %q, but has %q"
,
i
,
section
[
i
]
.
(
*
dns
.
TXT
)
.
Txt
[
j
],
txt
)
}
}
}
}
case
*
dns
.
SOA
:
case
*
dns
.
SOA
:
tt
:=
tc
.
Answer
[
i
]
.
(
*
dns
.
SOA
)
tt
:=
section
[
i
]
.
(
*
dns
.
SOA
)
if
x
.
Ns
!=
tt
.
Ns
{
if
x
.
Ns
!=
tt
.
Ns
{
t
.
Errorf
(
"SOA nameserver should be %q, but is %q"
,
x
.
Ns
,
tt
.
Ns
)
t
.
Errorf
(
"SOA nameserver should be %q, but is %q"
,
x
.
Ns
,
tt
.
Ns
)
}
}
case
*
dns
.
PTR
:
case
*
dns
.
PTR
:
tt
:=
tc
.
Answer
[
i
]
.
(
*
dns
.
PTR
)
tt
:=
section
[
i
]
.
(
*
dns
.
PTR
)
if
x
.
Ptr
!=
tt
.
Ptr
{
if
x
.
Ptr
!=
tt
.
Ptr
{
t
.
Errorf
(
"PTR ptr should be %q, but is %q"
,
x
.
Ptr
,
tt
.
Ptr
)
t
.
Errorf
(
"PTR ptr should be %q, but is %q"
,
x
.
Ptr
,
tt
.
Ptr
)
}
}
case
*
dns
.
CNAME
:
case
*
dns
.
CNAME
:
tt
:=
tc
.
Answer
[
i
]
.
(
*
dns
.
CNAME
)
tt
:=
section
[
i
]
.
(
*
dns
.
CNAME
)
if
x
.
Target
!=
tt
.
Target
{
if
x
.
Target
!=
tt
.
Target
{
t
.
Errorf
(
"CNAME target should be %q, but is %q"
,
x
.
Target
,
tt
.
Target
)
t
.
Errorf
(
"CNAME target should be %q, but is %q"
,
x
.
Target
,
tt
.
Target
)
}
}
case
*
dns
.
MX
:
case
*
dns
.
MX
:
tt
:=
tc
.
Answer
[
i
]
.
(
*
dns
.
MX
)
tt
:=
section
[
i
]
.
(
*
dns
.
MX
)
if
x
.
Mx
!=
tt
.
Mx
{
if
x
.
Mx
!=
tt
.
Mx
{
t
.
Errorf
(
"MX Mx should be %q, but is %q"
,
x
.
Mx
,
tt
.
Mx
)
t
.
Errorf
(
"MX Mx should be %q, but is %q"
,
x
.
Mx
,
tt
.
Mx
)
}
}
...
@@ -353,7 +386,7 @@ func checkSection(t *testing.T, tc dnsTestCase, rr []dns.RR) {
...
@@ -353,7 +386,7 @@ func checkSection(t *testing.T, tc dnsTestCase, rr []dns.RR) {
t
.
Errorf
(
"MX Preference should be %q, but is %q"
,
x
.
Preference
,
tt
.
Preference
)
t
.
Errorf
(
"MX Preference should be %q, but is %q"
,
x
.
Preference
,
tt
.
Preference
)
}
}
case
*
dns
.
NS
:
case
*
dns
.
NS
:
tt
:=
tc
.
Ns
[
i
]
.
(
*
dns
.
NS
)
tt
:=
section
[
i
]
.
(
*
dns
.
NS
)
if
x
.
Ns
!=
tt
.
Ns
{
if
x
.
Ns
!=
tt
.
Ns
{
t
.
Errorf
(
"NS nameserver should be %q, but is %q"
,
x
.
Ns
,
tt
.
Ns
)
t
.
Errorf
(
"NS nameserver should be %q, but is %q"
,
x
.
Ns
,
tt
.
Ns
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment