2016-08-23 08:31:50 +08:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRR(t *testing.T) {
|
|
|
|
experiment := RecordConfig{
|
2017-07-20 03:53:40 +08:00
|
|
|
Type: "A",
|
|
|
|
Name: "foo",
|
2018-03-20 05:18:58 +08:00
|
|
|
NameFQDN: "foo.example.com",
|
2021-03-05 07:58:23 +08:00
|
|
|
target: "1.2.3.4",
|
2017-07-20 03:53:40 +08:00
|
|
|
TTL: 0,
|
|
|
|
MxPreference: 0,
|
2016-08-23 08:31:50 +08:00
|
|
|
}
|
|
|
|
expected := "foo.example.com.\t300\tIN\tA\t1.2.3.4"
|
2017-06-17 23:00:12 +08:00
|
|
|
found := experiment.ToRR().String()
|
2016-08-23 08:31:50 +08:00
|
|
|
if found != expected {
|
|
|
|
t.Errorf("RR expected (%#v) got (%#v)\n", expected, found)
|
|
|
|
}
|
2017-07-26 02:59:40 +08:00
|
|
|
|
|
|
|
experiment = RecordConfig{
|
|
|
|
Type: "CAA",
|
|
|
|
Name: "@",
|
2018-03-20 05:18:58 +08:00
|
|
|
NameFQDN: "example.com",
|
2021-03-05 07:58:23 +08:00
|
|
|
target: "mailto:test@example.com",
|
2017-07-26 02:59:40 +08:00
|
|
|
TTL: 300,
|
|
|
|
CaaTag: "iodef",
|
2017-08-01 21:18:47 +08:00
|
|
|
CaaFlag: 1,
|
2017-07-26 02:59:40 +08:00
|
|
|
}
|
|
|
|
expected = "example.com.\t300\tIN\tCAA\t1 iodef \"mailto:test@example.com\""
|
|
|
|
found = experiment.ToRR().String()
|
|
|
|
if found != expected {
|
|
|
|
t.Errorf("RR expected (%#v) got (%#v)\n", expected, found)
|
|
|
|
}
|
2017-09-15 21:03:29 +08:00
|
|
|
|
|
|
|
experiment = RecordConfig{
|
|
|
|
Type: "TLSA",
|
|
|
|
Name: "@",
|
2018-03-20 05:18:58 +08:00
|
|
|
NameFQDN: "_443._tcp.example.com",
|
2021-03-05 07:58:23 +08:00
|
|
|
target: "abcdef0123456789",
|
2017-09-15 21:03:29 +08:00
|
|
|
TTL: 300,
|
|
|
|
TlsaUsage: 0,
|
|
|
|
TlsaSelector: 0,
|
|
|
|
TlsaMatchingType: 1,
|
|
|
|
}
|
|
|
|
expected = "_443._tcp.example.com.\t300\tIN\tTLSA\t0 0 1 abcdef0123456789"
|
|
|
|
found = experiment.ToRR().String()
|
|
|
|
if found != expected {
|
|
|
|
t.Errorf("RR expected (%#v) got (%#v)\n", expected, found)
|
|
|
|
}
|
2016-08-23 08:31:50 +08:00
|
|
|
}
|
2017-11-08 06:12:17 +08:00
|
|
|
|
|
|
|
func TestDowncase(t *testing.T) {
|
|
|
|
dc := DomainConfig{Records: Records{
|
2021-03-05 07:58:23 +08:00
|
|
|
&RecordConfig{Type: "MX", Name: "lower", target: "targetmx"},
|
|
|
|
&RecordConfig{Type: "MX", Name: "UPPER", target: "TARGETMX"},
|
2017-11-08 06:12:17 +08:00
|
|
|
}}
|
2018-03-20 05:18:58 +08:00
|
|
|
downcase(dc.Records)
|
2020-02-18 21:59:18 +08:00
|
|
|
if !dc.Records.HasRecordTypeName("MX", "lower") {
|
2017-11-08 06:12:17 +08:00
|
|
|
t.Errorf("%v: expected (%v) got (%v)\n", dc.Records, false, true)
|
|
|
|
}
|
2020-02-18 21:59:18 +08:00
|
|
|
if !dc.Records.HasRecordTypeName("MX", "upper") {
|
2017-11-08 06:12:17 +08:00
|
|
|
t.Errorf("%v: expected (%v) got (%v)\n", dc.Records, false, true)
|
|
|
|
}
|
2018-03-20 05:18:58 +08:00
|
|
|
if dc.Records[0].GetTargetField() != "targetmx" {
|
|
|
|
t.Errorf("%v: target0 expected (%v) got (%v)\n", dc.Records, "targetmx", dc.Records[0].GetTargetField())
|
2017-11-08 06:12:17 +08:00
|
|
|
}
|
2018-03-20 05:18:58 +08:00
|
|
|
if dc.Records[1].GetTargetField() != "targetmx" {
|
|
|
|
t.Errorf("%v: target1 expected (%v) got (%v)\n", dc.Records, "targetmx", dc.Records[1].GetTargetField())
|
2017-11-08 06:12:17 +08:00
|
|
|
}
|
|
|
|
}
|