diff options
author | 2016-11-10 16:24:06 -0500 | |
---|---|---|
committer | 2016-11-10 21:24:06 +0000 | |
commit | 96206cdbc38536e108ad553f0b17c5f7c9d856f8 (patch) | |
tree | 384092f55fa14a478c368338ae62d0a0ebc6741d /test/kubernetes_test.go | |
parent | 4036c3c31998de77cc1ba40d0f80207669917527 (diff) | |
download | coredns-96206cdbc38536e108ad553f0b17c5f7c9d856f8.tar.gz coredns-96206cdbc38536e108ad553f0b17c5f7c9d856f8.tar.zst coredns-96206cdbc38536e108ad553f0b17c5f7c9d856f8.zip |
Return NXDOMAIN when no items match query (#422)
* When no records match, reply with NXDOMAIN
* Implement in IsNameError
* case for unexposed namespace. k8s integation tests
* Fix imports order. Lower case of err strs.
Diffstat (limited to 'test/kubernetes_test.go')
-rw-r--r-- | test/kubernetes_test.go | 282 |
1 files changed, 159 insertions, 123 deletions
diff --git a/test/kubernetes_test.go b/test/kubernetes_test.go index dc3e512b9..6fba08e54 100644 --- a/test/kubernetes_test.go +++ b/test/kubernetes_test.go @@ -3,72 +3,160 @@ package test import ( - "io/ioutil" - "log" "testing" "time" + "github.com/miekg/coredns/middleware/test" + "github.com/mholt/caddy" "github.com/miekg/dns" ) -// Test data for A records -var testdataLookupA = []struct { - Query string - TotalAnswerCount int - ARecordCount int -}{ - // Matching queries - {"mynginx.demo.svc.coredns.local.", 1, 1}, // One A record, should exist - - // Failure queries - {"mynginx.test.svc.coredns.local.", 0, 0}, // One A record, is not exposed - {"someservicethatdoesnotexist.demo.svc.coredns.local.", 0, 0}, // Record does not exist - - // Namespace wildcards - {"mynginx.*.svc.coredns.local.", 1, 1}, // One A record, via wildcard namespace - {"mynginx.any.svc.coredns.local.", 1, 1}, // One A record, via wildcard namespace - {"someservicethatdoesnotexist.*.svc.coredns.local.", 0, 0}, // Record does not exist with wildcard for namespace - {"someservicethatdoesnotexist.any.svc.coredns.local.", 0, 0}, // Record does not exist with wildcard for namespace - {"*.demo.svc.coredns.local.", 2, 2}, // Two A records, via wildcard - {"any.demo.svc.coredns.local.", 2, 2}, // Two A records, via wildcard - {"*.test.svc.coredns.local.", 0, 0}, // Two A record, via wildcard that is not exposed - {"any.test.svc.coredns.local.", 0, 0}, // Two A record, via wildcard that is not exposed - {"*.*.svc.coredns.local.", 2, 2}, // Two A records, via namespace and service wildcard -} - -// Test data for SRV records -var testdataLookupSRV = []struct { - Query string - TotalAnswerCount int - // ARecordCount int - SRVRecordCount int -}{ - // Matching queries - {"mynginx.demo.svc.coredns.local.", 1, 1}, // One SRV record, should exist - - // Failure queries - {"mynginx.test.svc.coredns.local.", 0, 0}, // One SRV record, is not exposed - {"someservicethatdoesnotexist.demo.svc.coredns.local.", 0, 0}, // Record does not exist - - // Namespace wildcards - {"mynginx.*.svc.coredns.local.", 1, 1}, // One SRV record, via wildcard namespace - {"mynginx.any.svc.coredns.local.", 1, 1}, // One SRV record, via wildcard namespace - {"someservicethatdoesnotexist.*.svc.coredns.local.", 0, 0}, // Record does not exist with wildcard for namespace - {"someservicethatdoesnotexist.any.svc.coredns.local.", 0, 0}, // Record does not exist with wildcard for namespace - {"*.demo.svc.coredns.local.", 2, 2}, // Two (mynginx, webserver) SRV record, via wildcard - {"any.demo.svc.coredns.local.", 2, 2}, // Two (mynginx, webserver) SRV record, via wildcard - {"*.test.svc.coredns.local.", 0, 0}, // One SRV record, via wildcard that is not exposed - {"any.test.svc.coredns.local.", 0, 0}, // One SRV record, via wildcard that is not exposed - {"*.*.svc.coredns.local.", 2, 2}, // Two SRV record, via namespace and service wildcard -} - -func TestKubernetesIntegration(t *testing.T) { - - // t.Skip("Skip Kubernetes Integration tests") - // subtests here (Go 1.7 feature). - testLookupA(t) - testLookupSRV(t) +// Test data +// TODO: Fix the actual RR values + +var dnsTestCases = []test.Case{ + { + Qname: "mynginx.demo.svc.coredns.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.A("mynginx.demo.svc.coredns.local. 1800 IN A 10.3.0.10"), + }, + }, + { + Qname: "bogusservice.demo.svc.coredns.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeNameError, + Answer: []dns.RR{}, + }, + { + Qname: "mynginx.*.svc.coredns.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.A("mynginx.demo.svc.coredns.local. 1800 IN A 10.3.0.10"), + }, + }, + { + Qname: "mynginx.any.svc.coredns.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.A("mynginx.demo.svc.coredns.local. 1800 IN A 10.3.0.10"), + }, + }, + { + Qname: "bogusservice.*.svc.coredns.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeNameError, + Answer: []dns.RR{}, + }, + { + Qname: "bogusservice.any.svc.coredns.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeNameError, + Answer: []dns.RR{}, + }, + { + Qname: "*.demo.svc.coredns.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.A("mynginx.demo.svc.coredns.local. 1800 IN A 10.3.0.10"), + test.A("webserver.demo.svc.coredns.local. 1800 IN A 10.3.0.20"), + }, + }, + { + Qname: "any.demo.svc.coredns.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.A("mynginx.demo.svc.coredns.local. 1800 IN A 10.3.0.10"), + test.A("webserver.demo.svc.coredns.local. 1800 IN A 10.3.0.20"), + }, + }, + { + Qname: "any.test.svc.coredns.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeNameError, + Answer: []dns.RR{}, + }, + { + Qname: "*.test.svc.coredns.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeNameError, + Answer: []dns.RR{}, + }, + { + Qname: "*.*.svc.coredns.local.", Qtype: dns.TypeA, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.A("mynginx.demo.svc.coredns.local. 1800 IN A 10.3.0.10"), + test.A("webserver.demo.svc.coredns.local. 1800 IN A 10.3.0.20"), + }, + }, + //TODO: Fix below to all use test.SRV not test.A! + { + Qname: "mynginx.demo.svc.coredns.local.", Qtype: dns.TypeSRV, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.A("mynginx.demo.svc.coredns.local. 1800 IN A 10.3.0.10"), + }, + }, + { + Qname: "bogusservice.demo.svc.coredns.local.", Qtype: dns.TypeSRV, + Rcode: dns.RcodeNameError, + Answer: []dns.RR{}, + }, + { + Qname: "mynginx.*.svc.coredns.local.", Qtype: dns.TypeSRV, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.A("mynginx.demo.svc.coredns.local. 1800 IN A 10.3.0.10"), + }, + }, + { + Qname: "mynginx.any.svc.coredns.local.", Qtype: dns.TypeSRV, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.A("mynginx.demo.svc.coredns.local. 1800 IN A 10.3.0.10"), + }, + }, + { + Qname: "bogusservice.*.svc.coredns.local.", Qtype: dns.TypeSRV, + Rcode: dns.RcodeNameError, + Answer: []dns.RR{}, + }, + { + Qname: "bogusservice.any.svc.coredns.local.", Qtype: dns.TypeSRV, + Rcode: dns.RcodeNameError, + Answer: []dns.RR{}, + }, + { + Qname: "*.demo.svc.coredns.local.", Qtype: dns.TypeSRV, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.A("mynginx.demo.svc.coredns.local. 1800 IN A 10.3.0.10"), + test.A("webserver.demo.svc.coredns.local. 1800 IN A 10.3.0.20"), + }, + }, + { + Qname: "any.demo.svc.coredns.local.", Qtype: dns.TypeSRV, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.A("mynginx.demo.svc.coredns.local. 1800 IN A 10.3.0.10"), + test.A("webserver.demo.svc.coredns.local. 1800 IN A 10.3.0.20"), + }, + }, + { + Qname: "any.test.svc.coredns.local.", Qtype: dns.TypeSRV, + Rcode: dns.RcodeNameError, + Answer: []dns.RR{}, + }, + { + Qname: "*.test.svc.coredns.local.", Qtype: dns.TypeSRV, + Rcode: dns.RcodeNameError, + Answer: []dns.RR{}, + }, + { + Qname: "*.*.svc.coredns.local.", Qtype: dns.TypeSRV, + Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.A("mynginx.demo.svc.coredns.local. 1800 IN A 10.3.0.10"), + test.A("webserver.demo.svc.coredns.local. 1800 IN A 10.3.0.20"), + }, + }, } func createTestServer(t *testing.T, corefile string) (*caddy.Instance, string) { @@ -85,96 +173,44 @@ func createTestServer(t *testing.T, corefile string) (*caddy.Instance, string) { return server, udp } -func testLookupA(t *testing.T) { +func TestKubernetesIntegration(t *testing.T) { corefile := `.:0 { kubernetes coredns.local { endpoint http://localhost:8080 + #endpoint https://kubernetes/ admin.pem admin-key.pem ca.pem + #endpoint https://kubernetes/ + #tls k8s_auth/client2.crt k8s_auth/client2.key k8s_auth/ca2.crt namespaces demo } - ` server, udp := createTestServer(t, corefile) defer server.Stop() - log.SetOutput(ioutil.Discard) - // Work-around for timing condition that results in no-data being returned in // test environment. time.Sleep(5 * time.Second) - for _, testData := range testdataLookupA { + for _, tc := range dnsTestCases { dnsClient := new(dns.Client) dnsMessage := new(dns.Msg) - dnsMessage.SetQuestion(testData.Query, dns.TypeA) - dnsMessage.SetEdns0(4096, true) + dnsMessage.SetQuestion(tc.Qname, tc.Qtype) res, _, err := dnsClient.Exchange(dnsMessage, udp) if err != nil { t.Fatalf("Could not send query: %s", err) } - // Count A records in the answer section - ARecordCount := 0 - for _, a := range res.Answer { - if a.Header().Rrtype == dns.TypeA { - ARecordCount++ - } - } - if ARecordCount != testData.ARecordCount { - t.Errorf("Expected '%v' A records in response. Instead got '%v' A records. Test query string: '%v'", testData.ARecordCount, ARecordCount, testData.Query) + // check the answer + if res.Rcode != tc.Rcode { + t.Errorf("Expected rcode %d but got %d for query %s, %d", tc.Rcode, res.Rcode, tc.Qname, tc.Qtype) } - if len(res.Answer) != testData.TotalAnswerCount { - t.Errorf("Expected '%v' records in answer section. Instead got '%v' records in answer section. Test query string: '%v'", testData.TotalAnswerCount, len(res.Answer), testData.Query) - } - } -} -func testLookupSRV(t *testing.T) { - corefile := - `.:0 { - kubernetes coredns.local { - endpoint http://localhost:8080 - namespaces demo - } -` - - server, udp := createTestServer(t, corefile) - defer server.Stop() - - log.SetOutput(ioutil.Discard) - - // Work-around for timing condition that results in no-data being returned in - // test environment. - time.Sleep(5 * time.Second) - - // TODO: Add checks for A records in additional section - - for _, testData := range testdataLookupSRV { - dnsClient := new(dns.Client) - dnsMessage := new(dns.Msg) - - dnsMessage.SetQuestion(testData.Query, dns.TypeSRV) - dnsMessage.SetEdns0(4096, true) - - res, _, err := dnsClient.Exchange(dnsMessage, udp) - if err != nil { - t.Fatalf("Could not send query: %s", err) - } - // Count SRV records in the answer section - srvRecordCount := 0 - for _, a := range res.Answer { - if a.Header().Rrtype == dns.TypeSRV { - srvRecordCount++ - } + if len(res.Answer) != len(tc.Answer) { + t.Errorf("Expected %d answers but got %d for query %s, %d", len(tc.Answer), len(res.Answer), tc.Qname, tc.Qtype) } - if srvRecordCount != testData.SRVRecordCount { - t.Errorf("Expected '%v' SRV records in response. Instead got '%v' SRV records. Test query string: '%v', res: %v", testData.SRVRecordCount, srvRecordCount, testData.Query, res) - } - if len(res.Answer) != testData.TotalAnswerCount { - t.Errorf("Expected '%v' records in answer section. Instead got '%v' records in answer section. Test query string: '%v', res: %v", testData.TotalAnswerCount, len(res.Answer), testData.Query, res) - } + //TODO: Check the actual RR values } } |