From 683dbadb9157a4c29d9f79f6ff6c13ed46a8923d Mon Sep 17 00:00:00 2001 From: Eric LAZO Date: Sun, 14 Aug 2022 21:26:57 +0200 Subject: [PATCH] better telnet tester --- 1 | 3 ++ telnet_test.sh | 125 +++++++++++++++++++++++++---------------------- test_header.txt | 11 +++++ test_template.sh | 61 +++++++++++++++++++++++ 4 files changed, 142 insertions(+), 58 deletions(-) create mode 100644 1 create mode 100644 test_header.txt create mode 100644 test_template.sh diff --git a/1 b/1 new file mode 100644 index 0000000..3b77138 --- /dev/null +++ b/1 @@ -0,0 +1,3 @@ + +------ + diff --git a/telnet_test.sh b/telnet_test.sh index 5c199ca..3d2c3d6 100755 --- a/telnet_test.sh +++ b/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 diff --git a/test_header.txt b/test_header.txt new file mode 100644 index 0000000..bbe1f78 --- /dev/null +++ b/test_header.txt @@ -0,0 +1,11 @@ + +config_file=... +port=... + +# Host: ... + + + + +# the correct response +... diff --git a/test_template.sh b/test_template.sh new file mode 100644 index 0000000..6a057f4 --- /dev/null +++ b/test_template.sh @@ -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... +