-
Notifications
You must be signed in to change notification settings - Fork 2
/
gomalshare_test.go
189 lines (174 loc) · 3.85 KB
/
gomalshare_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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package gomalshare
import (
"flag"
"fmt"
"io/ioutil"
"os"
"testing"
)
var apiKey string
var URL string
func init() {
flag.StringVar(&apiKey, "api", "", "API key MalShare")
flag.StringVar(&URL, "url", "", "URL MalShare")
flag.Parse()
if apiKey == "" {
fmt.Println("API key is required to run the tests agains MalShare")
os.Exit(1)
}
}
func TestNew(t *testing.T) {
conf, err := New(apiKey, URL)
if err != nil {
t.Fatal(err)
}
if conf == nil {
t.Error("connection to Malshare.com isn't established")
return
}
}
func TestGetStoredFileDetails(t *testing.T) {
conf, err := New(apiKey, URL) // Initiate new connection to API
if err != nil {
t.Fatal(err)
}
var testMd5 = "95bc3d64f49b03749427fcd6601fa8a7"
report, err := conf.GetStoredFileDetails(testMd5)
if err != nil {
t.Error("error requesting report: ", err)
return
}
if report.Md5 != testMd5 {
t.Error("requested MD5 doesn't match result: ", testMd5, " - ", report.Md5)
return
}
}
func TestGetSearchResult(t *testing.T) {
conf, err := New(apiKey, URL) // Initiate new connection to API
if err != nil {
t.Fatal(err)
}
var testMd5 = "95bc3d64f49b03749427fcd6601fa8a7"
report, err := conf.GetSearchResult(testMd5)
if err != nil {
t.Error("error requesting report: ", err)
return
}
for _, v := range *report {
if v.Md5 == testMd5 {
return
}
}
t.Error("requested MD5 doesn't match result: ", testMd5)
}
func TestGetLimitKey(t *testing.T) {
conf, err := New(apiKey, URL) // Initiate new connection to API
if err != nil {
t.Fatal(err)
}
report, err := conf.GetLimitKey()
if err != nil {
t.Error("error requesting report: ", err)
return
}
if report.Limit != "" {
return
}
t.Error("wrong response from API service")
}
func TestDownloadFileFromHash(t *testing.T) {
conf, err := New(apiKey, URL) // Initiate new connection to API
if err != nil {
t.Fatal(err)
}
var testMd5 = "95bc3d64f49b03749427fcd6601fa8a7"
body, err := conf.DownloadFileFromHash(testMd5)
if err != nil {
t.Error("error requesting report: ", err)
return
}
if body == nil {
t.Error("service return nil data")
return
}
}
func TestGetListOfHash24(t *testing.T) {
conf, err := New(apiKey, URL) // Initiate new connection to API
if err != nil {
t.Fatal(err)
}
report, err := conf.GetListOfHash24()
if err != nil {
t.Error("error requesting report: ", err)
return
}
if report == nil {
t.Error("service return nil data")
return
}
}
func TestGetListOfHash24Type(t *testing.T) {
conf, err := New(apiKey, URL) // Initiate new connection to API
if err != nil {
t.Fatal(err)
}
testType := "PE32"
report, err := conf.GetListOfHash24Type(testType)
if err != nil {
t.Error("error requesting report: ", err)
return
}
if report == nil {
t.Error("service return nil data")
return
}
}
func TestGetListOfSource24(t *testing.T) {
conf, err := New(apiKey, URL) // Initiate new connection to API
if err != nil {
t.Fatal(err)
}
report, err := conf.GetListOfSource24()
if err != nil {
t.Error("error requesting report: ", err)
return
}
if report == nil {
t.Error("service return nil data")
return
}
}
func TestGetListOfTypesFile24(t *testing.T) {
conf, err := New(apiKey, URL) // Initiate new connection to API
if err != nil {
t.Fatal(err)
}
report, err := conf.GetListOfTypesFile24()
if err != nil {
t.Error("error requesting report: ", err)
return
}
if report == nil {
t.Error("service return nil data")
return
}
}
func TestUploadFile(t *testing.T) {
conf, err := New(apiKey, URL) // Initiate new connection to API
if err != nil {
t.Fatal(err)
}
data := []byte("hello\ngo\n")
err = ioutil.WriteFile("test.txt", data, 0644)
if err != nil {
t.Error("can't write data test.txt", err)
}
err = conf.UploadFile("test.txt")
if err != nil {
t.Error("can't upload file", err)
}
err = os.Remove("test.txt")
if err != nil {
t.Error("can't delete file", err)
}
}