1package spf
2
3import (
4 "net"
5 "testing"
6
7 "github.com/mjl-/mox/dns"
8)
9
10func TestReceived(t *testing.T) {
11 test := func(r Received, exp string) {
12 t.Helper()
13 s := r.Header()
14 if s != exp {
15 t.Fatalf("got %q, expected %q", s, exp)
16 }
17 }
18
19 test(Received{
20 Result: StatusPass,
21 Comment: "c",
22 ClientIP: net.ParseIP("0.0.0.0"),
23 EnvelopeFrom: "x@x",
24 Helo: dns.IPDomain{Domain: dns.Domain{ASCII: "y"}},
25 Problem: `a b"\`,
26 Receiver: "z",
27 Identity: ReceivedMailFrom,
28 Mechanism: "+ip4:0.0.0.0/0",
29 }, "Received-SPF: pass (c) client-ip=0.0.0.0; envelope-from=\"x@x\"; helo=y;\r\n\tproblem=\"a b\\\"\\\\\"; mechanism=\"+ip4:0.0.0.0/0\"; receiver=z; identity=mailfrom\r\n")
30
31 test(Received{
32 Result: StatusPass,
33 ClientIP: net.ParseIP("0.0.0.0"),
34 EnvelopeFrom: "x@x",
35 Helo: dns.IPDomain{IP: net.ParseIP("2001:db8::1")},
36 Receiver: "z",
37 Identity: ReceivedMailFrom,
38 }, "Received-SPF: pass client-ip=0.0.0.0; envelope-from=\"x@x\"; helo=\"2001:db8::1\";\r\n\treceiver=z; identity=mailfrom\r\n")
39}
40