mw/kubernetes: rewrite parseRequest
Stop looking at the qtype in parseRequest and make k.Namespace a map. Fallout from this is that pkg/strings as it is not used anymore. Also add a few helper functions to make unexposed namespaces easier to see in the code. Add wildcard tests to the middleware tests.
This commit is contained in:
parent
627687b11f
commit
118ef3dfa0
7 changed files with 128 additions and 127 deletions
|
@ -24,18 +24,12 @@ func TestParseRequest(t *testing.T) {
|
|||
{
|
||||
// wildcard acceptance
|
||||
"*.any.*.any.svc.inter.webs.test.", dns.TypeSRV,
|
||||
"*.any..*.any.svc",
|
||||
"*.*.any.*.any.svc",
|
||||
},
|
||||
{
|
||||
// A request of endpoint
|
||||
"1-2-3-4.webs.mynamespace.svc.inter.webs.test.", dns.TypeA,
|
||||
"..1-2-3-4.webs.mynamespace.svc",
|
||||
},
|
||||
{
|
||||
|
||||
// 3 segments
|
||||
"webs.mynamespace.svc.inter.webs.test.", dns.TypeSRV,
|
||||
"*...webs.mynamespace.svc",
|
||||
"*.*.1-2-3-4.webs.mynamespace.svc",
|
||||
},
|
||||
}
|
||||
for i, tc := range tests {
|
||||
|
@ -57,21 +51,18 @@ func TestParseRequest(t *testing.T) {
|
|||
func TestParseInvalidRequest(t *testing.T) {
|
||||
k := New([]string{zone})
|
||||
|
||||
invalid := map[string]uint16{
|
||||
"_http._tcp.webs.mynamespace.svc.inter.webs.test.": dns.TypeA, // A requests cannot have port or protocol
|
||||
"_http._pcp.webs.mynamespace.svc.inter.webs.test.": dns.TypeSRV, // SRV protocol must be tcp or udp
|
||||
"_http._tcp.ep.webs.ns.svc.inter.webs.test.": dns.TypeSRV, // SRV requests cannot have an endpoint
|
||||
"_*._*.webs.mynamespace.svc.inter.webs.test.": dns.TypeSRV, // SRV request with invalid wildcards
|
||||
|
||||
invalid := []string{
|
||||
"webs.mynamespace.pood.inter.webs.test.", // Request must be for pod or svc subdomain.
|
||||
"too.long.for.what.I.am.trying.to.do.inter.webs.tests.", // Too long.
|
||||
}
|
||||
|
||||
for query, qtype := range invalid {
|
||||
for i, query := range invalid {
|
||||
m := new(dns.Msg)
|
||||
m.SetQuestion(query, qtype)
|
||||
m.SetQuestion(query, dns.TypeA)
|
||||
state := request.Request{Zone: zone, Req: m}
|
||||
|
||||
if _, e := k.parseRequest(state); e == nil {
|
||||
t.Errorf("Expected error from %s:%d, got none", query, qtype)
|
||||
t.Errorf("Test %d: expected error from %s, got none", i, query)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue