still working on telnet tester

This commit is contained in:
Eric LAZO
2022-08-15 01:47:37 +02:00
parent 21efbef86a
commit aa03880601
12 changed files with 228 additions and 50 deletions

20
compare.txt Normal file
View File

@@ -0,0 +1,20 @@
telnet> Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
HTTP/1.1 200 OK
Server: Webserv/0.1
Connection: keep-alive
Content-Type: text/html; charset=UTF-8
Content-Length: 193
<!DOCTYPE html>
<html>
<head>
<title>Le Webserv</title>
</head>
<body>
<h1 style="text-align:center">Le index (˘ ͜ʖ˘)</h1>
<hr>
<p style="text-align:center">(˚3˚)</p>
</body>
</html>

View File

@@ -18,18 +18,6 @@ server {
# something to do with /upload
location /upload {
root ./www/test/;
index submit_form.html;
# upload_dir ./www/uploaded/;
# cgi_ext php;
}
location /uploaded {
# autoindex on;
root ./www/uploaded/;
upload_dir ./www/uploaded/;
}
# location /srcs/cgi-bin/ {
# root ./srcs/cgi-bin/;
@@ -46,11 +34,6 @@ server {
cgi_ext cpp php sh;
}
location /cgi-bin {
root ./srcs/cgi-bin/;
cgi_ext cpp php sh;
}
location /upload {
allow_methods POST;
autoindex on;

View File

@@ -0,0 +1,20 @@
telnet> Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
HTTP/1.1 200 OK
Server: Webserv/0.1
Connection: keep-alive
Content-Type: text/html; charset=UTF-8
Content-Length: 193
<!DOCTYPE html>
<html>
<head>
<title>Le Webserv</title>
</head>
<body>
<h1 style="text-align:center">Le index (˘ ͜ʖ˘)</h1>
<hr>
<p style="text-align:center">(˚3˚)</p>
</body>
</html>

51
main_test.sh Executable file
View File

@@ -0,0 +1,51 @@
#! /bin/bash
# import and run all tests
#test_files=("test_template.sh" "test_header.sh" "test_body.sh")
#test_files=("test_template.sh" "test_header.sh" "test_path.sh")
test_files=("test_path.sh")
test_all()
{
rm -rf telnet.out
rm -rf webserv.log
rm -rf compare.txt
rm -rf expected.txt
for i in "${test_files[@]}"
do
source $i
source telnet_test.sh
# echo $host $i
./webserv $config_file &>> webserv.log &
echo -e "${_GREEN}Running Telnet Test on '$test_name'${_END}"
sleep 1
# echo "$connect_to_telnet"
# run | telnet >> telnet.out
run | telnet > compare.txt
pkill webserv
echo -e "\n\n------\n" &>> webserv.log
# cat compare.txt
# cat $expected_result_file
DIFF=$(diff -q compare.txt $expected_result_file)
if [ "$DIFF" == "" ];
then
echo "Good diff"
else
diff compare.txt $expected_result_file
fi
cat compare.txt >> telnet.out
done
}
test_all

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/23 16:08:00 by me #+# #+# */
/* Updated: 2022/08/12 18:12:23 by lperrey ### ########.fr */
/* Updated: 2022/08/14 22:14:06 by erlazo ### ########.fr */
/* */
/* ************************************************************************** */
@@ -59,7 +59,7 @@ public:
}
// works a lot better than using a compare function...
bool operator<(const LocationConfig& rhs) const
bool operator<(const LocationConfig& rhs) const
{
int comp_lhs = 0;
int comp_rhs = 0;
@@ -84,6 +84,12 @@ public:
return (comp_lhs < comp_rhs); // right comparison ? not <= ?
};
bool operator==(const LocationConfig& rhs) const
{
if (path.compare(rhs.path) == 0)
return true;
return false;
}
};

View File

