-
Notifications
You must be signed in to change notification settings - Fork 6
/
test-all.sh
executable file
·301 lines (266 loc) · 10.4 KB
/
test-all.sh
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/bin/bash
echo "Running go generate..."
go generate
#echo "Running go fmt..."
#gofmt -s -w ./..
echo "Running unit tests..."
go test ./... || exit
echo "Building application..."
go build -ldflags="-s -w" || exit
GREEN='\033[1;32m'
RED='\033[0;31m'
NC='\033[0m'
if ./hashit --not-a-real-option > /dev/null ; then
echo -e "${RED}================================================="
echo -e "FAILED Invalid option should produce error code "
echo -e "======================================================="
exit
else
echo -e "${GREEN}PASSED invalid option test"
fi
if ./hashit > /dev/null ; then
echo -e "${GREEN}PASSED no directory specified test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should run correctly with no directory specified"
echo -e "======================================================="
exit
fi
if ./hashit * > /dev/null ; then
echo -e "${GREEN}PASSED all files test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should run correctly with all files specified"
echo -e "======================================================="
exit
fi
if ./hashit --debug --trace --verbose -f text --hash md5 --no-stream --stream-size 10 -r main.go > /dev/null ; then
echo -e "${GREEN}PASSED multiple options test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should run correctly with multiple options"
echo -e "======================================================="
exit
fi
if ./hashit processor > /dev/null ; then
echo -e "${GREEN}PASSED directory specified test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should run correctly with directory specified"
echo -e "======================================================="
exit
fi
if ./hashit main.go -c md5 | grep -q -i 'md5'; then
echo -e "${GREEN}PASSED short hash test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to work with short hash"
echo -e "======================================================="
exit
fi
for i in 'md4' 'md5' 'sha1' 'sha256' 'sha512'
do
if ./hashit main.go --hash $i | grep -q -i $i; then
echo -e "${GREEN}PASSED hash test $i"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to work with hash $i"
echo -e "======================================================="
exit
fi
done
if ./hashit main.go --hash blake2b256 | grep -q -i 'blake2b-256'; then
echo -e "${GREEN}PASSED hash test blake2b256"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to work with hash blake2b256"
echo -e "======================================================="
exit
fi
if ./hashit main.go --hash blake2b512 | grep -q -i 'blake2b-512'; then
echo -e "${GREEN}PASSED hash test blake2b512"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to work with hash blake2b512"
echo -e "======================================================="
exit
fi
if ./hashit main.go --hash sha3224 | grep -q -i 'sha3-224'; then
echo -e "${GREEN}PASSED hash test sha3224"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to work with hash sha3224"
echo -e "======================================================="
exit
fi
if ./hashit main.go --hash sha3256 | grep -q -i 'sha3-256'; then
echo -e "${GREEN}PASSED hash test sha3256"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to work with hash sha3256"
echo -e "======================================================="
exit
fi
if ./hashit main.go --hash sha3384 | grep -q -i 'sha3-384'; then
echo -e "${GREEN}PASSED hash test sha3384"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to work with hash sha3384"
echo -e "======================================================="
exit
fi
if ./hashit main.go --hash sha3512 | grep -q -i 'sha3-512'; then
echo -e "${GREEN}PASSED hash test sha3512"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to work with hash sha3512"
echo -e "======================================================="
exit
fi
if ./hashit main.go --hashes | grep -q -i 'md5'; then
echo -e "${GREEN}PASSED hashes test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to display hashes"
echo -e "======================================================="
exit
fi
if echo "hello" | ./hashit --hash md5 | grep -q -i 'b1946ac92492d2347c6235b4d2611184'; then
echo -e "${GREEN}PASSED stdin md5 test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to process md5 stdin"
echo -e "======================================================="
exit
fi
if echo "hello" | ./hashit --hash sha1 | grep -q -i 'f572d396fae9206628714fb2ce00f72e94f2258f'; then
echo -e "${GREEN}PASSED stdin sha1 test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to process sha1 stdin"
echo -e "======================================================="
exit
fi
if echo "hello" | ./hashit --hash sha256 | grep -q -i '5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03'; then
echo -e "${GREEN}PASSED stdin sha256 test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to process sha256 stdin"
echo -e "======================================================="
exit
fi
a=$(./hashit --no-stream * | sort | md5sum)
b=$(./hashit * | sort | md5sum)
if [ "$a" == "$b" ]; then
echo -e "${GREEN}PASSED stream output test"
else
echo -e "${RED}======================================================="
echo -e "FAILED stream output test"
echo -e "================================================="
exit
fi
a=$(./hashit --format hashdeep main.go | grep ',main.go')
b=$(hashdeep -l main.go | grep ',main.go')
if [ "$a" == "$b" ]; then
echo -e "${GREEN}PASSED hashdeep hash test"
else
echo -e "${RED}======================================================="
echo -e "FAILED hashdeep hash test"
echo -e "================================================="
exit
fi
a=$(./hashit --format sum --hash md5 main.go)
b=$(md5sum main.go)
if [ "$a" == "$b" ]; then
echo -e "${GREEN}PASSED sum md5 format test"
else
echo -e "${RED}======================================================="
echo -e "FAILED sum md5 format test"
echo -e "================================================="
exit
fi
a=$(./hashit --format sum --hash sha1 main.go)
b=$(sha1sum main.go)
if [ "$a" == "$b" ]; then
echo -e "${GREEN}PASSED sum sha1 format test"
else
echo -e "${RED}======================================================="
echo -e "FAILED sum sha1 format test"
echo -e "================================================="
exit
fi
a=$(./hashit --format sum --hash sha256 main.go)
b=$(sha256sum main.go)
if [ "$a" == "$b" ]; then
echo -e "${GREEN}PASSED sum sha256 format test"
else
echo -e "${RED}======================================================="
echo -e "FAILED sum sha256 format test"
echo -e "================================================="
exit
fi
a=$(./hashit --format sum --hash sha512 main.go)
b=$(sha512sum main.go)
if [ "$a" == "$b" ]; then
echo -e "${GREEN}PASSED sum sha512 format test"
else
echo -e "${RED}======================================================="
echo -e "FAILED sum sha512 format test"
echo -e "================================================="
exit
fi
for i in '' '--stream-size 0'
do
if ./hashit $i LICENSE | grep -q -i '227f999ca03b135a1b4d69bde84afb16'; then
echo -e "${GREEN}PASSED stream $i hash test"
else
echo -e "${RED}======================================================="
echo -e "FAILED $i test"
echo -e "======================================================="
exit
fi
done
a=$(./hashit --format sum --hash all ./LICENSE)
b=$(./hashit --format sum --hash all --stream-size 1 ./LICENSE)
if [ "$a" == "$b" ]; then
echo -e "${GREEN}PASSED small scanner test"
else
echo -e "${RED}======================================================="
echo -e "FAILED small scanner test"
echo -e "================================================="
exit
fi
if ./hashit --format hashdeep processor > audit.txt && hashdeep -l -r -a -k audit.txt processor | grep -q -i 'Audit passed'; then
echo -e "${GREEN}PASSED relative hashdeep audit test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to create relative hashdeep audit"
echo -e "======================================================="
exit
fi
if ./hashit --format hashdeep vendor > audit.txt && hashdeep -l -r -a -k audit.txt vendor | grep -q -i 'Audit passed'; then
echo -e "${GREEN}PASSED large relative hashdeep audit test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to create large relative hashdeep audit"
echo -e "======================================================="
exit
fi
mkdir -p /tmp/hashit/
echo "hello" > /tmp/hashit/file
if ./hashit --format hashdeep /tmp/hashit/ > audit.txt && hashdeep -r -a -k audit.txt /tmp/hashit/ | grep -q -i 'Audit passed'; then
echo -e "${GREEN}PASSED full hashdeep audit test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to create full hashdeep audit"
echo -e "======================================================="
exit
fi
echo -e "${NC}Cleaning up..."
rm ./hashit
rm ./audit.txt
rm /tmp/hashit/file
rmdir /tmp/hashit/
echo -e "${GREEN}================================================="
echo -e "ALL TESTS PASSED"
echo -e "================================================="