diff --git a/compare.txt b/compare.txt
new file mode 100644
index 0000000..bf282f7
--- /dev/null
+++ b/compare.txt
@@ -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
+
+
+
+
+ Le Webserv
+
+
+ Le index (˘ ͜ʖ˘)
+
+ (˚3˚)
+
+
diff --git a/default.config b/default.config
index 344ea17..5f7bdb6 100644
--- a/default.config
+++ b/default.config
@@ -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;
diff --git a/expected_results/expected_path_test.txt b/expected_results/expected_path_test.txt
new file mode 100644
index 0000000..bf282f7
--- /dev/null
+++ b/expected_results/expected_path_test.txt
@@ -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
+
+
+
+
+ Le Webserv
+
+
+ Le index (˘ ͜ʖ˘)
+
+ (˚3˚)
+
+
diff --git a/main_test.sh b/main_test.sh
new file mode 100755
index 0000000..bbe0551
--- /dev/null
+++ b/main_test.sh
@@ -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
+
diff --git a/srcs/config/LocationConfig.hpp b/srcs/config/LocationConfig.hpp
index b6d96b3..fdcfd6a 100644
--- a/srcs/config/LocationConfig.hpp
+++ b/srcs/config/LocationConfig.hpp
@@ -6,7 +6,7 @@
/* By: lperrey +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
+ }
};
diff --git a/srcs/config/postProcessing.cpp b/srcs/config/postProcessing.cpp
index f4bb1a0..f93242e 100644
--- a/srcs/config/postProcessing.cpp
+++ b/srcs/config/postProcessing.cpp
@@ -46,6 +46,18 @@ void ConfigParser::_post_processing(std::vector *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::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 *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());
diff --git a/srcs/main.cpp b/srcs/main.cpp
index 3a44a33..b2eb1d6 100644
--- a/srcs/main.cpp
+++ b/srcs/main.cpp
@@ -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* servers = configParser.parse();
@@ -28,8 +28,8 @@ int main(int ac, char **av)
for (std::vector::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();
}
diff --git a/telnet_test.sh b/telnet_test.sh
index 3d2c3d6..8bb0f73 100755
--- a/telnet_test.sh
+++ b/telnet_test.sh
@@ -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
diff --git a/test_header.sh b/test_header.sh
new file mode 100644
index 0000000..8f1c988
--- /dev/null
+++ b/test_header.sh
@@ -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...
+
diff --git a/test_header.txt b/test_header.txt
deleted file mode 100644
index bbe1f78..0000000
--- a/test_header.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-
-config_file=...
-port=...
-
-# Host: ...
-
-
-
-
-# the correct response
-...
diff --git a/test_path.sh b/test_path.sh
new file mode 100644
index 0000000..fac7810
--- /dev/null
+++ b/test_path.sh
@@ -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"
+
+
+
diff --git a/test_template.sh b/test_template.sh
index 22388ad..ffb11e3 100644
--- a/test_template.sh
+++ b/test_template.sh
@@ -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"