@@ -46,6 +46,18 @@ void ConfigParser::_post_processing(std::vector<ServerConfig> *servers)
while (it_l != it->locations.end())
{
if (it_l->path[it_l->path.size() - 1] == '/'
&& it_l->path.size() > 1)
it_l->path.erase(it_l->path.size() - 1);
std::vector<LocationConfig>::const_iterator tmp = it_l + 1;
while (tmp != it->locations.end())
{
if (it_l->path == tmp->path)
throw std::invalid_argument("Duplicate locations in config file");
++tmp;
}
if (it_l->root == "")
it_l->root = it->root;
@@ -57,13 +69,6 @@ void ConfigParser::_post_processing(std::vector<ServerConfig> *servers)
// nothing to be done for cgi_ext, error_pages, redirect
// if (eval_file_type(it_l->root) == IS_DIR
// && it_l->path[it_l->path.size() - 1] != '/')
// it_l->path.push_back('/');
if (it_l->path[it_l->path.size() - 1] == '/'
&& it_l->path.size() > 1)
it_l->path.erase(it_l->path.size() - 1);
++it_l;
}
std::sort(it->locations.begin(), it->locations.end());

View File

@@ -19,7 +19,7 @@ int main(int ac, char **av)
ConfigParser configParser(config.c_str());
// configParser._print_content();
configParser._print_content();
// i don't love that servers has to be a pointer...
std::vector<ServerConfig>* servers = configParser.parse();
@@ -28,8 +28,8 @@ int main(int ac, char **av)
for (std::vector<ServerConfig>::iterator it = servers->begin(); it < servers->end(); it++)
{
(void)0;
// std::cout << it->server_name << " ";
// it->print_all();
// std::cout << it->server_name << " ";
it->print_all();
}

View File

@@ -19,8 +19,8 @@ _WHITE='\033[37m'
_END='\033[0m'
test_file=$1
source $test_file
#test_file=$1
#source $test_file
connect_to_telnet="open $host $port"
@@ -106,27 +106,26 @@ run_all()
# This is where stuff is launched
#######
rm -rf test.log
rm -rf telnet.out
#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 &
#./webserv $config_file &> webserv.log &
#run_all
#run_this_test
echo -e "${_GREEN}Running Telnet Test on '$test_name'${_END}"
#echo -e "${_GREEN}Running Telnet Test on '$test_name'${_END}"
sleep 1
#sleep 1
run | telnet >> telnet.out
#run | telnet >> telnet.out
#run | telnet
pkill webserv
#pkill webserv

55
test_header.sh Normal file
View File

@@ -0,0 +1,55 @@
#! /bin/bash
test_name="Header Test"
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]} ${httpz[0]}"
header="Host: $host\n"
header+="Nonsense: fu\n"
header_cycle=("Transfer-encoding: fu" "Content-encoding: fu")
#header+="Transfer-encoding: fu\n"
#header+="Content-endcoding: fu\n"
body=
run_this_test()
{
for i in "${header_cycle[@]}"
do
header_send="$header$i"
request="$l1\n$header_send\n$body\n"
{
echo "----- $test_name -----"
echo -e "$_RED$request$_END"
} >> telnet.out
echo -e "$request"
sleep 1
echo -e "\n\n" >> telnet.out
done
}
# expected result...

View File

@@ -1,11 +0,0 @@
config_file=...
port=...
# Host: ...
# the correct response
...

49
test_path.sh Normal file
View File

@@ -0,0 +1,49 @@
#! /bin/bash
test_name="Path Test"
config_file="default.config"
port=4040
host="localhost"
#paths=("/" "/test" "/test/" "/list" "list" "/wrong") # you can add many
paths=("/") # you can add many
methods=("GET" "POST" "DELETE")
#methods=("GET")
httpz=("HTTP/1.1")
l1="${methods[0]} ${paths[0]} ${httpz[0]}"
header="Host: $host"
body=
run_this_test()
{
for i in "${paths[@]}"
do
l1="${methods[0]} $i ${httpz[0]}"
request="$l1\n$header\n$body\n"
{
echo "----- $test_name -----"
echo -e "$_RED$request$_END"
} >> telnet.out
echo -e "$request"
sleep 1
echo -e "\n\n" >> telnet.out
done
}
# expected result...
expected_result_file="./expected_results/expected_path_test.txt"

View File

@@ -19,7 +19,7 @@ httpz=("HTTP/1.1")
# let main.sh handle the l1
l1="${methods[0]} ${paths[0]} ${https[0]}"
l1="${methods[0]} ${paths[0]} ${httpz[0]}"
header="Host: $host"
body=
@@ -40,6 +40,7 @@ run_this_test()
# } 2>>&1
# } &>> /dev/stdout
echo -e "$request"
# echo
sleep 1
# {
# echo -e "\n------\n"