2021-05-19 19:38:37 +02:00
|
|
|
package test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
2025-09-30 19:36:13 +03:00
|
|
|
// TestCorefileParsing tests the Corefile parsing functionality.
|
|
|
|
|
// Expected to not panic or timeout.
|
|
|
|
|
func TestCorefileParsing(t *testing.T) {
|
|
|
|
|
cases := []struct {
|
|
|
|
|
name string
|
|
|
|
|
corefile string
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
// See: https://github.com/coredns/coredns/pull/4637
|
|
|
|
|
name: "PR4637_" + "NoPanicOnEscapedBackslashesAndUnicode",
|
|
|
|
|
corefile: `\\\\ȶ.
|
2021-05-19 19:38:37 +02:00
|
|
|
acl
|
2025-09-30 19:36:13 +03:00
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
// See: https://github.com/coredns/coredns/pull/7571
|
|
|
|
|
name: "PR7571_" + "InvalidBlockFailsToStart",
|
|
|
|
|
corefile: "\xD9//\n" +
|
|
|
|
|
"hosts#\x90\xD0{lc\x0C{\n" +
|
|
|
|
|
"'{mport\xEF1\x0C}\x0B''",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
|
defer func() {
|
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
|
t.Fatalf("Expected no panic, but got %v", r)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
i, _, _, _ := CoreDNSServerAndPorts(tc.corefile)
|
|
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
if i != nil {
|
|
|
|
|
i.Stop()
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
})
|
|
|
|
|
}
|
2021-05-19 19:38:37 +02:00
|
|
|
}
|