a few small fixes here and there, more telnet tests, starting Siege load testing

This commit is contained in:
Eric LAZO
2022-08-16 20:41:57 +02:00
parent ff443c80b1
commit 1b7d388231
17 changed files with 163 additions and 94 deletions

View File

@@ -63,8 +63,12 @@ server {
root ./Tester/www/test/;
}
location /stylesheet {
root ./stylesheet/;
}
location /test/index1.html {
root ./Tester/www/test/;
root ./Tester/www/test/index1.html;
index index1.html subdex.html;
}
@@ -72,14 +76,9 @@ server {
redirect 301 https://berniesanders.com/404/;
}
location /stylesheet/ {
# root ./www/../;
root ./styelsheet/;
}
location /test/something.html {
# allow_methods DELETE;
root ./Tester/www/test/;
root ./Tester/www/test/something.html;
}
location /test/test_deeper/ {

View File

@@ -2,7 +2,7 @@
test_name="Header Test"
config_file="test1.config"
config_file="./Tester/test1.config"
port=4040
host="localhost"
@@ -41,10 +41,10 @@ run_this_test()
{
echo "----- $test_name -----"
echo -e "$_RED$request$_END"
} >> telnet.out
} >> telnet.log
echo -e "$request"
sleep 1
echo -e "\n\n" >> telnet.out
echo -e "\n\n" >> telnet.log
done
}

View File

@@ -2,7 +2,7 @@
test_name="Method Test"
config_file="test1.config"
config_file="./Tester/test1.config"
port=4040
host="localhost"
@@ -41,10 +41,10 @@ run_this_test()
{
echo "----- $test_name -----"
echo -e "$_RED$request$_END"
} >> telnet.out
} >> telnet.log
echo -e "$request"
sleep 1
echo -e "\n\n" >> telnet.out
echo -e "\n\n" >> telnet.log
done
}

View File

@@ -2,7 +2,7 @@
test_name="Path Test"
config_file="test1.config"
config_file="./Tester/test1.config"
port=4040
host="localhost"
@@ -31,7 +31,6 @@ run_this_test()
echo "----- $test_name -----"
echo -e "$_RED$request$_END"
} >> telnet.log
# echo -e "$request" > compare.txt >> telnet.out
echo -e "$request"
sleep 1
echo -e "\n" >> telnet.log

View File

@@ -2,7 +2,7 @@
test_name="Template test all good"
config_file="default.config"
config_file="./Tester/test1.config"
port=4040
host="localhost"
@@ -35,7 +35,7 @@ run_this_test()
{
echo "----- $test_name -----"
echo -e "$_RED$request$_END"
} >> telnet.out
} >> telnet.log
# } &>> test.log
# } 2>>&1
# } &>> /dev/stdout
@@ -47,7 +47,7 @@ run_this_test()
# } > /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" >> telnet.log
# echo -e "\n\n------\n\n" >> telnet.out
# echo -e "\n------\n" > /dev/stdout
# run_a_test

74
Tester/test_valid_uri.sh Normal file
View File

@@ -0,0 +1,74 @@
#! /bin/bash
test_name="Valid URIs Test"
config_file="./Tester/test1.config"
port=4040
host="localhost"
paths=("/" "/stylesheet/style.css" "/test/something.html" "/test/something.html/" "/test/" "/list" "/hilarious_404" "/redirect") # 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.log
echo -e "$request"
sleep 1
echo -e "\n" >> telnet.log
done
}
# expected result...
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=""
add_path()
{
for i in "${files[@]}"
do
local_expected_test_files+=("$test_path$i")
done
}
#add_path

View File

@@ -2,9 +2,7 @@
<html>
<head>
<title>Webserv test index</title>
<!-- <link rel="stylesheet" href="stylesheet/style.css"> -->
<link rel="stylesheet" href="/stylesheet/style.css">
</head>
<body>
<h1>Webserv Test Index</h1>

View File

@@ -21,19 +21,26 @@ Content-Length: 193
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: 290
Content-Length: 207
<!DOCTYPE html>
<html>
<head>
<title>Webserv test index</title>
<!-- <link rel="stylesheet" href="stylesheet/style.css"> -->
<link rel="stylesheet" href="/stylesheet/style.css">
<title>Webserv test Something</title>
</head>
<body>
<h1>Webserv Test Index</h1>
<h1 style="text-align:center">Webserv Test Something</h1>
<hr>
<p style="text-align:center">(˚3˚)</p>
</body>
@@ -42,15 +49,30 @@ HTTP/1.1 200 OK
Server: Webserv/0.1
Connection: keep-alive
Content-Type: text/html; charset=UTF-8
Content-Length: 290
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"> -->
<link rel="stylesheet" href="/stylesheet/style.css">
</head>
<body>
<h1>Webserv Test Index</h1>
@@ -58,7 +80,7 @@ Content-Length: 290
<p style="text-align:center">(˚3˚)</p>
</body>
</html>
HTTP/1.1
HTTP/1.1 200 OK
Server: Webserv/0.1
Connection: keep-alive
Content-Type: text/html; charset=UTF-8
@@ -80,37 +102,13 @@ Content-Length: 1277
<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 404 Not Found
</pre><hr></body></html>HTTP/1.1 301 Moved Permanently
Location: https://berniesanders.com/404/
Server: Webserv/0.1
Connection: keep-alive
Content-Type: text/html; charset=UTF-8
Content-Length: 210
HTTP/1.1 307 Temporary Redirect
Location: https://fr.wikipedia.org/wiki/Ketchup
<!DOCTYPE html>
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1 style="text-align:center">Check it UP 404 Not Found</h1>
<hr>
<p style=\"text-align:center\">Le Webserv/0.1</p>
</body>
</html>
HTTP/1.1 404 Not Found
Server: Webserv/0.1
Connection: keep-alive
Content-Type: text/html; charset=UTF-8
Content-Length: 210
<!DOCTYPE html>
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1 style="text-align:center">Check it UP 404 Not Found</h1>
<hr>
<p style=\"text-align:center\">Le Webserv/0.1</p>
</body>
</html>

