MCPcopy Create free account
hub / github.com/foxcpp/maddy / TestDMARC

Function TestDMARC

internal/dmarc/verifier_test.go:35–222  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33)
34
35func TestDMARC(t *testing.T) {
36 test := func(zones map[string]mockdns.Zone, hdr string, authres []authres.Result, policyApplied Policy, dmarcRes authres.ResultValue) {
37 t.Helper()
38 v := NewVerifier(&mockdns.Resolver{Zones: zones})
39 defer func() {
40 require.NoError(t, v.Close())
41 }()
42
43 hdrParsed, err := textproto.ReadHeader(bufio.NewReader(strings.NewReader(hdr)))
44 if err != nil {
45 panic(err)
46 }
47 v.FetchRecord(context.Background(), hdrParsed)
48 evalRes, policy := v.Apply(authres)
49
50 if policy != policyApplied {
51 t.Errorf("expected applied policy to be '%v', got '%v'", policyApplied, policy)
52 }
53 if evalRes.Authres.Value != dmarcRes {
54 t.Errorf("expected DMARC result to be '%v', got '%v'", dmarcRes, evalRes.Authres.Value)
55 }
56 }
57
58 // No policy => DMARC 'none'
59 test(map[string]mockdns.Zone{}, "From: hello@example.org\r\n\r\n", []authres.Result{
60 &authres.DKIMResult{Value: authres.ResultPass, Domain: "example.org"},
61 &authres.SPFResult{Value: authres.ResultNone, From: "example.org", Helo: "mx.example.org"},
62 }, PolicyNone, authres.ResultNone)
63
64 // Policy present & identifiers align => DMARC 'pass'
65 test(map[string]mockdns.Zone{
66 "_dmarc.example.org.": {
67 TXT: []string{"v=DMARC1; p=none"},
68 },
69 }, "From: hello@example.org\r\n\r\n", []authres.Result{
70 &authres.DKIMResult{Value: authres.ResultPass, Domain: "example.org"},
71 &authres.SPFResult{Value: authres.ResultNone, From: "example.org", Helo: "mx.example.org"},
72 }, PolicyNone, authres.ResultPass)
73
74 // No SPF check run => DMARC 'none', no action taken
75 test(map[string]mockdns.Zone{
76 "_dmarc.example.org.": {
77 TXT: []string{"v=DMARC1; p=reject"},
78 },
79 }, "From: hello@example.org\r\n\r\n", []authres.Result{
80 &authres.DKIMResult{Value: authres.ResultPass, Domain: "example.org"},
81 }, PolicyNone, authres.ResultNone)
82
83 // No DKIM check run => DMARC 'none', no action taken
84 test(map[string]mockdns.Zone{
85 "_dmarc.example.org.": {
86 TXT: []string{"v=DMARC1; p=reject"},
87 },
88 }, "From: hello@example.org\r\n\r\n", []authres.Result{
89 &authres.SPFResult{Value: authres.ResultPass, From: "example.org", Helo: "mx.example.org"},
90 }, PolicyNone, authres.ResultNone)
91
92 // Check org. domain and from domain, prefer from domain.

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.95
FetchRecordMethod · 0.95
ApplyMethod · 0.95
NewVerifierFunction · 0.85
testStruct · 0.85

Tested by

no test coverage detected