11 "github.com/mjl-/mox/dmarcrpt"
12 "github.com/mjl-/mox/dns"
13 "github.com/mjl-/mox/mox-"
16var ctxbg = context.Background()
18func TestDMARCDB(t *testing.T) {
20 mox.ConfigStaticPath = filepath.FromSlash("../testdata/dmarcdb/mox.conf")
21 mox.MustLoadConfig(true, false)
23 os.Remove(mox.DataDirPath("dmarcrpt.db"))
25 tcheckf(t, err, "init")
28 tcheckf(t, err, "close")
31 feedback := &dmarcrpt.Feedback{
32 ReportMetadata: dmarcrpt.ReportMetadata{
33 OrgName: "google.com",
34 Email: "noreply-dmarc-support@google.com",
35 ExtraContactInfo: "https://support.google.com/a/answer/2466580",
36 ReportID: "10051505501689795560",
37 DateRange: dmarcrpt.DateRange{
42 PolicyPublished: dmarcrpt.PolicyPublished{
43 Domain: "example.org",
47 SubdomainPolicy: "reject",
50 Records: []dmarcrpt.ReportRecord{
53 SourceIP: "127.0.0.1",
55 PolicyEvaluated: dmarcrpt.PolicyEvaluated{
56 Disposition: dmarcrpt.DispositionNone,
57 DKIM: dmarcrpt.DMARCPass,
58 SPF: dmarcrpt.DMARCPass,
61 Identifiers: dmarcrpt.Identifiers{
62 HeaderFrom: "example.org",
64 AuthResults: dmarcrpt.AuthResults{
65 DKIM: []dmarcrpt.DKIMAuthResult{
67 Domain: "example.org",
68 Result: dmarcrpt.DKIMPass,
72 SPF: []dmarcrpt.SPFAuthResult{
74 Domain: "example.org",
75 Result: dmarcrpt.SPFPass,
82 if err := AddReport(ctxbg, feedback, dns.Domain{ASCII: "google.com"}); err != nil {
83 t.Fatalf("adding report: %s", err)
86 records, err := Records(ctxbg)
87 if err != nil || len(records) != 1 || !reflect.DeepEqual(&records[0].Feedback, feedback) {
88 t.Fatalf("records: got err %v, records %#v, expected no error, single record with feedback %#v", err, records, feedback)
91 record, err := RecordID(ctxbg, records[0].ID)
92 if err != nil || !reflect.DeepEqual(&record.Feedback, feedback) {
93 t.Fatalf("record id: got err %v, record %#v, expected feedback %#v", err, record, feedback)
96 start := time.Unix(1596412800, 0)
97 end := time.Unix(1596499199, 0)
98 records, err = RecordsPeriodDomain(ctxbg, start, end, "example.org")
99 if err != nil || len(records) != 1 || !reflect.DeepEqual(&records[0].Feedback, feedback) {
100 t.Fatalf("records: got err %v, records %#v, expected no error, single record with feedback %#v", err, records, feedback)
103 records, err = RecordsPeriodDomain(ctxbg, end, end, "example.org")
104 if err != nil || len(records) != 0 {
105 t.Fatalf("records: got err %v, records %#v, expected no error and no records", err, records)
107 records, err = RecordsPeriodDomain(ctxbg, start, end, "other.example")
108 if err != nil || len(records) != 0 {
109 t.Fatalf("records: got err %v, records %#v, expected no error and no records", err, records)