mirror of
https://github.com/coredns/coredns.git
synced 2025-12-26 20:15:10 -05:00
fix(sign): report parser err before missing SOA (#7775)
This commit is contained in:
@@ -80,13 +80,12 @@ func Parse(f io.Reader, origin, fileName string) (*file.Zone, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := zp.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if !seenSOA {
|
if !seenSOA {
|
||||||
return nil, fmt.Errorf("file %q has no SOA record", fileName)
|
return nil, fmt.Errorf("file %q has no SOA record", fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := zp.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return z, nil
|
return z, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package sign
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
@@ -41,3 +42,41 @@ func TestFileParse(t *testing.T) {
|
|||||||
t.Errorf("Expected no DNSKEYs, but got %d", len(key))
|
t.Errorf("Expected no DNSKEYs, but got %d", len(key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseSyntaxErrorBeforeSOA(t *testing.T) {
|
||||||
|
const dbSyntaxErrorBeforeSOA = `
|
||||||
|
$TTL 1M
|
||||||
|
$ORIGIN example.org.
|
||||||
|
|
||||||
|
@ IN SOA ns1.example.com. admin.example.com. (
|
||||||
|
foobarbaz ; Invalid serial
|
||||||
|
1200 ; Refresh
|
||||||
|
144 ; Retry
|
||||||
|
1814400 ; Expire
|
||||||
|
2h ) ; Minimum
|
||||||
|
`
|
||||||
|
_, err := Parse(strings.NewReader(dbSyntaxErrorBeforeSOA), "example.org.", "stdin")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("Zone %q should have failed to load", "example.org.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(err.Error(), "bad SOA zone parameter") {
|
||||||
|
t.Fatalf("Expected parser error, but got: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseNoSOA(t *testing.T) {
|
||||||
|
const dbNoSOA = `
|
||||||
|
$TTL 1M
|
||||||
|
$ORIGIN example.org.
|
||||||
|
|
||||||
|
www IN A 192.168.0.14
|
||||||
|
`
|
||||||
|
_, err := Parse(strings.NewReader(dbNoSOA), "example.org.", "stdin")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("Zone %q should have failed to load", "example.org.")
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), "has no SOA record") {
|
||||||
|
t.Fatalf("Expected 'no SOA record' error, but got: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user