aboutsummaryrefslogtreecommitdiffstats
path: root/checker/test.sh
blob: 9b2d08ead3c27cc87df141c4484a1ea26b74e820 (plain) (blame)
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
#!/bin/bash

ipstr="$1"

SCRIPTPATH="$(dirname $(readlink -f "$0"))"
cd "$SCRIPTPATH"
export REVHASH_PATH="$SCRIPTPATH/src/revhash/revhash"

nop() { :; }

splitmsg() {
	python3 -c "
import json,sys

try:
	instr = sys.stdin.read().strip()
	jres = json.loads(instr)
	print(jres['result'])
	print(jres['message'])
except:
	print('INVALID')
	print('INVALID')
	print('FAIL:', instr, file=sys.stderr)
	" || nop
}

try() {
	cmd="$1"
	tmpfile="/tmp/checker-log-$BASHPID"
	[ -e "$tmpfile" ] && rm "$tmpfile"
	if [ $# -lt 2 ]; then
		variant=0
	else
		variant=$2
	fi
	taskid=$$
	if [ ! -z "$REMOTE" ]; then
		python3 enoreq.py -j True -A http://localhost:9091 -a $REMOTE \
			--flag ENOTESTFLAG123= --flag_regex 'ENO.*=' -i $taskid \
			-v "$variant" -x 4000 ${@:3} "$cmd" > "$tmpfile" 
		res="$(cat $tmpfile | splitmsg | head -n1)"
	else
		python3 src/checker.py -j run -v "$variant" -x 4000 \
			--flag ENOTESTFLAG123= --flag_regex 'ENO.*=' -i $taskid \
			${@:3} "$cmd" > "$tmpfile"
		res="$(cat $tmpfile | grep -a Result: | tail -n1 | grep -a -o OK)"
	fi
	if [ "$res" != "OK" ]; then
		newfile="fails/err-$(ls fails | wc -l)"
		(
			echo "METHOD $@"
			cat "$tmpfile"
			if [ ! -z "$REMOTE" -a -e "$ENOLOGMESSAGE_PARSER" ]; then
				docker-compose logs --tail=400 | grep '"taskId": '$taskid | $ENOLOGMESSAGE_PARSER
			fi
		) > "$newfile"
		echo -ne "Executing $cmd with variant $variant.. $res ($newfile)\n"
	else
		echo -ne "Executing $cmd with variant $variant.. $res\n"
	fi
}

try-all() {
	try putflag 0
	try getflag 0

	try putflag 1
	try getflag 1

	try putnoise 0
	try getnoise 0

	try putflag 1
	try getflag 1

	try havoc 0
	try havoc 1
	try havoc 2
	try havoc 3

	try exploit 0
	try exploit 1
}

if [ $# -ge 2 ]; then
	try $@
elif [ "$1" == "test-exploits" ]; then
	try exploit 0
	try exploit 1
elif [ "$1" == "stress-test" ]; then
	mkdir -p fails
	while [ 1 ]; do
		try-all &
		sleep 2
	done
else
	try-all
fi

exit 0