-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiplist_test.go
62 lines (50 loc) · 1.61 KB
/
iplist_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
package iplist
import (
"testing"
"net/http"
)
func TestShouldCheckIfIpIsFoundInBlockList(t *testing.T) {
response, err := http.Get("https://raw.githubusercontent.com/firehol/blocklist-ipsets/master/firehol_level1.netset")
if err != nil {
t.Fatalf("error while obtaining the list %s", err.Error())
}
defer response.Body.Close()
iplist, err := NewFromReader(response.Body)
if err != nil {
t.Fatalf("Error while building the iplist %s", err.Error())
}
ip := "2.50.11.28"
if iplist.Contains(ip) == false {
t.Fatalf("List should contain the ip %s", ip)
}
}
func TestShouldCheckIfIpIsFoundInBlockListRange(t *testing.T) {
response, err := http.Get("https://raw.githubusercontent.com/firehol/blocklist-ipsets/master/firehol_level1.netset")
if err != nil {
t.Fatalf("error while obtaining the list %s", err.Error())
}
defer response.Body.Close()
iplist, err := NewFromReader(response.Body)
if err != nil {
t.Fatalf("Error while building the iplist %s", err.Error())
}
ip := "109.232.160.1"
if iplist.Contains(ip) == false {
t.Fatalf("List should contain the ip %s", ip)
}
}
func TestShouldCheckIfIpIsNotFoundInBlockList(t *testing.T) {
response, err := http.Get("https://raw.githubusercontent.com/firehol/blocklist-ipsets/master/firehol_level1.netset")
if err != nil {
t.Fatalf("error while obtaining the list %s", err.Error())
}
defer response.Body.Close()
iplist, err := NewFromReader(response.Body)
if err != nil {
t.Fatalf("Error while building the iplist %s", err.Error())
}
ip := "93.120.46.119"
if iplist.Contains(ip) == true {
t.Fatalf("List should not contain the ip %s", ip)
}
}