View File

@@ -63,8 +63,12 @@ server {
root ./www/test/;
}
location /stylesheet {
root ./stylesheet/;
}
location /test/index1.html {
root ./www/test/;
root ./www/test/index1.html;
index index1.html subdex.html;
}
@@ -72,14 +76,9 @@ server {
redirect 301 https://berniesanders.com/404/;
}
location /stylesheet/ {
# root ./www/../;
root ./styelsheet/;
}
location /test/something.html {
# allow_methods DELETE;
root ./www/test/;
root ./www/test/something.html;
}
location /test/test_deeper/ {

View File

@@ -21,7 +21,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_method.sh" "test_header.sh" "test_path.sh")
test_file_names=("test_valid_uri.sh")
#test_file_names=("test_path.sh")
test_files=()
@@ -103,10 +104,10 @@ test_all()
done
# if [ "$arg" != "diff" ];
# then
# cat telnet.log
# fi
if [ "$arg" = "" ];
then
cat telnet.log
fi
}

View File

@@ -361,6 +361,8 @@ void Client::_parse_request_target( std::string target )
else
_request.query = "";
_request.abs_path = target.substr(0, pos);
if (_request.abs_path[_request.abs_path.size() - 1] == '/')
_request.abs_path.erase(_request.abs_path.size() - 1);
}
void Client::_parse_request_fields()

View File

@@ -50,14 +50,6 @@ void ConfigParser::_post_processing(std::vector<ServerConfig> *servers)
&& 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;
@@ -71,6 +63,20 @@ void ConfigParser::_post_processing(std::vector<ServerConfig> *servers)
++it_l;
}
it_l = it->locations.begin();
while (it_l != it->locations.end())
{
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;
}
++it_l;
}
std::sort(it->locations.begin(), it->locations.end());
std::reverse(it->locations.begin(), it->locations.end());

View File

@@ -19,6 +19,7 @@ void Webserv::_get(Client *client, std::string &path)
{
path.append(client->assigned_location->index[i]);
_get_file(client, path);
std::cerr << "Added an index\n"; //debug
return ;
}
}
@@ -88,16 +89,10 @@ void Webserv::_autoindex(Client *client, const std::string &path)
{
std::cout << "_autoindex()\n";
// std::cout << "client target: " << client->get_rq_target() << '\n';
std::string dir_list;
DIR *dir;
struct dirent *ent;
// std::cout << "location root: " << client->assigned_location->root << " location path: " << client->assigned_location->path << '\n';
// std::cout << "Path in auto is: " << path << '\n';
if ( (dir = opendir(path.c_str()) ) != NULL)
{
@@ -106,20 +101,19 @@ void Webserv::_autoindex(Client *client, const std::string &path)
dir_list.append(AUTOINDEX_MID1);
dir_list.append(path);
dir_list.append(AUTOINDEX_MID2);
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL)
{
// std::cout << "ent: " << ent->d_name << '\n';
if (strcmp(".", ent->d_name) == 0)
continue ;
dir_list.append("<a style=\"font-size:1.5em\" href=\"");
// dir_list.append(client->get_rq_target());
dir_list.append(client->get_rq_abs_path());
if (dir_list[dir_list.size() - 1] != '/')
dir_list.push_back('/');
dir_list.append(ent->d_name);
dir_list.append("\">");
dir_list.append(ent->d_name);
if (ent->d_type == DT_DIR)
dir_list.append("/");
dir_list.append("</a>");
dir_list.append("\n");
}
@@ -131,15 +125,14 @@ void Webserv::_autoindex(Client *client, const std::string &path)
// <a href="/test/test_deeper/..">..</a>
dir_list.append(AUTOINDEX_END);
// std::cout << "\n\n" << dir_list << '\n';
closedir (dir);
client->status = 200;
_append_body(client, dir_list, "html");
}
else
{
// in theory not possible cuz we already checked...
std::cerr << "could not open dir\n";
// throw?
client->status = 500;
perror("could not open dir");
return ;
}
}

View File

@@ -105,6 +105,7 @@ void Webserv::_construct_response(Client *client)
void Webserv::_process_method(Client *client, std::string &path)
{
std::cerr << "allow_methods = " << http_methods_to_str(client->assigned_location->allow_methods) << "\n"; // debug
std::cerr << "Path again: " << path << '\n'; // debug
switch (client->get_rq_method())
{

View File

@@ -1 +0,0 @@
something

View File

@@ -1 +0,0 @@
something

View File

@@ -1,3 +1,4 @@
http://localhost:4040
http://localhost:4040/test
http://localhost:4040/test/test_deeper/
http://localhost:4040/test/test_deeper/super_deep/