This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
blacklist_test.go
90 lines (78 loc) · 2.31 KB
/
blacklist_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
package blacklist
import (
"os"
"testing"
"github.com/activecm/mgosec"
"github.com/activecm/rita-bl/database"
"github.com/activecm/rita-bl/list"
"github.com/activecm/rita-bl/sources/mock"
)
//nolint: golint
var __blacklistTestHandle *Blacklist
func TestMain(m *testing.M) {
db, err := database.NewMongoDB("localhost:27017", mgosec.None, "rita-blacklist-TEST")
if err != nil {
os.Exit(-1)
}
__blacklistTestHandle = NewBlacklist(db, func(err error) { panic(err) })
os.Exit(m.Run())
}
func TestDummyList(t *testing.T) {
t.Run("Update Indeterminate", UpdateDummyList)
t.Run("Delete", DeleteDummyList)
t.Run("Empty IP Search", EmptyIPSearch)
t.Run("Empty Hostname Search", EmptyHostnameSearch)
t.Run("Update From Scratch", UpdateDummyList)
t.Run("Update Existing", UpdateDummyList)
t.Run("IP Search", DummyIPSearch)
t.Run("Hostname Search", DummyHostnameSearch)
t.Run("Delete", DeleteDummyList)
}
func UpdateDummyList(t *testing.T) {
__blacklistTestHandle.SetLists(mock.NewDummyList())
__blacklistTestHandle.Update()
}
func DeleteDummyList(t *testing.T) {
__blacklistTestHandle.SetLists()
__blacklistTestHandle.Update()
}
func EmptyIPSearch(t *testing.T) {
results := __blacklistTestHandle.CheckEntries(list.BlacklistedIPType, "50.0.0.0")
if len(results["50.0.0.0"]) != 0 {
t.Fail()
}
}
func EmptyHostnameSearch(t *testing.T) {
results := __blacklistTestHandle.CheckEntries(list.BlacklistedHostnameType, "booking.com")
if len(results["booking.com"]) != 0 {
t.Fail()
}
}
func DummyIPSearch(t *testing.T) {
results := __blacklistTestHandle.CheckEntries(list.BlacklistedIPType, "50.0.0.0")
if len(results["50.0.0.0"]) != 1 {
t.Fail()
}
}
func DummyHostnameSearch(t *testing.T) {
results := __blacklistTestHandle.CheckEntries(list.BlacklistedHostnameType, "booking.com")
if len(results["booking.com"]) != 1 {
t.Fail()
}
}
/* NOTE: This test only runs if you supply it an api key and a db path
func TestGoogleRPC(t *testing.T) {
google, err := rpc.NewGoogleSafeBrowsingURLsRPC("API_KEY", "DB_PATH", os.Stdout)
if err != nil {
panic(err)
}
url := "http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/MALWARE/URL/"
__blacklistTestHandle.SetRPCs(google)
results := __blacklistTestHandle.CheckEntries(list.BlacklistedURLType, url)
if len(results) < 1 {
t.Fail()
}
if len(results[url]) < 1 {
t.Fail()
}
}*/