mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Direct SOA record management (#1115)
* Adds SOA record to JS, zone parsing and record validation * adds JS parsing test for SOA record * fix validation & regenerates static resources * Adds label and target test for SOA record * Removes serial from SOA JS macro * Adds generated resources * reformat with gofmt Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
@@ -9,6 +9,73 @@ import (
|
||||
"github.com/StackExchange/dnscontrol/v3/providers"
|
||||
)
|
||||
|
||||
func TestSoaLabelAndTarget(t *testing.T) {
|
||||
var tests = []struct {
|
||||
isError bool
|
||||
label string
|
||||
target string
|
||||
}{
|
||||
{false, "@", "ns1.foo.com."},
|
||||
// Invalid target
|
||||
{true, "@", "ns1.foo.com"},
|
||||
// Invalid label, only '@' is allowed for SOA records
|
||||
{true, "foo.com", "ns1.foo.com."},
|
||||
}
|
||||
for _, test := range tests {
|
||||
experiment := fmt.Sprintf("%s %s", test.label, test.target)
|
||||
rc := makeRC(test.label, "foo.com", test.target, models.RecordConfig{Type: "SOA",
|
||||
SoaExpire: 1, SoaMinttl: 1, SoaRefresh: 1, SoaRetry: 1, SoaSerial: 1, SoaMbox: "bar.foo.com"})
|
||||
err := checkTargets(rc, "foo.com")
|
||||
if err != nil && !test.isError {
|
||||
t.Errorf("%v: Error (%v)\n", experiment, err)
|
||||
}
|
||||
if err == nil && test.isError {
|
||||
t.Errorf("%v: Expected error but got none \n", experiment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckSoa(t *testing.T) {
|
||||
var tests = []struct {
|
||||
isError bool
|
||||
expire uint32
|
||||
minttl uint32
|
||||
refresh uint32
|
||||
retry uint32
|
||||
serial uint32
|
||||
mbox string
|
||||
}{
|
||||
// Expire
|
||||
{false, 123, 123, 123, 123, 123, "foo.bar.com."},
|
||||
{true, 0, 123, 123, 123, 123, "foo.bar.com."},
|
||||
// MinTTL
|
||||
{false, 123, 123, 123, 123, 123, "foo.bar.com."},
|
||||
{true, 123, 0, 123, 123, 123, "foo.bar.com."},
|
||||
// Refresh
|
||||
{false, 123, 123, 123, 123, 123, "foo.bar.com."},
|
||||
{true, 123, 123, 0, 123, 123, "foo.bar.com."},
|
||||
// Retry
|
||||
{false, 123, 123, 123, 123, 123, "foo.bar.com."},
|
||||
{true, 123, 123, 123, 0, 123, "foo.bar.com."},
|
||||
// Serial
|
||||
{false, 123, 123, 123, 123, 123, "foo.bar.com."},
|
||||
{false, 123, 123, 123, 123, 0, "foo.bar.com."},
|
||||
// MBox
|
||||
{true, 123, 123, 123, 123, 123, ""},
|
||||
{true, 123, 123, 123, 123, 123, "foo@bar.com."},
|
||||
{false, 123, 123, 123, 123, 123, "foo.bar.com."},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
experiment := fmt.Sprintf("%d %d %d %d %d %s", test.expire, test.minttl, test.refresh,
|
||||
test.retry, test.serial, test.mbox)
|
||||
t.Run(experiment, func(t *testing.T) {
|
||||
err := checkSoa(test.expire, test.minttl, test.refresh, test.retry, test.serial, test.mbox)
|
||||
checkError(t, err, test.isError, experiment)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckLabel(t *testing.T) {
|
||||
var tests = []struct {
|
||||
label string
|
||||
|
||||
Reference in New Issue
Block a user