decent start to bash tester

This commit is contained in:
Eric LAZO
2022-08-13 22:38:31 +02:00
parent ebd0fda52c
commit dda32c759a
4 changed files with 133 additions and 32 deletions

2
.gitignore vendored
View File

@@ -22,3 +22,5 @@ webserv
*.log *.log
large.jpg large.jpg
webserv_tester
webserv_tester2

View File

@@ -131,7 +131,8 @@ void Webserv::_autoindex(Client *client, const std::string &path)
if (strcmp(".", ent->d_name) == 0) if (strcmp(".", ent->d_name) == 0)
continue ; continue ;
dir_list.append("<a href=\""); dir_list.append("<a href=\"");
dir_list.append(client->get_rq_target()); // dir_list.append(client->get_rq_target());
dir_list.append(client->get_rq_abs_path());
if (dir_list[dir_list.size() - 1] != '/') if (dir_list[dir_list.size() - 1] != '/')
dir_list.push_back('/'); dir_list.push_back('/');
dir_list.append(ent->d_name); dir_list.append(ent->d_name);

View File

@@ -1,41 +1,131 @@
#! /bin/bash #! /bin/bash
# no idea what we're doing here... # you need to put absolutely everything in ""
PORT=80 #port="80"
METHOD="GET" port="4040"
PATH="/" path="/"
HOST="duckduckgo.com" #host="duckduckgo.com"
HOST_FULL="$HOST $PORT" host="localhost"
START="open $HOST_FULL" ##########
# Colors
##########
L1="$METHOD $PATH HTTP/1.1"
run() _GREY='\033[30m'
_RED='\033[0;31m'
_GREEN='\033[32m'
_YELLOW='\033[33m'
_BLUE='\033[34m'
_PURPLE='\033[35m'
_CYAN='\033[36m'
_WHITE='\033[37m'
_END='\033[0m'
methods=(GET POST DELETE GUMBALL)
#ports=($port ($port + 1))
https=(HTTP/1.1 HTTP/1.0)
run_telnet()
{ {
# echo "this is a test" echo "open $host $port"
# $TEL_START
# spaw telnet localhost $PORT
echo "$START"
# telnet $HOST_FULL
# echo
sleep 1 sleep 1
# echo "$L1" echo "$l1"
# echo "GET / HTTP/1.1" echo "$header"
# echo "Host: duckduckgo.com" # echo
# echo "Host: $HOST" ## echo $body
# echo
# echo
echo echo
echo echo
sleep 1
# ret = $(arg | telnet)
}
run_a_test()
{
echo "----- $test_name -----"
echo
# run_telnet
# echo ${pid}
run_telnet | telnet
# run_telnet
echo
echo "----- end of test -----"
}
run_all()
{
# open_a_connection
# run_a_test | telnet
test_to_run="$valid_get"
test_name=$valid_get_name
# l1="$test_to_run"
header="Host: $host"
body=
#while something i change headers
for i in "${methods[@]}"
do
test_name="Test Method $i"
l1="$i $path ${https[0]}"
expected_result="something"
run_a_test
echo -e "${_RED}$expected_result${_END}"
echo
done
# consider running several tests in a single telnet connection
} }
# open telnet localhost 4040
# GET / HTTP/1.1
# Host: localhost
# more header stuff
#
# maybe a body
run_all
#echo $START
run

View File

@@ -1,8 +1,16 @@
#! /usr/bin/expect #! /bin/bash
set timeout 20
set Host "localhost 80"
spawn telnet $Host
echo "open duckduckgo.com 80"
sleep 1
echo "GET / HTTP/1.1"
echo "Host: duckduckgo.com"
echo
echo
sleep 2
#(
#echo open duckduckgo.com 80
#echo "GET / HTTP/1.1"
#echo "Host: duckduckgo.com"
#echo "exit"
#) | telnet