-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprod-test.sh
executable file
·52 lines (43 loc) · 1.61 KB
/
prod-test.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
sleep 5
EXITSTATUS=0
# website data
URL="https://blobber.tech"
PAGES="/ /dashboard /login /register /faq /about /chat"
METHODS="GET POST"
# Testing endpoints with request methods
echo ${cyan}Testing endpoints with request methods${reset_color}
for PAGE in $PAGES; do
for METHOD in $METHODS; do
GETVAR=$(curl -LI $URL$PAGE -o /dev/null -w '%{http_code}\n' -s -X $METHOD)
STATCAT=${GETVAR:0:1}
if [[ $STATCAT == 2 ]]; then
echo $PAGE ${white}$METHOD${reset_color} $GETVAR ${green}'SUCCESS'${reset_color}
elif [[ $GETVAR == 400 ]]; then
echo $PAGE ${white}$METHOD${reset_color} $GETVAR ${purple}"Bad Request"${reset_color}
elif [[ $GETVAR == 405 ]]; then
echo $PAGE ${white}$METHOD${reset_color} $GETVAR ${yellow}'METHOD NOT ALLOWED'${reset_color}
elif [[ $GETVAR == 301 ]]; then
echo $PAGE ${white}$METHOD${reset_color} $GETVAR ${purple}"Re-direct"${reset_color}
else
echo $PAGE ${white}$METHOD${reset_color} $GETVAR ${red}'ERROR'${reset_color}
EXITSTATUS=1
fi
done
done
# Function to post endpoints
testing_endpoint () {
GETVAR=$1
if [[ $GETVAR == $2 ]]; then
echo $GETVAR ${green}'SUCCESS'${reset_color}
else
echo $GETVAR ${red}'ERROR'${reset_color}
EXITSTATUS=2
fi
}
echo ${cyan}Posting to /login endpoint with register user and empty password${reset_color}
testing_endpoint "$(curl -sX POST -d "username=test" -o /dev/null -w '%{http_code}\n' $URL'/login')" "400"
echo Posting to /register endpoint with usr test, pw test pw test
testing_endpoint "$(curl -sX POST -d "username=test&password=test&password2=test" -o /dev/null -w '%{http_code}\n' $URL'/register')" "400"
echo 'EXIT STATUS = '$EXITSTATUS
exit $EXITSTATUS