mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	plugin/file: preserve case in SRV record names and targets per RFC 6763 (#7402)
This commit is contained in:
		| @@ -1,6 +1,12 @@ | ||||
| package file | ||||
|  | ||||
| import "testing" | ||||
| import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/coredns/coredns/plugin/file/tree" | ||||
|  | ||||
| 	"github.com/miekg/dns" | ||||
| ) | ||||
|  | ||||
| func TestNameFromRight(t *testing.T) { | ||||
| 	z := NewZone("example.org.", "stdin") | ||||
| @@ -28,3 +34,41 @@ func TestNameFromRight(t *testing.T) { | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestInsertPreservesSRVCase(t *testing.T) { | ||||
| 	z := NewZone("home.arpa.", "stdin") | ||||
|  | ||||
| 	// SRV with mixed case and space-escaped instance name | ||||
| 	srv, err := dns.NewRR(`Home\032Media._smb._tcp.home.arpa. 5 IN SRV 0 0 445 samba.home.arpa.`) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("Failed to parse SRV RR: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if err := z.Insert(srv); err != nil { | ||||
| 		t.Fatalf("Insert failed: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	found := false | ||||
| 	err = z.Walk(func(elem *tree.Elem, rrsets map[uint16][]dns.RR) error { | ||||
| 		for _, rrs := range rrsets { | ||||
| 			for _, rr := range rrs { | ||||
| 				if srvRR, ok := rr.(*dns.SRV); ok { | ||||
| 					if srvRR.Hdr.Name == "Home\\032Media._smb._tcp.home.arpa." { | ||||
| 						found = true | ||||
| 						if srvRR.Target != "samba.home.arpa." { | ||||
| 							t.Errorf("Expected SRV target to be 'samba.home.arpa.', got %q", srvRR.Target) | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		return nil | ||||
| 	}) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("Tree walk failed: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	if !found { | ||||
| 		t.Errorf("SRV record with original case not found in tree") | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user