diff --git a/Tester/expected_results/expected_delete_test.txt b/Tester/expected_results/expected_delete_test.txt new file mode 100644 index 0000000..0867f2b --- /dev/null +++ b/Tester/expected_results/expected_delete_test.txt @@ -0,0 +1,29 @@ +telnet> Trying 127.0.0.1... +Connected to localhost. +Escape character is '^]'. +HTTP/1.1 405 Method Not Allowed +Allow: GET +Content-Type: text/html; charset=UTF-8 +Content-Length: 199 + +
Le Webserv/0.1
HTTP/1.1 204 No Content +Server: Webserv/0.1 +Connection: keep-alive + +HTTP/1.1 404 Not Found +Server: Webserv/0.1 +Connection: keep-alive +Content-Type: text/html; charset=UTF-8 +Content-Length: 210 + + + + +Le Webserv/0.1
+ + diff --git a/Tester/expected_results/expected_header_test.txt b/Tester/expected_results/expected_header_test.txt new file mode 100644 index 0000000..b2b8794 --- /dev/null +++ b/Tester/expected_results/expected_header_test.txt @@ -0,0 +1,15 @@ +telnet> Trying 127.0.0.1... +Connected to localhost. +Escape character is '^]'. +HTTP/1.1 501 Not Implemented +Server: Webserv/0.1 +Connection: keep-alive +Content-Type: text/html; charset=UTF-8 +Content-Length: 193 + +Le Webserv/0.1
HTTP/1.1 415 Unsupported Media Type +Accept-Encoding: +Content-Type: text/html; charset=UTF-8 +Content-Length: 207 + +Le Webserv/0.1
\ No newline at end of file diff --git a/Tester/expected_results/expected_method_test.txt b/Tester/expected_results/expected_method_test.txt new file mode 100644 index 0000000..976d413 --- /dev/null +++ b/Tester/expected_results/expected_method_test.txt @@ -0,0 +1,37 @@ +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 + + + + +(˚3˚)
+ + +HTTP/1.1 405 Method Not Allowed +Allow: GET +Content-Type: text/html; charset=UTF-8 +Content-Length: 199 + +Le Webserv/0.1
HTTP/1.1 405 Method Not Allowed +Allow: GET +Content-Type: text/html; charset=UTF-8 +Content-Length: 199 + +Le Webserv/0.1
HTTP/1.1 501 Not Implemented +Server: Webserv/0.1 +Connection: keep-alive +Content-Type: text/html; charset=UTF-8 +Content-Length: 193 + +Le Webserv/0.1
\ No newline at end of file diff --git a/Tester/expected_results/expected_path_test.txt b/Tester/expected_results/expected_path_test.txt index e09bbf5..e859985 100644 --- a/Tester/expected_results/expected_path_test.txt +++ b/Tester/expected_results/expected_path_test.txt @@ -22,15 +22,13 @@ HTTP/1.1 200 OK Server: Webserv/0.1 Connection: keep-alive Content-Type: text/html; charset=UTF-8 -Content-Length: 290 +Content-Length: 227(˚3˚)
-HTTP/1.1 +HTTP/1.1 200 OK Server: Webserv/0.1 Connection: keep-alive Content-Type: text/html; charset=UTF-8 -Content-Length: 1277 +Content-Length: 1281 -.. +Index of ./Tester/www/ Index of ./Tester/www/
../ upload_form.html form_get.html kermit.ico @@ -72,14 +68,14 @@ Content-Length: 1277 Cagneyc_intro.gif Van_Eyck_Portrait_Arnolfini.jpg root.png -test +test/ drill.jpg punpun.png favicon.ico index.html rfc2119.html -error_pages -rfc2119_files +error_pages/ +rfc2119_files/
HTTP/1.1 404 Not Found Server: Webserv/0.1 Connection: keep-alive diff --git a/Tester/expected_results/expected_valid_uri_test.txt b/Tester/expected_results/expected_valid_uri_test.txt new file mode 100644 index 0000000..9a28a20 --- /dev/null +++ b/Tester/expected_results/expected_valid_uri_test.txt @@ -0,0 +1,110 @@ +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˚)
+ + +HTTP/1.1 200 OK +Server: Webserv/0.1 +Connection: keep-alive +Content-Type: text/css; charset=UTF-8 +Content-Length: 43 + +h1 { + color: red; + text-align: center; +} +HTTP/1.1 200 OK +Server: Webserv/0.1 +Connection: keep-alive +Content-Type: text/html; charset=UTF-8 +Content-Length: 207 + + + + +Webserv test Something + + +Webserv Test Something
+
+(˚3˚)
+ + +HTTP/1.1 200 OK +Server: Webserv/0.1 +Connection: keep-alive +Content-Type: text/html; charset=UTF-8 +Content-Length: 207 + + + + +Webserv test Something + + +Webserv Test Something
+
+(˚3˚)
+ + +HTTP/1.1 200 OK +Server: Webserv/0.1 +Connection: keep-alive +Content-Type: text/html; charset=UTF-8 +Content-Length: 227 + + + + +Webserv test index + + + +Webserv Test Index
+
+(˚3˚)
+ + +HTTP/1.1 200 OK +Server: Webserv/0.1 +Connection: keep-alive +Content-Type: text/html; charset=UTF-8 +Content-Length: 1281 + +Index of ./Tester/www/ Index of ./Tester/www/
../ +upload_form.html +form_get.html +kermit.ico +upload_form_single.html +Cagneyc_intro.gif +Van_Eyck_Portrait_Arnolfini.jpg +root.png +test/ +drill.jpg +punpun.png +favicon.ico +index.html +rfc2119.html +error_pages/ +rfc2119_files/ +
HTTP/1.1 301 Moved Permanently +Location: https://berniesanders.com/404/ + +HTTP/1.1 307 Temporary Redirect +Location: https://fr.wikipedia.org/wiki/Ketchup + diff --git a/Tester/test1.config b/Tester/test1.config index e245aaa..013778d 100644 --- a/Tester/test1.config +++ b/Tester/test1.config @@ -25,6 +25,16 @@ server { root ./Tester/www/; } + location /to_delete.txt { + allow_methods GET DELETE; + root ./Tester/www/to_delete.txt; + } + + location /i_do_not_exist.txt { + allow_methods GET DELETE; + root ./Tester/www/to_delete.txt; + } + location /srcs/cgi-bin/ { root ./srcs/cgi-bin/; allow_methods POST; diff --git a/Tester/test_body.sh b/Tester/test_body.sh index fd0656d..6b84fa9 100644 --- a/Tester/test_body.sh +++ b/Tester/test_body.sh @@ -25,7 +25,7 @@ body+="this is a message this is a message this is a message this is a message t #header_cycle=("Content-Length: 17\n" "\n") #header_cycle=("Content-Length: 17\n") #header_cycle=() -#header+="Content-Length: 8\n" +header+="Content-Length: 8\n" run_this_test() { diff --git a/Tester/test_delete.sh b/Tester/test_delete.sh new file mode 100644 index 0000000..e708488 --- /dev/null +++ b/Tester/test_delete.sh @@ -0,0 +1,75 @@ +#! /bin/bash + +test_name="Delete Test" + +config_file="./Tester/test1.config" +port=4040 +host="localhost" + +#paths=("/" "/test" "/test/" "/list" "list" "/wrong") # you can add many +paths=("/" "/to_delete.txt" "/i_do_not_exist.txt") # you can add many +#methods=("GET" "POST" "DELETE") +methods=("DELETE") +httpz=("HTTP/1.1") + + + +l1="${methods[0]} ${paths[0]} ${httpz[0]}" + +header="Host: $host" +body= + + +run_this_test() +{ + + echo "we will delete" > ./Tester/www/to_delete.txt + + 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.log + echo -e "$request" + sleep 1 + echo -e "\n" >> telnet.log + done + +} + + + +# expected result... + + +files=() + +file="expected_delete_test.txt" +#files+=("expected_path_root_test.txt") +#files+=("expected_path_testnoslash_test.txt") +#files+=("expected_path_testslash_test.txt") +#files+=("expected_path_list_test.txt") +#files+=("expected_path_badlist_test.txt") +#files+=("expected_path_wrong_test.txt") + + +#local_expected_test_file=$file +local_expected_test_files=() +test_path="" + +add_path() +{ + for i in "${files[@]}" + do + local_expected_test_files+=("$test_path$i") + done +} + +#add_path + + + + diff --git a/Tester/test_method.sh b/Tester/test_method.sh index ca0fb43..b85aaca 100644 --- a/Tester/test_method.sh +++ b/Tester/test_method.sh @@ -17,7 +17,6 @@ httpz=("HTTP/1.1") # the parts we will send to webserv -# let main.sh handle the l1 @@ -26,8 +25,6 @@ header+="Nonsense: fu\n" #header_cycle=("Transfer-encoding: fu" "Content-encoding: fu") -#header+="Transfer-encoding: fu\n" -#header+="Content-endcoding: fu\n" body= diff --git a/Tester/test_path.sh b/Tester/test_path.sh index ffd4417..b2cd65b 100644 --- a/Tester/test_path.sh +++ b/Tester/test_path.sh @@ -16,7 +16,7 @@ httpz=("HTTP/1.1") l1="${methods[0]} ${paths[0]} ${httpz[0]}" -header="Host: $host" +header="Host: $host\n" body= diff --git a/Tester/test_port.sh b/Tester/test_port.sh index 27c83cf..5991663 100644 --- a/Tester/test_port.sh +++ b/Tester/test_port.sh @@ -45,8 +45,7 @@ run_this_test() files=() -file="expected_path_test.txt" -files+=("expected_path_test.txt") +file="expected_port_test.txt" #files+=("expected_path_root_test.txt") #files+=("expected_path_testnoslash_test.txt") #files+=("expected_path_testslash_test.txt") diff --git a/compare.txt b/compare.txt index 94ccf2a..0867f2b 100644 --- a/compare.txt +++ b/compare.txt @@ -1,4 +1,29 @@ telnet> Trying 127.0.0.1... -telnet> ?Invalid command -telnet> ?Invalid command -telnet> telnet> telnet> \ No newline at end of file +Connected to localhost. +Escape character is '^]'. +HTTP/1.1 405 Method Not Allowed +Allow: GET +Content-Type: text/html; charset=UTF-8 +Content-Length: 199 + +405 Method Not Allowed 405 Method Not Allowed
Le Webserv/0.1
HTTP/1.1 204 No Content +Server: Webserv/0.1 +Connection: keep-alive + +HTTP/1.1 404 Not Found +Server: Webserv/0.1 +Connection: keep-alive +Content-Type: text/html; charset=UTF-8 +Content-Length: 210 + + + + +404 Not Found + + +Check it UP 404 Not Found
+
+Le Webserv/0.1
+ + diff --git a/default.config b/default.config index 033bc4a..cbdb2b3 100644 --- a/default.config +++ b/default.config @@ -11,12 +11,14 @@ server { client_body_limit 5000; # Max == 18446744073709551615 / 1024 == 18014398509481984 + index index.html; # this is another comment #index mdr.html; # this is another comment root ./www/; error_page 404 ./www/error_pages/error_404.html; +# error_page 403 ./www/error_pages/error_404.html; @@ -103,10 +105,6 @@ server { index something.html; } -# location /test/test_deeper/something.html { -# allow_methods DELETE; -# } - } server { diff --git a/main_test.sh b/main_test.sh index 63b0494..9cf7dcb 100755 --- a/main_test.sh +++ b/main_test.sh @@ -21,11 +21,13 @@ _END='\033[0m' #test_file_names=("test_template.sh" "test_header.sh" "test_path.sh") -#test_file_names=("test_method.sh" "test_header.sh" "test_path.sh") -test_file_names=("test_port.sh") +test_file_names=("test_method.sh" "test_header.sh" "test_path.sh" "test_valid_uri.sh" "test_delete.sh") + +# Run this separately cuz of the content length subtlty #test_file_names=("test_body.sh") -#test_file_names=("test_valid_uri.sh") -#test_file_names=("test_path.sh") + +# kinda fucking useless, easier to test IRL +#test_file_names=("test_port.sh") test_files=() expected_result_files=() @@ -54,7 +56,6 @@ test_all() { arg=${1} - c=0 make @@ -102,8 +103,6 @@ test_all() cat compare.txt > $expected_result_file fi - c+=1 - done if [ "$arg" = "" ]; diff --git a/www/to_delete.txt b/www/to_delete.txt new file mode 100644 index 0000000..e2147d4 --- /dev/null +++ b/www/to_delete.txt @@ -0,0 +1 @@ +we will delete