forked from zaccone/spf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrace_test.go
88 lines (85 loc) · 2.32 KB
/
trace_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package spf
import (
"errors"
"fmt"
"net"
"testing"
)
func TestTrace_ReceivedSPF(t *testing.T) {
tests := []struct {
name string
trace *Trace
want string
}{
{
"nil",
nil,
"",
},
{
"pass",
&Trace{Result: Pass},
"pass (domain of sender designates the host as permitted sender)",
},
{
"fail+ip+from+receiver",
&Trace{
Result: Fail,
Receiver: "example.net",
EnvelopeFrom: "[email protected]",
ClientIP: net.ParseIP("1:0000::1"),
},
"fail (example.net: domain of [email protected] does not designate 1::1 as permitted sender) client-ip=1::1; [email protected]; receiver=example.net",
},
{
"permerror+ip",
&Trace{
Result: Permerror,
ClientIP: net.ParseIP("1000::1"),
},
"permerror (a permanent error has occured) client-ip=1000::1",
},
{
"permerror+ip+error",
&Trace{
Result: Permerror,
ClientIP: net.ParseIP("1000::1"),
Problem: errors.New("people afraid to use bicycles on the roads"),
},
"permerror (a permanent error has occured) client-ip=1000::1; problem=people afraid to use bicycles on the roads",
},
{
"temperror+ip+mechanism+from",
&Trace{
Result: Temperror,
ClientIP: net.ParseIP("127.0.0.1"),
Mechanism: "default",
EnvelopeFrom: "[email protected]",
},
"temperror (a transient error has occured) client-ip=127.0.0.1; [email protected]; mechanism=default",
},
{
"temperror+ip+error+explanation",
&Trace{
Result: Temperror,
ClientIP: net.ParseIP("1000::1"),
Problem: errors.New("people afraid to use bicycles on the roads"),
Explanation: "motorists either do not treat cyclist as equals or just can't spot them because of difference of speed",
},
"temperror (motorists either do not treat cyclist as equals or just can't spot them because of difference of speed) client-ip=1000::1; problem=people afraid to use bicycles on the roads",
},
}
const wantTest = -1
for testNo, test := range tests {
//noinspection GoBoolExpressions
if wantTest > -1 && wantTest != testNo {
continue
}
t.Run(fmt.Sprintf("%d_%s", testNo, test.name), func(t *testing.T) {
got := test.trace.ReceivedSPF()
if got != test.want {
t.Errorf("ReceivedSPF() got=%q, want=%q", got, test.want)
}
})
}
}