-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathspf_test.go
114 lines (96 loc) · 3.58 KB
/
spf_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package spf_test
import (
"net"
"testing"
"github.com/mileusna/spf"
)
func TestLookup(t *testing.T) {
if s, r := spf.LookupSPF("naslovi.net"); s == "" {
t.Fatal("SPF to naslovi.net failed", r.String())
}
if s, r := spf.LookupSPF("aviokarte.rs"); s == "" {
t.Fatal("SPF to aviokarte.rs failed", r.String())
}
if _, r := spf.LookupSPF("naslovi.dsdrs"); r != spf.None {
t.Fatal("SPF on invalid domain should be NONE, returned", r.String())
}
}
func TestParse(t *testing.T) {
////fmt.Println(spf.ParseSPF("v=spf1 mx +a include:_spf.ha.rs ip4:87.237.206.36 -ip4:87.237.205.215 ip4:87.237.204.223 include:_spf.google.com ~all"))
//fmt.Println(spf.ParseSPF("v=spf1 +a redirect=_spf.mailspot.com"))
}
func TestCNAME(t *testing.T) {
ip := net.ParseIP("123.123.123.123")
spf.CheckHost(ip, "teicee.fr", "[email protected]", "")
}
type testData struct {
ip net.IP
domain string
sender string
helo string
result spf.Result
}
func newTestData(ip, domain, sender, helo string, expResult spf.Result) testData {
return testData{
ip: net.ParseIP(ip),
domain: domain,
sender: sender,
helo: helo,
result: expResult,
}
}
func TestCheckHost(t *testing.T) {
ip := "188.93.126.226"
ip2 := "87.237.205.46"
data := []testData{
newTestData(ip, "aviokarte.rs", "[email protected]", "", spf.Pass),
newTestData(ip, "naslovi.net", "[email protected]", "", spf.Pass),
newTestData(ip, "netmark.rs", "[email protected]", "", spf.Pass),
newTestData(ip, "gmail.com", "[email protected]", "", spf.Softfail),
newTestData(ip, "hotmail.com", "[email protected]", "", spf.Softfail),
newTestData(ip2, "netmark.rs", "[email protected]", "", spf.Pass),
newTestData(ip2, "liteanalytics.com", "[email protected]", "", spf.Pass),
}
for _, d := range data {
if r := spf.CheckHost(d.ip, d.domain, d.sender, d.helo); r != d.result {
t.Error("CheckHost", d.ip, d.domain, d.sender, "should", d.result, "returned:", r)
}
}
}
func TestDNSSettings(t *testing.T) {
spf.DNSServer = "127.2.2.1:53"
if spf.CheckHost(net.ParseIP("87.237.204.223"), "naslovi.net", "[email protected]", "") != "TEMPERROR" {
t.Error("Invalid DNS configuration should return TEMPERROR")
}
spf.DNSServer = "8.8.8.8:53"
}
func TestMacro(t *testing.T) {
sender := "[email protected]"
ip := net.ParseIP("192.0.2.3")
test := map[string]string{
"%{s}": "[email protected]",
"%{o}": "email.example.com",
"%{d}": "email.example.com",
"%{d4}": "email.example.com",
"%{d3}": "email.example.com",
"%{d2}": "example.com",
"%{d1}": "com",
"%{dr}": "com.example.email",
"%{d2r}": "example.email",
"%{l}": "strong-bad",
"%{l-}": "strong.bad",
"%{lr}": "strong-bad",
"%{lr-}": "bad.strong",
"%{l1r-}": "strong",
"%{ir}.%{v}._spf.%{d2}": "3.2.0.192.in-addr._spf.example.com",
"%{lr-}.lp._spf.%{d2}": "bad.strong.lp._spf.example.com",
"%{ir}.%{v}.%{l1r-}.lp._spf.%{d2}": "3.2.0.192.in-addr.strong.lp._spf.example.com",
"%{d2}.trusted-domains.example.net": "example.com.trusted-domains.example.net",
}
for m, r := range test {
res := spf.Macro(m, ip, "email.example.com", sender, "hello.server")
if res != r {
t.Fatal(m, "result shold be", r, "returned:", res)
}
}
}