more telnet tests
This commit is contained in:
95
Tester/test2.config
Normal file
95
Tester/test2.config
Normal file
@@ -0,0 +1,95 @@
|
||||
|
||||
server {
|
||||
|
||||
# this is a comment
|
||||
|
||||
server_name server1;
|
||||
|
||||
listen 0.0.0.0:4040;
|
||||
|
||||
client_body_limit 1;
|
||||
# Max == 18446744073709551615 / 1024 == 18014398509481984
|
||||
|
||||
index index.html; # this is another comment
|
||||
|
||||
root ./Tester/www/;
|
||||
|
||||
error_page 404 ./Tester/www/error_pages/error_404.html;
|
||||
|
||||
|
||||
|
||||
location / {
|
||||
allow_methods GET;
|
||||
root ./Tester/www/;
|
||||
}
|
||||
|
||||
location /srcs/cgi-bin/ {
|
||||
root ./srcs/cgi-bin/;
|
||||
allow_methods POST;
|
||||
cgi_ext php;
|
||||
}
|
||||
|
||||
location /list {
|
||||
autoindex on;
|
||||
}
|
||||
|
||||
location /cgi-bin {
|
||||
root ./srcs/cgi-bin/;
|
||||
cgi_ext out php sh;
|
||||
}
|
||||
|
||||
location /upload {
|
||||
allow_methods POST;
|
||||
autoindex on;
|
||||
upload_dir ./Tester/www/user_files/;
|
||||
# root doesn’t matter if used only with POST and no CGI
|
||||
}
|
||||
|
||||
location /the_dump {
|
||||
allow_methods GET DELETE;
|
||||
root ./Tester/www/user_files;
|
||||
autoindex on;
|
||||
}
|
||||
|
||||
location /redirect {
|
||||
redirect 307 https://fr.wikipedia.org/wiki/Ketchup;
|
||||
# redirect 307 https://www.youtube.com/watch?v=rG6b8gjMEkw;
|
||||
}
|
||||
|
||||
location /test {
|
||||
index index1.html subdex.html;
|
||||
root ./Tester/www/test/;
|
||||
}
|
||||
|
||||
location /stylesheet {
|
||||
root ./stylesheet/;
|
||||
}
|
||||
|
||||
location /test/index1.html {
|
||||
root ./Tester/www/test/index1.html;
|
||||
index index1.html subdex.html;
|
||||
}
|
||||
|
||||
location /hilarious_404/ {
|
||||
redirect 301 https://berniesanders.com/404/;
|
||||
}
|
||||
|
||||
location /test/something.html {
|
||||
# allow_methods DELETE;
|
||||
root ./Tester/www/test/something.html;
|
||||
}
|
||||
|
||||
location /test/test_deeper/ {
|
||||
# allow_methods
|
||||
root ./Tester/www/test/test_deeper/;
|
||||
}
|
||||
|
||||
location /test/test_deeper/super_deep {
|
||||
root ./Tester/www/test/test_deeper/super_deep/;
|
||||
}
|
||||
|
||||
# location /test/test_deeper/something.html {
|
||||
# allow_methods DELETE;
|
||||
# }
|
||||
|
||||
}
|
||||
84
Tester/test_body.sh
Normal file
84
Tester/test_body.sh
Normal file
@@ -0,0 +1,84 @@
|
||||
#! /bin/bash
|
||||
|
||||
test_name="Body Test"
|
||||
|
||||
config_file="./Tester/test2.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\n"
|
||||
body="this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message \n"
|
||||
|
||||
# turns out this does nothing...
|
||||
#header_cycle=("Content-Length: 17" "Content-Length: 14" "Content-Length: 25")
|
||||
#header_cycle=("Content-Length: 17" "")
|
||||
#header_cycle=("Content-Length: 17")
|
||||
#header_cycle=()
|
||||
header+="Content-Length: 15"
|
||||
|
||||
run_this_test()
|
||||
{
|
||||
|
||||
# for i in "${header_cycle[@]}"
|
||||
for i in "${paths[@]}"
|
||||
do
|
||||
# l1="${methods[0]} ${paths[0]} ${httpz[0]}"
|
||||
l1="${methods[0]} $i ${httpz[0]}"
|
||||
# header_send="$header$i"
|
||||
header_send="$header"
|
||||
request="$l1\n$header_send\n\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_body_test.txt"
|
||||
files+=("expected_body_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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -47,15 +47,7 @@ files=()
|
||||
|
||||
file="expected_valid_uri_test.txt"
|
||||
files+=("expected_valid_files_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=""
|
||||
|
||||
|
||||
112
compare.txt
112
compare.txt
@@ -1,114 +1,10 @@
|
||||
telnet> Trying 127.0.0.1...
|
||||
Connected to localhost.
|
||||
Escape character is '^]'.
|
||||
HTTP/1.1 200 OK
|
||||
HTTP/1.1 413 Content Too Large
|
||||
Server: Webserv/0.1
|
||||
Connection: keep-alive
|
||||
Connection: close
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
Content-Length: 193
|
||||
Content-Length: 197
|
||||
|
||||
<!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>
|
||||
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
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Webserv test Something</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="text-align:center">Webserv Test Something</h1>
|
||||
<hr>
|
||||
<p style="text-align:center">(˚3˚)</p>
|
||||
</body>
|
||||
</html>
|
||||
HTTP/1.1 200 OK
|
||||
Server: Webserv/0.1
|
||||
Connection: keep-alive
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
Content-Length: 207
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Webserv test Something</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="text-align:center">Webserv Test Something</h1>
|
||||
<hr>
|
||||
<p style="text-align:center">(˚3˚)</p>
|
||||
</body>
|
||||
</html>
|
||||
HTTP/1.1 200 OK
|
||||
Server: Webserv/0.1
|
||||
Connection: keep-alive
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
Content-Length: 227
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Webserv test index</title>
|
||||
<link rel="stylesheet" href="/stylesheet/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Webserv Test Index</h1>
|
||||
<hr>
|
||||
<p style="text-align:center">(˚3˚)</p>
|
||||
</body>
|
||||
</html>
|
||||
HTTP/1.1 200 OK
|
||||
Server: Webserv/0.1
|
||||
Connection: keep-alive
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
Content-Length: 1277
|
||||
|
||||
<!DOCTYPE html><html><head><title>Index of ./Tester/www/</title></head><body><h1>Index of ./Tester/www/</h1><hr><pre><a style="font-size:1.5em" href="/list/..">..</a>
|
||||
<a style="font-size:1.5em" href="/list/upload_form.html">upload_form.html</a>
|
||||
<a style="font-size:1.5em" href="/list/form_get.html">form_get.html</a>
|
||||
<a style="font-size:1.5em" href="/list/kermit.ico">kermit.ico</a>
|
||||
<a style="font-size:1.5em" href="/list/upload_form_single.html">upload_form_single.html</a>
|
||||
<a style="font-size:1.5em" href="/list/Cagneyc_intro.gif">Cagneyc_intro.gif</a>
|
||||
<a style="font-size:1.5em" href="/list/Van_Eyck_Portrait_Arnolfini.jpg">Van_Eyck_Portrait_Arnolfini.jpg</a>
|
||||
<a style="font-size:1.5em" href="/list/root.png">root.png</a>
|
||||
<a style="font-size:1.5em" href="/list/test">test</a>
|
||||
<a style="font-size:1.5em" href="/list/drill.jpg">drill.jpg</a>
|
||||
<a style="font-size:1.5em" href="/list/punpun.png">punpun.png</a>
|
||||
<a style="font-size:1.5em" href="/list/favicon.ico">favicon.ico</a>
|
||||
<a style="font-size:1.5em" href="/list/index.html">index.html</a>
|
||||
<a style="font-size:1.5em" href="/list/rfc2119.html">rfc2119.html</a>
|
||||
<a style="font-size:1.5em" href="/list/error_pages">error_pages</a>
|
||||
<a style="font-size:1.5em" href="/list/rfc2119_files">rfc2119_files</a>
|
||||
</pre><hr></body></html>HTTP/1.1 301 Moved Permanently
|
||||
Location: https://berniesanders.com/404/
|
||||
|
||||
Server: Webserv/0.1
|
||||
Connection: keep-alive
|
||||
HTTP/1.1 307 Temporary Redirect
|
||||
Location: https://fr.wikipedia.org/wiki/Ketchup
|
||||
|
||||
Server: Webserv/0.1
|
||||
Connection: keep-alive
|
||||
<!DOCTYPE html><html><head><title>413 Content Too Large</title></head><body><h1 style="text-align:center">413 Content Too Large</h1><hr><p style="text-align:center">Le Webserv/0.1</p></body></html>
|
||||
@@ -22,7 +22,8 @@ _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_valid_uri.sh")
|
||||
test_file_names=("test_body.sh")
|
||||
#test_file_names=("test_valid_uri.sh")
|
||||
#test_file_names=("test_path.sh")
|
||||
|
||||
test_files=()
|
||||
|
||||
@@ -23,11 +23,6 @@ void ConfigParser::_post_processing(std::vector<ServerConfig> *servers)
|
||||
|
||||
if (it->client_body_limit == 0)
|
||||
it->client_body_limit = 1 * MB;
|
||||
|
||||
|
||||
// if error_pages is left empty, we'll use the defaults which
|
||||
// i believe are set elsewhere...
|
||||
|
||||
|
||||
if (!_find_root_path_location(it->locations))
|
||||
{
|
||||
@@ -84,7 +79,6 @@ void ConfigParser::_post_processing(std::vector<ServerConfig> *servers)
|
||||
}
|
||||
}
|
||||
|
||||
// const?
|
||||
bool ConfigParser::_find_root_path_location(std::vector<LocationConfig> locations) const
|
||||
{
|
||||
std::vector<LocationConfig>::const_iterator it = locations.begin();
|
||||
@@ -96,5 +90,4 @@ bool ConfigParser::_find_root_path_location(std::vector<LocationConfig> location
|
||||
++it;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
4
urls.txt
4
urls.txt
@@ -1,5 +1,9 @@
|
||||
http://localhost:4040
|
||||
http://localhost:4040/punpun.png
|
||||
http://localhost:4040/Cagneyc_intro.gif
|
||||
http://localhost:4040/drill.jpg
|
||||
http://localhost:4040/test
|
||||
http://localhost:4040/test/test_deeper/
|
||||
http://localhost:4040/test/test_deeper/super_deep/
|
||||
http://localhost:4040/test/index1.html
|
||||
|
||||
|
||||
Reference in New Issue
Block a user