From 9798dd067f53a74e3777cff539b2f01617c107c6 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Thu, 24 Sep 2020 11:30:39 -0700 Subject: Cherry-pick: Implement notifies for transfer plugin (#3972) (#4142) * Implement notifies for transfer plugin (#3972) * Fix notifies in transfer plugin Signed-off-by: Miek Gieben * Make it compile Signed-off-by: Miek Gieben * Port more plugins Signed-off-by: Miek Gieben * golint Signed-off-by: Miek Gieben * Fix tests Signed-off-by: Miek Gieben * Fix notifies in transfer plugin Signed-off-by: Miek Gieben * Make it compile Signed-off-by: Miek Gieben * Port more plugins Signed-off-by: Miek Gieben * golint Signed-off-by: Miek Gieben * Fix tests Signed-off-by: Miek Gieben * Fix tests Signed-off-by: Miek Gieben * really fix test Signed-off-by: Miek Gieben * Implement ixfr fallback and unify file and auto for transfering Signed-off-by: Miek Gieben * Add transfer tests copied and modified from #3452 Signed-off-by: Miek Gieben * Test correct selection of plugin Signed-off-by: Miek Gieben * add upstream back in Signed-off-by: Miek Gieben * Implement ixfr fallback and unify file and auto for transfering Signed-off-by: Miek Gieben * fix test Signed-off-by: Miek Gieben * properly merge Signed-off-by: Miek Gieben * Remove plugin/kubernetes/setup_transfer_test.go Signed-off-by: Yong Tang Co-authored-by: Miek Gieben --- plugin/kubernetes/xfr_test.go | 255 +++++++++++++----------------------------- 1 file changed, 76 insertions(+), 179 deletions(-) (limited to 'plugin/kubernetes/xfr_test.go') diff --git a/plugin/kubernetes/xfr_test.go b/plugin/kubernetes/xfr_test.go index 1ada4f7aa..b5f13ad6e 100644 --- a/plugin/kubernetes/xfr_test.go +++ b/plugin/kubernetes/xfr_test.go @@ -1,229 +1,126 @@ package kubernetes import ( - "context" "strings" "testing" - "github.com/coredns/coredns/plugin/kubernetes/object" - "github.com/coredns/coredns/plugin/pkg/dnstest" - "github.com/coredns/coredns/plugin/test" - "github.com/miekg/dns" ) -func TestKubernetesXFR(t *testing.T) { +func TestKubernetesAXFR(t *testing.T) { k := New([]string{"cluster.local."}) k.APIConn = &APIConnServeTest{} - k.TransferTo = []string{"10.240.0.1:53"} k.Namespaces = map[string]struct{}{"testns": {}} - ctx := context.TODO() - w := dnstest.NewMultiRecorder(&test.ResponseWriter{}) dnsmsg := &dns.Msg{} dnsmsg.SetAxfr(k.Zones[0]) - _, err := k.ServeDNS(ctx, w, dnsmsg) + ch, err := k.Transfer(k.Zones[0], 0) if err != nil { t.Error(err) } + validateAXFR(t, ch) +} - if len(w.Msgs) == 0 { - t.Logf("%+v\n", w) - t.Fatal("Did not get back a zone response") - } - - if len(w.Msgs[0].Answer) == 0 { - t.Logf("%+v\n", w) - t.Fatal("Did not get back an answer") - } - - // Ensure xfr starts with SOA - if w.Msgs[0].Answer[0].Header().Rrtype != dns.TypeSOA { - t.Error("Invalid XFR, does not start with SOA record") - } - - // Ensure xfr starts with SOA - // Last message is empty, so we need to go back one further - if w.Msgs[len(w.Msgs)-2].Answer[len(w.Msgs[len(w.Msgs)-2].Answer)-1].Header().Rrtype != dns.TypeSOA { - t.Error("Invalid XFR, does not end with SOA record") - } - - testRRs := []dns.RR{} - for _, tc := range dnsTestCases { - if tc.Rcode != dns.RcodeSuccess { - continue - } - - for _, ans := range tc.Answer { - // Exclude wildcard searches - if strings.Contains(ans.Header().Name, "*") { - continue - } - - // Exclude TXT records - if ans.Header().Rrtype == dns.TypeTXT { - continue - } - testRRs = append(testRRs, ans) - } - } - - gotRRs := []dns.RR{} - for _, resp := range w.Msgs { - for _, ans := range resp.Answer { - // Skip SOA records since these - // test cases do not exist - if ans.Header().Rrtype == dns.TypeSOA { - continue - } - - gotRRs = append(gotRRs, ans) - } - - } +func TestKubernetesIXFRFallback(t *testing.T) { + k := New([]string{"cluster.local."}) + k.APIConn = &APIConnServeTest{} + k.Namespaces = map[string]struct{}{"testns": {}} - diff := difference(testRRs, gotRRs) - if len(diff) != 0 { - t.Errorf("Got back %d records that do not exist in test cases, should be 0:", len(diff)) - for _, rec := range diff { - t.Errorf("%+v", rec) - } - } + dnsmsg := &dns.Msg{} + dnsmsg.SetAxfr(k.Zones[0]) - diff = difference(gotRRs, testRRs) - if len(diff) != 0 { - t.Errorf("Found %d records we're missing, should be 0:", len(diff)) - for _, rec := range diff { - t.Errorf("%+v", rec) - } + ch, err := k.Transfer(k.Zones[0], 1) + if err != nil { + t.Error(err) } + validateAXFR(t, ch) } -func TestKubernetesXFRNotAllowed(t *testing.T) { +func TestKubernetesIXFRCurrent(t *testing.T) { k := New([]string{"cluster.local."}) k.APIConn = &APIConnServeTest{} - k.TransferTo = []string{"1.2.3.4:53"} k.Namespaces = map[string]struct{}{"testns": {}} - ctx := context.TODO() - w := dnstest.NewMultiRecorder(&test.ResponseWriter{}) dnsmsg := &dns.Msg{} dnsmsg.SetAxfr(k.Zones[0]) - _, err := k.ServeDNS(ctx, w, dnsmsg) + ch, err := k.Transfer(k.Zones[0], 3) if err != nil { t.Error(err) } - if len(w.Msgs) == 0 { - t.Logf("%+v\n", w) - t.Fatal("Did not get back a zone response") + var gotRRs []dns.RR + for rrs := range ch { + gotRRs = append(gotRRs, rrs...) } - if len(w.Msgs[0].Answer) != 0 { - t.Logf("%+v\n", w) - t.Fatal("Got an answer, should not have") + // ensure only one record is returned + if len(gotRRs) > 1 { + t.Errorf("Expected only one answer, got %d", len(gotRRs)) } -} -// difference shows what we're missing when comparing two RR slices -func difference(testRRs []dns.RR, gotRRs []dns.RR) []dns.RR { - expectedRRs := map[string]struct{}{} - for _, rr := range testRRs { - expectedRRs[rr.String()] = struct{}{} + // Ensure first record is a SOA + if gotRRs[0].Header().Rrtype != dns.TypeSOA { + t.Error("Invalid transfer response, does not start with SOA record") } - - foundRRs := []dns.RR{} - for _, rr := range gotRRs { - if _, ok := expectedRRs[rr.String()]; !ok { - foundRRs = append(foundRRs, rr) - } - } - return foundRRs } -func TestEndpointsEquivalent(t *testing.T) { - epA := object.Endpoints{ - Subsets: []object.EndpointSubset{{ - Addresses: []object.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, - }}, - } - epB := object.Endpoints{ - Subsets: []object.EndpointSubset{{ - Addresses: []object.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, - }}, +func validateAXFR(t *testing.T, ch <-chan []dns.RR) { + xfr := []dns.RR{} + for rrs := range ch { + xfr = append(xfr, rrs...) } - epC := object.Endpoints{ - Subsets: []object.EndpointSubset{{ - Addresses: []object.EndpointAddress{{IP: "1.2.3.5", Hostname: "foo"}}, - }}, - } - epD := object.Endpoints{ - Subsets: []object.EndpointSubset{{ - Addresses: []object.EndpointAddress{{IP: "1.2.3.5", Hostname: "foo"}}, - }, - { - Addresses: []object.EndpointAddress{{IP: "1.2.2.2", Hostname: "foofoo"}}, - }}, - } - epE := object.Endpoints{ - Subsets: []object.EndpointSubset{{ - Addresses: []object.EndpointAddress{{IP: "1.2.3.5", Hostname: "foo"}, {IP: "1.1.1.1"}}, - }}, - } - epF := object.Endpoints{ - Subsets: []object.EndpointSubset{{ - Addresses: []object.EndpointAddress{{IP: "1.2.3.4", Hostname: "foofoo"}}, - }}, - } - epG := object.Endpoints{ - Subsets: []object.EndpointSubset{{ - Addresses: []object.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, - Ports: []object.EndpointPort{{Name: "http", Port: 80, Protocol: "TCP"}}, - }}, - } - epH := object.Endpoints{ - Subsets: []object.EndpointSubset{{ - Addresses: []object.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, - Ports: []object.EndpointPort{{Name: "newportname", Port: 80, Protocol: "TCP"}}, - }}, - } - epI := object.Endpoints{ - Subsets: []object.EndpointSubset{{ - Addresses: []object.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, - Ports: []object.EndpointPort{{Name: "http", Port: 8080, Protocol: "TCP"}}, - }}, - } - epJ := object.Endpoints{ - Subsets: []object.EndpointSubset{{ - Addresses: []object.EndpointAddress{{IP: "1.2.3.4", Hostname: "foo"}}, - Ports: []object.EndpointPort{{Name: "http", Port: 80, Protocol: "UDP"}}, - }}, + if xfr[0].Header().Rrtype != dns.TypeSOA { + t.Error("Invalid transfer response, does not start with SOA record") } - tests := []struct { - equiv bool - a *object.Endpoints - b *object.Endpoints - }{ - {true, &epA, &epB}, - {false, &epA, &epC}, - {false, &epA, &epD}, - {false, &epA, &epE}, - {false, &epA, &epF}, - {false, &epF, &epG}, - {false, &epG, &epH}, - {false, &epG, &epI}, - {false, &epG, &epJ}, + zp := dns.NewZoneParser(strings.NewReader(expectedZone), "", "") + i := 0 + for rr, ok := zp.Next(); ok; rr, ok = zp.Next() { + if !dns.IsDuplicate(rr, xfr[i]) { + t.Fatalf("Record %d, expected\n%v\n, got\n%v", i, rr, xfr[i]) + } + i++ } - for i, tc := range tests { - if tc.equiv && !endpointsEquivalent(tc.a, tc.b) { - t.Errorf("Test %d: expected endpoints to be equivalent and they are not.", i) - } - if !tc.equiv && endpointsEquivalent(tc.a, tc.b) { - t.Errorf("Test %d: expected endpoints to be seen as different but they were not.", i) - } + if err := zp.Err(); err != nil { + t.Fatal(err) } } + +const expectedZone = ` +cluster.local. 5 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 3 7200 1800 86400 5 +external.testns.svc.cluster.local. 5 IN CNAME ext.interwebs.test. +external-to-service.testns.svc.cluster.local. 5 IN CNAME svc1.testns.svc.cluster.local. +hdls1.testns.svc.cluster.local. 5 IN A 172.0.0.2 +172-0-0-2.hdls1.testns.svc.cluster.local. 5 IN A 172.0.0.2 +_http._tcp.hdls1.testns.svc.cluster.local. 5 IN SRV 0 16 80 172-0-0-2.hdls1.testns.svc.cluster.local. +hdls1.testns.svc.cluster.local. 5 IN A 172.0.0.3 +172-0-0-3.hdls1.testns.svc.cluster.local. 5 IN A 172.0.0.3 +_http._tcp.hdls1.testns.svc.cluster.local. 5 IN SRV 0 16 80 172-0-0-3.hdls1.testns.svc.cluster.local. +hdls1.testns.svc.cluster.local. 5 IN A 172.0.0.4 +dup-name.hdls1.testns.svc.cluster.local. 5 IN A 172.0.0.4 +_http._tcp.hdls1.testns.svc.cluster.local. 5 IN SRV 0 16 80 dup-name.hdls1.testns.svc.cluster.local. +hdls1.testns.svc.cluster.local. 5 IN A 172.0.0.5 +dup-name.hdls1.testns.svc.cluster.local. 5 IN A 172.0.0.5 +_http._tcp.hdls1.testns.svc.cluster.local. 5 IN SRV 0 16 80 dup-name.hdls1.testns.svc.cluster.local. +hdls1.testns.svc.cluster.local. 5 IN AAAA 5678:abcd::1 +5678-abcd--1.hdls1.testns.svc.cluster.local. 5 IN AAAA 5678:abcd::1 +_http._tcp.hdls1.testns.svc.cluster.local. 5 IN SRV 0 16 80 5678-abcd--1.hdls1.testns.svc.cluster.local. +hdls1.testns.svc.cluster.local. 5 IN AAAA 5678:abcd::2 +5678-abcd--2.hdls1.testns.svc.cluster.local. 5 IN AAAA 5678:abcd::2 +_http._tcp.hdls1.testns.svc.cluster.local. 5 IN SRV 0 16 80 5678-abcd--2.hdls1.testns.svc.cluster.local. +hdlsprtls.testns.svc.cluster.local. 5 IN A 172.0.0.20 +172-0-0-20.hdlsprtls.testns.svc.cluster.local. 5 IN A 172.0.0.20 +svc1.testns.svc.cluster.local. 5 IN A 10.0.0.1 +svc1.testns.svc.cluster.local. 5 IN SRV 0 100 80 svc1.testns.svc.cluster.local. +_http._tcp.svc1.testns.svc.cluster.local. 5 IN SRV 0 100 80 svc1.testns.svc.cluster.local. +svc6.testns.svc.cluster.local. 5 IN AAAA 1234:abcd::1 +svc6.testns.svc.cluster.local. 5 IN SRV 0 100 80 svc6.testns.svc.cluster.local. +_http._tcp.svc6.testns.svc.cluster.local. 5 IN SRV 0 100 80 svc6.testns.svc.cluster.local. +svcempty.testns.svc.cluster.local. 5 IN A 10.0.0.1 +svcempty.testns.svc.cluster.local. 5 IN SRV 0 100 80 svcempty.testns.svc.cluster.local. +_http._tcp.svcempty.testns.svc.cluster.local. 5 IN SRV 0 100 80 svcempty.testns.svc.cluster.local. +cluster.local. 5 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 3 7200 1800 86400 5 +` -- cgit v1.2.3 evert-5167-dylan/decode-regex-if-needed Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
AgeCommit message (Expand)AuthorFilesLines
2023-10-18Adds macOS Keychain certs to default CA storeGravatar Anshul Gupta 2-2/+175
2023-10-18fix(node:buffer): fix the behavior of `totalLength` in `Buffer.concat` (#6574)Gravatar Ai Hoshino 2-3/+23
2023-10-18fix: change `--no-scripts` to `--ignore-scripts` (#6587)Gravatar Dawid Sowa 1-2/+2
2023-10-18fix: online docs moved (#6579)Gravatar Mountain/\Ash 1-1/+1
2023-10-18Fix minimum kernel version in docs (#6153)Gravatar Kevin Latka 1-1/+1
2023-10-18build-id++Gravatar Dylan Conway 1-1/+1
2023-10-18fix(web): stub `performance.getEntriesByName` (#6542)Gravatar Liz 1-0/+18
2023-10-17update root package variableGravatar Dylan Conway 1-8/+3
2023-10-17Fix missing `{port: 0}` causing flaky testGravatar Ashcon Partovi 1-0/+2
2023-10-17test changes in usockets in ciGravatar Dylan Conway 5-0/+9
2023-10-17fix #4766 (#6563)Gravatar Pierre CM 1-4/+4
2023-10-17Update ZigGeneratedClasses.cppGravatar Dylan Conway 1-2/+0
2023-10-17use npm alias in dependencies (#6545)Gravatar Dylan Conway 7-29/+271
2023-10-17fix(node:http): fix `server.address()` (#6442)Gravatar Ai Hoshino 12-12/+453
2023-10-17docs: fix ws.publish (#6558)Gravatar Aral Roca Gomez 1-1/+1
2023-10-17perf(bun-types): remove needless some call (#6550)Gravatar Mikhail 1-1/+1
2023-10-16fix(runtime): make some things more stable (partial jsc debug build) (#5881)Gravatar dave caruso 116-1446/+1830
2023-10-16fix(runtime): improve IPC reliability + organization pass on that code (#6475)Gravatar dave caruso 15-98/+266
2023-10-16Simplify getting Set of extentions (#4975)Gravatar Mikhail 1-3/+3
2023-10-16Fix formattingGravatar Ashcon Partovi 1-3/+1
2023-10-16fix(test): when tests run with --only the nested describe blocks `.on… (#5616)Gravatar Igor Shapiro 2-13/+45
2023-10-16perf(node:events): optimize `emit(...)` function (#5485)Gravatar Yannik Schröder 3-11/+132
2023-10-16fix: don't remove content-encoding header from header table (#5743)Gravatar Liz 2-2/+25
2023-10-16fix(sqlite) Insert .all() does not return an array #5872 (#5946)Gravatar Hugo Galan 2-7/+11
2023-10-16Fix formattingGravatar Ashcon Partovi 2-5/+4
2023-10-16Fix `Response.statusText` (#6151)Gravatar Chris Toshok 10-238/+269
2023-10-16fix-subprocess-argument-missing (#6407)Gravatar Nicolae-Rares Ailincai 4-2/+40
2023-10-16Add type parameter to `expect` (#6128)Gravatar Voldemat 1-3/+3
2023-10-16fix(node:worker_threads): ensure threadId property is exposed on worker_threa...Gravatar Jérôme Benoit 6-15/+75
2023-10-16Fix use before define bug in sqliteGravatar Ashcon Partovi 2-5/+5
2023-10-16fix(jest): fix toStrictEqual on same URLs (#6528)Gravatar João Alisson 2-13/+16
2023-10-16Fix `toHaveBeenCalled` having wrong error signatureGravatar Ashcon Partovi 1-2/+2
2023-10-16Fix formattingGravatar Ashcon Partovi 1-2/+1
2023-10-16Add `reusePort` to `Bun.serve` typesGravatar Ashcon Partovi 1-0/+9
2023-10-16Fix `request.url` having incorrect portGravatar Ashcon Partovi 4-1/+92
2023-10-16Remove uWebSockets header from Bun.serve responsesGravatar Ashcon Partovi 1-6/+6
2023-10-16Rename some testsGravatar Ashcon Partovi 3-0/+0
2023-10-16Fix #6467Gravatar Ashcon Partovi 2-3/+10
2023-10-16Update InternalModuleRegistryConstants.hGravatar Dylan Conway 1-3/+3
2023-10-16Development -> Contributing (#6538)Gravatar Colin McDonnell 2-1/+1
2023-10-14fix(net/tls) fix pg hang on end + hanging on query (#6487)Gravatar Ciro Spaciari 3-8/+36
2023-10-13fix installing dependencies that match workspace versions (#6494)Gravatar Dylan Conway 4-2/+64
2023-10-13fix lockfile struct padding (#6495)Gravatar Dylan Conway 3-3/+18