This repository has been archived by the owner on Jan 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck-ip_test.go
89 lines (76 loc) · 2.15 KB
/
check-ip_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
package main
import (
"strings"
"testing"
)
func TestIPBlacklistOK(t *testing.T) {
//
// Just submit something that is not blacklisted.
//
result, detail := checkBlacklist(Submission{Email: "[email protected]",
Subject: "Hello", IP: "127.0.0.1"})
if result != Undecided {
t.Errorf("Unexpected response: '%v'", result)
}
if len(detail) != 0 {
t.Errorf("Unexpected response: '%v'", detail)
}
}
func TestIPBlacklistOne(t *testing.T) {
//
// This should pass - the IP is outside the CIDR range
//
result, detail := checkBlacklist(Submission{Email: "[email protected]",
Subject: "Hello", IP: "10.20.30.48", Options: "blacklist=10.20.30.40/29"})
if result != Undecided {
t.Errorf("Unexpected response: '%v'", result)
}
if len(detail) != 0 {
t.Errorf("Unexpected response: '%v'", detail)
}
}
func TestIPBlacklistTwo(t *testing.T) {
//
// This should fail the source IP is inside the blacklist.
//
result, detail := checkBlacklist(Submission{Email: "[email protected]",
Subject: "Hello", IP: "10.20.30.47", Options: "blacklist=10.20.30.40/29"})
if result != Spam {
t.Errorf("Unexpected response: '%v'", result)
}
if len(detail) == 0 {
t.Errorf("Unexpected response: '%v'", detail)
}
}
func TestIPBlacklistBogusCIDR(t *testing.T) {
//
// This should fail, as the CIDR is bogus.
//
result, detail := checkBlacklist(Submission{Email: "[email protected]",
Subject: "Hello", IP: "10.20.30.47", Options: "blacklist=10.20.30.40/329"})
if result != Error {
t.Errorf("Unexpected result: '%v'", result)
}
if len(detail) == 0 {
t.Errorf("Unexpected response: '%v'", detail)
}
if !strings.Contains(detail, "parse CIDR") {
t.Errorf("Unexpected response: '%v'", detail)
}
}
func TestIPBlacklistLiterally(t *testing.T) {
//
// This should fail as the IP is blacklisted.
//
result, detail := checkBlacklist(Submission{Email: "[email protected]",
Subject: "Hello", IP: "10.20.30.47", Options: "blacklist=10.20.30.47"})
if result != Spam {
t.Errorf("Unexpected result: '%v'", result)
}
if len(detail) == 0 {
t.Errorf("Unexpected response: '%v'", detail)
}
if !strings.Contains(detail, "IP blacklisted") {
t.Errorf("Unexpected response: '%v'", detail)
}
}