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 ""
|
# you need to put absolutely everything in ""
|
||||||
|
|
||||||
#port="80"
|
|
||||||
port="4040"
|
|
||||||
path="/"
|
|
||||||
#host="duckduckgo.com"
|
|
||||||
host="localhost"
|
|
||||||
|
|
||||||
##########
|
##########
|
||||||
# Colors
|
# Colors
|
||||||
@@ -24,30 +19,30 @@ _WHITE='\033[37m'
|
|||||||
_END='\033[0m'
|
_END='\033[0m'
|
||||||
|
|
||||||
|
|
||||||
|
test_file=$1
|
||||||
|
source $test_file
|
||||||
|
|
||||||
|
connect_to_telnet="open $host $port"
|
||||||
|
|
||||||
|
|
||||||
|
start_telnet()
|
||||||
|
|
||||||
methods=(GET POST DELETE GUMBALL)
|
|
||||||
|
|
||||||
#ports=($port ($port + 1))
|
|
||||||
|
|
||||||
https=(HTTP/1.1 HTTP/1.0)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
run_telnet()
|
|
||||||
{
|
{
|
||||||
echo "open $host $port"
|
echo "open $host $port"
|
||||||
sleep 1
|
sleep 1
|
||||||
echo "$l1"
|
}
|
||||||
echo "$header"
|
|
||||||
|
run_telnet()
|
||||||
|
{
|
||||||
|
echo "$connect_to_telnet"
|
||||||
|
sleep 1
|
||||||
|
echo -e "$request"
|
||||||
|
# echo "$l1"
|
||||||
|
# echo "$header"
|
||||||
# echo
|
# echo
|
||||||
## echo $body
|
# echo $body
|
||||||
# echo
|
# echo
|
||||||
# echo
|
# echo
|
||||||
|
|
||||||
echo
|
|
||||||
echo
|
echo
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
@@ -55,69 +50,83 @@ run_telnet()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run()
|
||||||
|
{
|
||||||
|
echo "$connect_to_telnet"
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
run_this_test
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
run_a_test()
|
run_a_test()
|
||||||
{
|
{
|
||||||
|
{
|
||||||
echo "----- $test_name -----"
|
echo "----- $test_name -----"
|
||||||
echo
|
echo -e "$_RED$request$_END"
|
||||||
|
} &> test.log
|
||||||
|
|
||||||
# run_telnet
|
# run_telnet
|
||||||
# echo ${pid}
|
# echo ${pid}
|
||||||
|
# echo -e "$_END---"
|
||||||
|
|
||||||
run_telnet | telnet
|
echo -e "$request" | telnet
|
||||||
|
# run_telnet | telnet
|
||||||
# run_telnet
|
# run_telnet
|
||||||
|
|
||||||
echo
|
# echo
|
||||||
echo "----- end of test -----"
|
# echo "----- end of test -----"
|
||||||
}
|
}
|
||||||
|
|
||||||
run_all()
|
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
|
#while something i change headers
|
||||||
|
|
||||||
for i in "${methods[@]}"
|
# for i in "${methods[@]}"
|
||||||
do
|
# do
|
||||||
test_name="Test Method $i"
|
# expected_result="something"
|
||||||
l1="$i $path ${https[0]}"
|
# run_a_test
|
||||||
expected_result="something"
|
# echo -e "${_GREEN}$expected_result${_END}"
|
||||||
run_a_test
|
## echo
|
||||||
echo -e "${_RED}$expected_result${_END}"
|
# done
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# open telnet localhost 4040
|
#######
|
||||||
# GET / HTTP/1.1
|
# This is where stuff is launched
|
||||||
# Host: localhost
|
#######
|
||||||
# more header stuff
|
|
||||||
#
|
rm -rf test.log
|
||||||
# maybe a body
|
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