Files
wt d6409140f1
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 9s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 14s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Successful in 12s
fix tests
2025-09-02 09:48:46 +07:00

726 lines
22 KiB
Bash
Executable File

#!/bin/bash
RESET="\033[0m"
BWHITE="\033[1;37m"
BLUE="\033[0;34m"
GREEN="\033[0;32m"
RED="\033[0;31m"
YELLOW="\033[1;33m"
CYAN="\033[0;36m"
HOST="localhost"
PORT="8222"
./auth_service &> auth_service.log &
sleep 0.1
success=0
errors=0
# test POST /api/token
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/token${RESET} "
curl \
--silent \
-X POST \
-d '{"username":"tola","password":"e0c7bfa5b8e4ae0cecfc1f14093a71e05c27abd93a3850fc35f008c3baf866b4"}' \
$HOST:$PORT/api/token &> api_token_test.log
sleep 0.1
res=$(cat api_token_test.log)
if [[ "$res" == *"token"* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/token with wrong password
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/token with wrong password${RESET} "
curl \
--silent \
-X POST \
-d '{"username":"tola","password":"288"}' \
$HOST:$PORT/api/token &> api_token_wrong_password_test.log
sleep 0.1
res=$(cat api_token_wrong_password_test.log)
if [[ "$res" == *"{\"error\":\"wrong password\"}"* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/token with wrong username
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/token with wrong username${RESET} "
curl \
--silent \
-X POST \
-d '{"username":"toa","password":"2808"}' \
$HOST:$PORT/api/token &> api_token_wrong_username_test.log
sleep 0.1
res=$(cat api_token_wrong_username_test.log)
if [[ "$res" == *"{\"error\":\"couldn't find user\"}"* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/token without post data
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/token without post data${RESET} "
curl \
--silent \
-X POST \
-d '' \
$HOST:$PORT/api/token &> api_token_no_data_test.log
sleep 0.1
res=$(cat api_token_no_data_test.log)
if [[ "$res" == *"{\"error\":\"must have username and password\"}"* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/token with not valid json
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/token with not valid json${RESET} "
curl \
--silent \
-X POST \
-d '{{asdf}}}asdfasdfasdf""asdf' \
$HOST:$PORT/api/token &> api_token_not_valid_json_test.log
sleep 0.1
res=$(cat api_token_not_valid_json_test.log)
if [[ "$res" == *"error"* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/token/verify
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/token/verify${RESET} "
curl \
--silent \
-X POST \
-d $(cat api_token_test.log) \
$HOST:$PORT/api/token/verify &> api_token_verify_test.log
sleep 0.1
res=$(cat api_token_verify_test.log)
if [[ "$res" == *'{"valid":true}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/token/verify without post data
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/token/verify without post data${RESET} "
curl \
--silent \
-X POST \
-d '' \
$HOST:$PORT/api/token/verify &> api_token_verify_no_data_test.log
sleep 0.1
res=$(cat api_token_verify_no_data_test.log)
if [[ "$res" == *'{"valid":false}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/token/verify with wrong token
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/token/verify with wrong token${RESET} "
curl \
--silent \
-X POST \
-d '{"token":"asdf"}' \
$HOST:$PORT/api/token/verify &> api_token_verify_wrong_token_test.log
sleep 0.1
res=$(cat api_token_verify_wrong_token_test.log)
if [[ "$res" == *'{"valid":false}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/token/verify with wrong json
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/token/verify with wrong json${RESET} "
curl \
--silent \
-X POST \
-d 'asdf[apsdfqopwjf[9qfm93qq89n]]' \
$HOST:$PORT/api/token/verify &> api_token_verify_wrong_json_test.log
sleep 0.1
res=$(cat api_token_verify_wrong_json_test.log)
if [[ "$res" == *'{"valid":false}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/users
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/users${RESET} "
curl \
--silent \
-X POST \
-d $(cat api_token_test.log) \
$HOST:$PORT/api/users &> api_users_test.log
sleep 0.1
res=$(cat api_users_test.log)
if [[ "$res" == *'username'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/users with wrong token
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/users with wrong token${RESET} "
curl \
--silent \
-X POST \
-d '{"token":"asdf"}' \
$HOST:$PORT/api/users &> api_users_wrong_token_test.log
sleep 0.1
res=$(cat api_users_wrong_token_test.log)
if [[ "$res" == *'{"error":"invalid token"}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/users without post data
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/users without post data${RESET} "
curl \
--silent \
-X POST \
-d '' \
$HOST:$PORT/api/users &> api_users_no_data_test.log
sleep 0.1
res=$(cat api_users_no_data_test.log)
if [[ "$res" == *'{"error":"must have token"}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/users with wrong json
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/users with wrong json${RESET} "
curl \
--silent \
-X POST \
-d 'ahsdlfhjalighafina[a[][apofj OFFW[Efflja]]]' \
$HOST:$PORT/api/users &> api_users_wrong_json_test.log
sleep 0.1
res=$(cat api_users_wrong_json_test.log)
if [[ "$res" == *'error'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/users/user
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/users/user${RESET} "
curl \
--silent \
-X POST \
-d $(cat api_token_test.log) \
$HOST:$PORT/api/users/user &> api_users_user_test.log
sleep 0.1
res=$(cat api_users_user_test.log)
if [[ "$res" == *'username'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/users/user with wrong token
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/users/user with wrong token${RESET} "
curl \
--silent \
-X POST \
-d '{"token":"asdf"}' \
$HOST:$PORT/api/users/user &> api_users_user_wrong_token_test.log
sleep 0.1
res=$(cat api_users_user_wrong_token_test.log)
if [[ "$res" == *'{"error":"invalid token"}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/users/user without post data
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/users/user without post data${RESET} "
curl \
--silent \
-X POST \
-d '' \
$HOST:$PORT/api/users/user &> api_users_user_no_data_test.log
sleep 0.1
res=$(cat api_users_user_no_data_test.log)
if [[ "$res" == *'{"error":"must have token"}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/users/user with wrong json
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/users/user with wrong json${RESET} "
curl \
--silent \
-X POST \
-d 'alskodjfqjvoq3vn[q90\audv0q j89fvn 2vp]' \
$HOST:$PORT/api/users/user &> api_users_user_wrong_json_test.log
sleep 0.1
res=$(cat api_users_user_wrong_json_test.log)
if [[ "$res" == *'error'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/users/add
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/users/add${RESET} "
curl \
--silent \
-X POST \
-d '{
"username":"asdff",
"email":"asdf@asdff.com",
"password":"asdf",
"group":"users",
"is_superuser":false,
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IDEsInVzZXJuYW1lIjogInRvbGEiLCJlbWFpbCI6ICJtYWlsQGV4YW1wbGUuY29tIiwiZ3JvdXAiOiAicm9vdCIsImlzX3N1cGVydXNlciI6IHRydWV9.QGUnCWPmp5hWAtGFTGDMw2SugZqLsYfMboeFU4UQLXQ"
}' \
$HOST:$PORT/api/users/add &> api_users_add_test.log
sleep 0.1
res=$(cat api_users_add_test.log)
if [[ "$res" == *'username'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test DELETE /api/users
printf "==> ${BLUE}Testing${RED} DELETE${BWHITE} /api/users${RESET} "
reqdata=$(curl \
--silent \
-X POST \
-d '{"username":"asdff","password":"asdf"}' \
$HOST:$PORT/api/token)
sleep 0.1
curl \
--silent \
-X DELETE \
-d $reqdata \
$HOST:$PORT/api/users &> delete_api_users_test.log
sleep 0.1
res=$(cat delete_api_users_test.log)
if [[ "$res" == *'{"success": true}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
cat auth_service.log
fi
# test DELETE /api/users second delete
printf "==> ${BLUE}Testing${RED} DELETE${BWHITE} /api/users second delete${RESET} "
curl \
--silent \
-X DELETE \
-d $reqdata \
$HOST:$PORT/api/users &> delete_api_users_second_delete_test.log
sleep 0.1
res=$(cat delete_api_users_second_delete_test.log)
if [[ "$res" == *'{"success": false}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test DELETE /api/users with wrong json
printf "==> ${BLUE}Testing${RED} DELETE${BWHITE} /api/users with wrong json${RESET} "
curl \
--silent \
-X DELETE \
-d '$reqdata' \
$HOST:$PORT/api/users &> delete_api_users_wrong_json_test.log
sleep 0.1
res=$(cat delete_api_users_wrong_json_test.log)
if [[ "$res" == *'error'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test DELETE /api/users with wrong token
printf "==> ${BLUE}Testing${RED} DELETE${BWHITE} /api/users with wrong token${RESET} "
curl \
--silent \
-X DELETE \
-d '{"token":"asdf"}' \
$HOST:$PORT/api/users &> delete_api_users_wrong_token_test.log
sleep 0.1
res=$(cat delete_api_users_wrong_token_test.log)
if [[ "$res" == *'{"error":"invalid token"}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test DELETE /api/users without post data
printf "==> ${BLUE}Testing${RED} DELETE${BWHITE} /api/users without post data${RESET} "
curl \
--silent \
-X DELETE \
-d '' \
$HOST:$PORT/api/users &> delete_api_users_no_data_test.log
sleep 0.1
res=$(cat delete_api_users_no_data_test.log)
if [[ "$res" == *'{"error":"must have token"}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/users/password
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/users/password${RESET} "
reqtoken=$(cat api_token_test.log | sed -e "s/{//g" | sed -e "s/}//g")
curl \
--silent \
-X POST \
-d "{\"old_password\":\"e0c7bfa5b8e4ae0cecfc1f14093a71e05c27abd93a3850fc35f008c3baf866b4\",\"new_password\":\"1234\",$reqtoken}" \
$HOST:$PORT/api/users/password &> api_users_password_test.log
sleep 0.1
res=$(cat api_users_password_test.log)
if [[ "$res" == *'{"success": true}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/users/password without post data
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/users/password without post data${RESET} "
curl \
--silent \
-X POST \
-d "" \
$HOST:$PORT/api/users/password &> api_users_password_no_data_test.log
sleep 0.1
res=$(cat api_users_password_no_data_test.log)
if [[ "$res" == *'{"error":"must have token, old_password, new_password"}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/users/password with wrong json
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/users/password with wrong json${RESET} "
curl \
--silent \
-X POST \
-d "ijansd fu9q303ghq9" \
$HOST:$PORT/api/users/password &> api_users_password_wrong_json_test.log
sleep 0.1
res=$(cat api_users_password_wrong_json_test.log)
if [[ "$res" == *'error'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test PUT /api/users
printf "==> ${BLUE}Testing${YELLOW} PUT${BWHITE} /api/users${RESET} "
reqtoken=$(cat api_token_test.log | sed -e "s/{//g" | sed -e "s/}//g")
curl \
--silent \
-X PUT \
-d "{
\"username\":\"tola\",
\"email\":\"tola@tola.tola\",
\"group\":\"admin\",
\"is_superuser\":true,
$reqtoken}" \
$HOST:$PORT/api/users &> put_api_users_test.log
sleep 0.1
res=$(cat put_api_users_test.log)
if [[ "$res" == *'username'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test PUT /api/users without post data
printf "==> ${BLUE}Testing${YELLOW} PUT${BWHITE} /api/users without post data${RESET} "
curl \
--silent \
-X PUT \
-d "" \
$HOST:$PORT/api/users &> put_api_users_no_data_test.log
sleep 0.1
res=$(cat put_api_users_no_data_test.log)
if [[ "$res" == *'{"error":"must have token, new_user_data"}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test PUT /api/users with wrong json
printf "==> ${BLUE}Testing${YELLOW} PUT${BWHITE} /api/users with wrong json${RESET} "
curl \
--silent \
-X PUT \
-d "hiusdf 7qyt0 y qy40" \
$HOST:$PORT/api/users &> put_api_users_wrong_json_test.log
sleep 0.1
res=$(cat put_api_users_wrong_json_test.log)
if [[ "$res" == *'error'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/register
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/register${RESET} "
curl \
--silent \
-X POST \
-d '{
"username":"asdf",
"email":"asdf@asdf.com",
"password":"asdf",
"group":"users",
"is_superuser":false
}' \
$HOST:$PORT/api/register &> api_register_test.log
sleep 0.1
res=$(cat api_register_test.log)
if [[ "$res" == *'username'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/register without username
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/register without username${RESET} "
curl \
--silent \
-X POST \
-d '{
"email":"asdf@asdf.com",
"password":"asdf",
"group":"users",
"is_superuser":false
}' \
$HOST:$PORT/api/register &> api_register_without_username_test.log
sleep 0.1
res=$(cat api_register_without_username_test.log)
if [[ "$res" == *'{"error":"must have <username>, <password>, <email>, <group, optional>, <is_superuser, optional>"}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/register without email
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/register without email${RESET} "
curl \
--silent \
-X POST \
-d '{
"username":"asdf",
"password":"asdf",
"group":"users",
"is_superuser":false
}' \
$HOST:$PORT/api/register &> api_register_without_email_test.log
sleep 0.1
res=$(cat api_register_without_email_test.log)
if [[ "$res" == *'{"error":"must have <username>, <password>, <email>, <group, optional>, <is_superuser, optional>"}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/register without password
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/register without password${RESET} "
curl \
--silent \
-X POST \
-d '{
"username":"asdf",
"email":"asdf@asdf.com",
"group":"users",
"is_superuser":false
}' \
$HOST:$PORT/api/register &> api_register_without_password_test.log
sleep 0.1
res=$(cat api_register_without_password_test.log)
if [[ "$res" == *'{"error":"must have <username>, <password>, <email>, <group, optional>, <is_superuser, optional>"}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/register without group
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/register without group${RESET} "
curl \
--silent \
-X POST \
-d '{
"username":"qwer",
"email":"qwer@qwer.com",
"password":"qwer",
"is_superuser":false
}' \
$HOST:$PORT/api/register &> api_register_without_group_test.log
sleep 0.1
res=$(cat api_register_without_group_test.log)
if [[ "$res" == *'username'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/register without is_superuser
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/register without is_superuser${RESET} "
curl \
--silent \
-X POST \
-d '{
"username":"zxcv",
"email":"zxcv@zxcv.com",
"password":"zxcv",
"group":"users"
}' \
$HOST:$PORT/api/register &> api_register_without_is_superuser_test.log
sleep 0.1
res=$(cat api_register_without_is_superuser_test.log)
if [[ "$res" == *'username'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/register second register
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/register second register${RESET} "
curl \
--silent \
-X POST \
-d '{
"username":"zxcv",
"email":"zxcv@zxcv.com",
"password":"zxcv",
"group":"users"
}' \
$HOST:$PORT/api/register &> api_register_second_register_test.log
sleep 0.1
res=$(cat api_register_second_register_test.log)
if [[ "$res" == *'{"error":"failed to create user"}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/register with wrong json
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/register with wrong json${RESET} "
curl \
--silent \
-X POST \
-d 'najsnvpnvq234890vn9qq234vqui3v' \
$HOST:$PORT/api/register &> api_register_wrong_json_test.log
sleep 0.1
res=$(cat api_register_wrong_json_test.log)
if [[ "$res" == *'error'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
# test POST /api/register without post data
printf "==> ${BLUE}Testing${CYAN} POST${BWHITE} /api/register without post data${RESET} "
curl \
--silent \
-X POST \
-d '' \
$HOST:$PORT/api/register &> api_register_no_data_test.log
sleep 0.1
res=$(cat api_register_no_data_test.log)
if [[ "$res" == *'{"error":"must have <username>, <password>, <email>, <group, optional>, <is_superuser, optional>"}'* ]]; then
printf "[$GREEN OK $RESET]\n"
success=$(($success+1))
else
printf "[$RED ERR $RESET]\n==> ${BLUE}Response: $RESET$(echo $res)\n"
errors=$(($errors+1))
fi
killall auth_service
printf "==> ${GREEN}Success: ${RESET}${success}\n==>${RED} Errors: ${RESET}${errors}\n"
if [ ! $errors -eq 0 ]; then
exit 1
fi