-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
prod-test.sh
34 lines (29 loc) · 1.13 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
#!/bin/sh
assert ()
{
text=$1
string=$2
if [[ $text == *"$string"* ]];
then
echo "'$string': passed"
else
echo "'$string' not found in text:"
echo "$text"
exit 99
fi
}
username="$RANDOM"
password="$RANDOM"
wrongpassword="wrongpw"
homepage () { curl -s https://mlha11y.tech; }
register () { curl -H "Content-Type: application/json" -d "{\"username\":\"$1\",\"password\":\"$2\"}" -s -X POST https://mlha11y.tech/api/register; }
login () { curl -H "Content-Type: application/json" -d "{\"username\":\"$1\",\"password\":\"$2\"}" -s -X POST https://mlha11y.tech/api/login; }
assert "$(homepage)" "A11Y"
assert "$(register "" "$password")" "Username is required."
assert "$(register "$username" "")" "Password is required."
assert "$(register "$username" "$password")" "User ${username} created successfully"
assert "$(register "$username" "$password")" "User ${username} is already registered."
assert "$(login "" "$password")" "Incorrect username."
assert "$(login "$username" "")" "Incorrect password."
assert "$(login "$username" "$wrongpassword")" "Incorrect password."
assert "$(login "$username" "$password")" "Login Successful"