-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathmercury-json-validity-check.sh
executable file
·51 lines (44 loc) · 1.6 KB
/
mercury-json-validity-check.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
#!/bin/bash
#
# mercury-json-validity-check.sh
#
#
# usage: mercury-json-validity-check.sh <option1> <option2> ...
#
# to change the input files, export the shell variable INPUT before
# calling this script, for instance:
#
# $ export INPUT=pcap; ./mercury-json-validity-check --certs-json --dns-json
MERCURY=../src/mercury
if [[ -z "${INPUT}" ]]; then
INPUT=data/top-https.pcap
fi
option_array=("$@")
# test with no options
echo "testing mercury JSON output validity with no options"
$MERCURY -r $INPUT | jq . > /dev/null
# test with all permutations of options
for (( length=1; length <= "${#option_array[@]}"; ++length )); do
for (( start=0; start + length <= "${#option_array[@]}"; ++start )); do
options="${option_array[@]:start:length}"
echo "testing mercury JSON output validity with options $options"
$MERCURY -r $INPUT $options | jq . > /dev/null
if [ $? -ne 0 ]; then
echo "error: jq returned error code $?"
exit 255
fi
done
done
# test with all permutations of options, with --analysis and --resources
extra_options="--analysis --resources=data/resources-test.tgz"
for (( length=1; length <= "${#option_array[@]}"; ++length )); do
for (( start=0; start + length <= "${#option_array[@]}"; ++start )); do
options="${option_array[@]:start:length}"
echo "testing mercury JSON output validity with options $options $extra_options"
$MERCURY -r $INPUT $options $extra_options | jq . > /dev/null
if [ $? -ne 0 ]; then
echo "error: jq returned error code $?"
exit 255
fi
done
done