better telnet tester
This commit is contained in:
125
telnet_test.sh
125
telnet_test.sh
@@ -2,11 +2,6 @@
|
||||
|
||||
# you need to put absolutely everything in ""
|
||||
|
||||
#port="80"
|
||||
port="4040"
|
||||
path="/"
|
||||
#host="duckduckgo.com"
|
||||
host="localhost"
|
||||
|
||||
##########
|
||||
# Colors
|
||||
@@ -24,30 +19,30 @@ _WHITE='\033[37m'
|
||||
_END='\033[0m'
|
||||
|
||||
|
||||
test_file=$1
|
||||
source $test_file
|
||||
|
||||
connect_to_telnet="open $host $port"
|
||||
|
||||
|
||||
|
||||
|
||||
methods=(GET POST DELETE GUMBALL)
|
||||
|
||||
#ports=($port ($port + 1))
|
||||
|
||||
https=(HTTP/1.1 HTTP/1.0)
|
||||
|
||||
|
||||
|
||||
run_telnet()
|
||||
start_telnet()
|
||||
{
|
||||
echo "open $host $port"
|
||||
sleep 1
|
||||
echo "$l1"
|
||||
echo "$header"
|
||||
}
|
||||
|
||||
run_telnet()
|
||||
{
|
||||
echo "$connect_to_telnet"
|
||||
sleep 1
|
||||
echo -e "$request"
|
||||
# echo "$l1"
|
||||
# echo "$header"
|
||||
# echo
|
||||
## echo $body
|
||||
# echo $body
|
||||
# echo
|
||||
# echo
|
||||
|
||||
echo
|
||||
echo
|
||||
sleep 1
|
||||
|
||||
@@ -55,69 +50,83 @@ run_telnet()
|
||||
|
||||
}
|
||||
|
||||
run()
|
||||
{
|
||||
echo "$connect_to_telnet"
|
||||
sleep 1
|
||||
|
||||
run_this_test
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
run_a_test()
|
||||
{
|
||||
{
|
||||
echo "----- $test_name -----"
|
||||
echo
|
||||
echo -e "$_RED$request$_END"
|
||||
} &> test.log
|
||||
|
||||
# run_telnet
|
||||
# echo ${pid}
|
||||
# echo -e "$_END---"
|
||||
|
||||
run_telnet | telnet
|
||||
echo -e "$request" | telnet
|
||||
# run_telnet | telnet
|
||||
# run_telnet
|
||||
|
||||
echo
|
||||
echo "----- end of test -----"
|
||||
# echo
|
||||
# echo "----- end of test -----"
|
||||
}
|
||||
|
||||
run_all()
|
||||
{
|
||||
# open_a_connection
|
||||
echo
|
||||
|
||||
# run_a_test | telnet
|
||||
# ./webserv $config_file 2>&1 > webserv.log &
|
||||
|
||||
|
||||
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
|
||||
|
||||
# do a thing where you pass an array as parameter and based on that it
|
||||
# decides which test to run and then you can loop through the arrays you pass
|
||||
|
||||
|
||||
# consider running several tests in a single telnet connection
|
||||
|
||||
# for i in "${methods[@]}"
|
||||
# do
|
||||
# expected_result="something"
|
||||
# run_a_test
|
||||
# echo -e "${_GREEN}$expected_result${_END}"
|
||||
## echo
|
||||
# done
|
||||
|
||||
}
|
||||
|
||||
|
||||
# open telnet localhost 4040
|
||||
# GET / HTTP/1.1
|
||||
# Host: localhost
|
||||
# more header stuff
|
||||
#
|
||||
# maybe a body
|
||||
#######
|
||||
# This is where stuff is launched
|
||||
#######
|
||||
|
||||
rm -rf test.log
|
||||
rm -rf telnet.out
|
||||
|
||||
#./webserv $config_file 2>&1 > webserv.log & run_all
|
||||
#./webserv $config_file 2>&1 > webserv.log &
|
||||
#./webserv $config_file &> /dev/null &
|
||||
./webserv $config_file &> webserv.log &
|
||||
#./webserv $config_file 1>&1 > webserv.log &
|
||||
|
||||
|
||||
#run_all
|
||||
#run_this_test
|
||||
|
||||
echo -e "${_GREEN}Running Telnet Test on '$test_name'${_END}"
|
||||
|
||||
run_all
|
||||
|
||||
|
||||
sleep 1
|
||||
|
||||
run | telnet >> telnet.out
|
||||
#run | telnet
|
||||
|
||||
pkill webserv
|
||||
|
||||
|
||||
|
||||
|
||||
11
test_header.txt
Normal file
11
test_header.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
config_file=...
|
||||
port=...
|
||||
|
||||
# Host: ...
|
||||
|
||||
|
||||
|
||||
|
||||
# the correct response
|
||||
...
|
||||
61
test_template.sh
Normal file
61
test_template.sh
Normal file
@@ -0,0 +1,61 @@
|
||||
#! /bin/bash
|
||||
|
||||
test_name="Template test all good"
|
||||
|
||||
config_file="default.config"
|
||||
port=4040
|
||||
host="localhost"
|
||||
|
||||
paths=("/") # you can add many
|
||||
methods=("GET" "POST" "DELETE")
|
||||
#methods=("GET")
|
||||
httpz=("HTTP/1.1")
|
||||
|
||||
|
||||
|
||||
|
||||
# the parts we will send to webserv
|
||||
|
||||
|
||||
# let main.sh handle the l1
|
||||
|
||||
l1="${methods[0]} ${paths[0]} ${https[0]}"
|
||||
|
||||
header="Host: $host"
|
||||
body=
|
||||
|
||||
|
||||
run_this_test()
|
||||
{
|
||||
|
||||
for i in "${methods[@]}"
|
||||
do
|
||||
l1="$i ${paths[0]} ${httpz[0]}"
|
||||
request="$l1\n$header\n$body\n"
|
||||
{
|
||||
echo "----- $test_name -----"
|
||||
echo -e "$_RED$request$_END"
|
||||
} &>> telnet.out
|
||||
# } &>> test.log
|
||||
# } 2>>&1
|
||||
# } &>> /dev/stdout
|
||||
echo -e "$request"
|
||||
sleep 1
|
||||
# {
|
||||
# echo -e "\n------\n"
|
||||
# } > /dev/stdout
|
||||
# echo -e "\n\n\n------\n\n\n" >> telnet.out
|
||||
# echo -e "\n\n\n------\n\n\n" &> /dev/stdout
|
||||
echo -e "\n\n" >> telnet.out
|
||||
# echo -e "\n\n------\n\n" >> telnet.out
|
||||
# echo -e "\n------\n" > /dev/stdout
|
||||
# run_a_test
|
||||
# echo
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
# expected result...
|
||||
|
||||
Reference in New Issue
Block a user