dns_record_test.go 918 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package option
  2. import (
  3. "testing"
  4. "github.com/miekg/dns"
  5. "github.com/stretchr/testify/require"
  6. )
  7. func mustRecordOptions(t *testing.T, record string) DNSRecordOptions {
  8. t.Helper()
  9. var value DNSRecordOptions
  10. require.NoError(t, value.UnmarshalJSON([]byte(`"`+record+`"`)))
  11. return value
  12. }
  13. func TestDNSRecordOptionsUnmarshalJSONRejectsRelativeNames(t *testing.T) {
  14. t.Parallel()
  15. for _, record := range []string{
  16. "@ IN A 1.1.1.1",
  17. "www IN CNAME example.com.",
  18. "example.com. IN CNAME @",
  19. "example.com. IN CNAME www",
  20. } {
  21. var value DNSRecordOptions
  22. err := value.UnmarshalJSON([]byte(`"` + record + `"`))
  23. require.Error(t, err)
  24. }
  25. }
  26. func TestDNSRecordOptionsMatchIgnoresTTL(t *testing.T) {
  27. t.Parallel()
  28. expected := mustRecordOptions(t, "example.com. 600 IN A 1.1.1.1")
  29. record, err := dns.NewRR("example.com. 60 IN A 1.1.1.1")
  30. require.NoError(t, err)
  31. require.True(t, expected.Match(record))
  32. }