9 "github.com/mjl-/mox/dns"
10 "github.com/mjl-/mox/mlog"
13func TestLookup(t *testing.T) {
14 log := mlog.New("tlsrpt", nil)
15 resolver := dns.MockResolver{
16 TXT: map[string][]string{
17 "_smtp._tls.basic.example.": {"v=TLSRPTv1; rua=mailto:tlsrpt@basic.example"},
18 "_smtp._tls.one.example.": {"v=TLSRPTv1; rua=mailto:tlsrpt@basic.example", "other"},
19 "_smtp._tls.multiple.example.": {"v=TLSRPTv1; rua=mailto:tlsrpt@basic.example", "v=TLSRPTv1; rua=mailto:tlsrpt@basic.example"},
20 "_smtp._tls.malformed.example.": {"v=TLSRPTv1; bad"},
21 "_smtp._tls.other.example.": {"other"},
24 "txt _smtp._tls.temperror.example.",
28 test := func(domain string, expRecord *Record, expErr error) {
31 d := dns.Domain{ASCII: domain}
32 record, _, err := Lookup(context.Background(), log.Logger, resolver, d)
33 if (err == nil) != (expErr == nil) || err != nil && !errors.Is(err, expErr) {
34 t.Fatalf("lookup, got err %#v, expected %#v", err, expErr)
36 if err == nil && !reflect.DeepEqual(record, expRecord) {
37 t.Fatalf("lookup, got %#v, expected %#v", record, expRecord)
41 test("basic.example", &Record{Version: "TLSRPTv1", RUAs: [][]RUA{{"mailto:tlsrpt@basic.example"}}}, nil)
42 test("one.example", &Record{Version: "TLSRPTv1", RUAs: [][]RUA{{"mailto:tlsrpt@basic.example"}}}, nil)
43 test("multiple.example", nil, ErrMultipleRecords)
44 test("absent.example", nil, ErrNoRecord)
45 test("other.example", nil, ErrNoRecord)
46 test("malformed.example", nil, ErrRecordSyntax)
47 test("temperror.example", nil, ErrDNS)