Skip to content

Commit

Permalink
Merge pull request #99 from ak0327/feature/test
Browse files Browse the repository at this point in the history
add test
  • Loading branch information
ak0327 authored Mar 8, 2024
2 parents eccb6ac + 952554c commit 6bce3d1
Show file tree
Hide file tree
Showing 68 changed files with 1,468 additions and 593 deletions.
32 changes: 25 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -MMD -MP -pedantic
CXXFLAGS += -D USE_SELECT
#CXXFLAGS += -D USE_POLL
CXXFLAGS += -D DEBUG
#CXXFLAGS += -D LEAKS

# SRCS -------------------------------------------------------------------------
SRCS_DIR = srcs
Expand Down Expand Up @@ -141,6 +140,19 @@ CGI_DIR = $(RESPONSE_DIR)/CgiHandler
SRCS += $(CGI_DIR)/CgiHandler.cpp


# CLIENT -----------------------------------------------------------------------
#CLIENT_DIR = Client
#CLIENT_SRC = $(CLIENT_DIR)/Client.cpp \
# $(CLIENT_DIR)/client_main.cpp
#CLIENT_OBJ = $(CLIENT_SRC:%.cpp=%.o)
#CLIENT_OBJS = $(addprefix $(OBJS_DIR)/, $(CLIENT_OBJ)) \
# $(filter-out $(OBJS_DIR)/main.o, $(OBJS))


INCLUDES = $(addprefix -I, $(INCLUDES_DIR))



# OBJS -------------------------------------------------------------------------
OBJS_DIR = objs
OBJS = $(SRCS:%.cpp=$(OBJS_DIR)/%.o)
Expand Down Expand Up @@ -169,7 +181,8 @@ INCLUDES_DIR = includes \
$(SRCS_DIR)/$(CONFIG_DIR)/Tokenizer \
$(SRCS_DIR)/$(CONFIG_DIR) \
$(SRCS_DIR)/$(EVENT_DIR) \
$(SRCS_DIR)/$(CGI_DIR)
$(SRCS_DIR)/$(CGI_DIR) \
$(SRCS_DIR)/$(CLIENT_DIR)

REQUEST_INCLUDES = $(SRCS_DIR)/$(REQUEST_DIR) \
$(SRCS_DIR)/$(DATE_DIR) \
Expand All @@ -189,8 +202,6 @@ RESPONSE_INCLUDES = $(SRCS_DIR)/$(RESPONSE_DIR) \
$(SRCS_DIR)/$(RESPONSE_DIR)/POST \
$(SRCS_DIR)/$(RESPONSE_DIR)/DELETE

INCLUDES = $(addprefix -I, $(INCLUDES_DIR))


# RULES ------------------------------------------------------------------------
.PHONY : all
Expand Down Expand Up @@ -314,8 +325,8 @@ run_multi_field_values_test :
run_map_field_values_test :
cmake -S . -B build
cmake --build build
# ./build/unit_test --gtest_filter=TestMapFieldValues*
./build/unit_test --gtest_filter=TestMapFieldValues*.Cookie*
./build/unit_test --gtest_filter=TestMapFieldValues*
#./build/unit_test --gtest_filter=TestMapFieldValues*.Cookie*

.PHONY : run_map_set_field_values_test
run_map_set_field_values_test :
Expand Down Expand Up @@ -369,8 +380,9 @@ run_parse_test :
#cmake -S . -B build
cmake --build build
./build/unit_test --gtest_filter=TestParser*
#./build/unit_test --gtest_filter=TestParser:TestParse
# ./build/unit_test --gtest_filter=TestParser:TestParse
#./build/unit_test --gtest_filter=TestParser.ParseServer
# ./build/unit_test --gtest_filter=TestParser.ParseHttp

.PHONY : run_config_test
run_config_test :
Expand All @@ -397,5 +409,11 @@ run_post_test :
./build/unit_test --gtest_filter=HttpResponsePOST*
@. test/integration/prepare_test_file.sh; clear_test_files


#.PHONY : client
#client : $(CLIENT_OBJS)
# $(CXX) $(CXXFLAGS) -o $@ $^


# include DEPS -----------------------------------------------------------------
-include $(DEPS)
51 changes: 34 additions & 17 deletions conf/webserv.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
events {
} # events
# webserv conf

http {
recv_timeout 30s; # original; combined client_header_timeout and client_body_timeout
send_timeout 10s;
keepalive_timeout 20s; # 0: disable keep-alive
keepalive_timeout 30s; # 0: disable keep-alive

# static file server
# static file server -------------------------------------------------------
server {
listen 4242 default_server;
server_name webserv static_server;
Expand All @@ -22,6 +21,7 @@ http {
}
}

# directory listing
location /autoindex_files/ {
root html;
autoindex on;
Expand All @@ -31,23 +31,24 @@ http {
}
}

# external redirect
location /google.html {
return 301 http://www.google.com;
}

# internal redirect
location /old.html {
root html;
return 301 /new.html;
}


# internal redirect
location /old/ {
root html;
return 301 /new/;
}

location /dynamic/ {
limit_except GET POST {
deny all;
}
}

# upload
location /upload/ {
autoindex on;
client_max_body_size 20M;
Expand All @@ -71,8 +72,15 @@ http {
}
root html;
index index.html;
error_page 404 /a/b/c/404.html;

}

location /post_only/ {
limit_except POST {
deny all;
}
}

location /delete_only/ {
autoindex on;
Expand All @@ -83,6 +91,11 @@ http {
}
}

location /dynamic/ {
limit_except GET POST {
deny all;
}
}

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
Expand All @@ -93,7 +106,7 @@ http {
} # server


# CGI server
# CGI server ---------------------------------------------------------------
server {
listen 4343;
server_name cgi_server;
Expand All @@ -115,9 +128,9 @@ http {
deny all;
}

cgi_mode on;
cgi_extension py php sh;
cgi_timeout 3s;
cgi_mode on; # original; cgi_mode (on/off)
cgi_extension py php sh; # original; extension of cgi file
cgi_timeout 10s; # original; cgi process timeout (sec/min)
}

error_page 404 /404.html;
Expand All @@ -129,21 +142,25 @@ http {
} # server


# --------------------------------------------------------------------------
# port 4040: default_server -> new_server
# port 3939: no default_server -> upper server set to default
server { listen 4040;
server_name old_server;
location / { root html/old;
index index.html; } }
server { listen 4040 default_server;

server { listen 4040 default_server; # 4040 default
server_name new_server;
location / { root html/new;
index index.html; } }
server { listen 3939;

server { listen 3939; # 3939 default
listen 4040;
server_name server_a;
location / { root html/dir_a;
index index.html; } }

server { listen 3939;
listen 4040;
server_name server_b;
Expand Down
21 changes: 21 additions & 0 deletions html/cgi-bin/big_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3

import os


def header():
print('Content-Type: text/html')
print()


def main():
src_file = os.environ.get('QUERY_STRING', '')
file = open(f'html/big_size/{src_file}', 'r')
content = file.read()
print(content, end='')
file.close()


if __name__ == "__main__":
header()
main()
10 changes: 10 additions & 0 deletions html/cgi-bin/hello.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env perl

use strict;
use warnings;


print "Content-Type: text/html\n\n";
print "\n";

print "hello\n";
20 changes: 20 additions & 0 deletions html/cgi-bin/sleep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
import os
import time


def header():
print('Content-Type: text/html')
print()


def main():
query_string = os.environ.get('QUERY_STRING', '')
print(f'sleep {query_string} sec')
time.sleep(float(query_string))
print('fin')


if __name__ == "__main__":
header()
main()
38 changes: 24 additions & 14 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ <h3>GET</h3>
<li><a href="/dir_a/index.html">/dir_a/index.html</a>
<li><a href="/a/b/">/a/b/ -> /a/b/file_b.html</a>
<li><a href="/a/b/c/">/a/b/c/ -> /a/b/c/index.html</a>
<li><a href="/post_only/">/post_only/</a>
<li><a href="/delete_only/">/delete_only/ allow 127.0.0.1 -> ok?</a>
</ul>
<br>

<li> error page
<li> error page (404)
<ul>
<li><a href="/nothing.html">/nothing.html -> 404</a>
<li><a href="/a/b/c/nothing.html">/a/b/c/nothing.html -> 404</a>
<li><a href="/a/b/c/404.html">/a/b/c/404.html</a>
<li><a href="/nothing.html">/nothing.html -> /404.html</a>
<li><a href="/a/b/c/nothing.html">/a/b/c/nothing.html -> /404.html</a>
<li><a href="/a/b/c/nothing.html">/a/b/c/nothing.html -> /a/b/c/404.html</a>
</ul>
<br>

Expand All @@ -73,6 +74,7 @@ <h3>GET</h3>
<li><a href="/old.html">/old.html redirect to new.html</a>
<li><a href="/old/">/old/ redirect to html/new/</a>
<li><a href="/autoindex_files">/autoindex_files redirect to directory list</a>
<li><a href="/google.html">redirect to google.com</a>
</ul>
<br>

Expand All @@ -96,7 +98,8 @@ <h3>GET</h3>
<li><a href="http://localhost:4343/cgi-bin/error_no_shebang.py">error_no_shebang.py -> 500</a>
<li><a href="http://localhost:4343/cgi-bin/infinite_loop.py">infinite_loop.py -> 504</a>
<li><a href="http://localhost:4343/cgi-bin/infinite_print.py">infinite_print.py -> 504</a>
<li><a href="http://localhost:4343/cgi-bin/sleep10sec.py">sleep10sec.py -> 504</a>
<li><a href="http://localhost:4343/cgi-bin/sleep.py?1">sleep 1sec -> ok</a>
<li><a href="http://localhost:4343/cgi-bin/sleep.py?10">sleep 10sec -> 504</a>
</ul>
<br>

Expand All @@ -118,15 +121,15 @@ <h3>GET</h3>
value="curl -i -H &quot;Host: webserv&quot; localhost:4242">
</div>

<li> default server-1: localhost:4040 and nothing_server_name -> old_server or new_server
<li> default server-1: localhost:4040 and nothing_server_name -> old_server or new_server
<div class="container">
<button onclick="copyCommand('default_server_1')">copy</button>
<input type="text"
id="default_server_1"
value="curl -i -H &quot;Host: nothing_server_name&quot; localhost:4040">
</div>

<li> default server-2: localhost:3939 and nothing_server_name -> server_a or server_b
<li> default server-2: localhost:3939 and nothing_server_name -> server_a 🅰 or server_b
<div class="container">
<button onclick="copyCommand('default_server_2')">copy</button>
<input type="text"
Expand Down Expand Up @@ -155,33 +158,39 @@ <h3>GET</h3>
<button onclick="copyCommand('large_content')">copy</button>
<input type="text"
id="large_content"
value="curl -i -X GET -H &quot;Content-Length: 1&quot; --data &quot;larger than 1&quot; localhost:4242/cgi-bin/post_simple.py">
value="curl -i -X GET -H &quot;Content-Length: 1&quot; --data &quot;larger than 1&quot; localhost:4343/cgi-bin/post_simple.py">
</div>

<li> Content less than Content-Length -> connection closed by host
<div class="container">
<button onclick="copyCommand('small_content')">copy</button>
<input type="text"
id="small_content"
value="curl -i -X GET -H &quot;Content-Length: 100&quot; --data &quot;less than 100&quot; localhost:4242/cgi-bin/post_simple.py">
value="curl -i -X GET -H &quot;Content-Length: 100&quot; --data &quot;less than 100&quot; localhost:4343/cgi-bin/post_simple.py">
</div>

<li> Content-Length too large by Length
<div class="container">
<button onclick="copyCommand('content_length_large')">copy</button>
<input type="text"
id="content_length_large"
value="curl -i -H &quot;Content-Length: 2147483647&quot; localhost:4242/cgi-bin/post_simple.py">
value="curl -i -H &quot;Content-Length: 2147483647&quot; localhost:4343/cgi-bin/post_simple.py">
</div>

</ul>
<br>

<li> Siege test
<div class="container">
<button onclick="copyCommand('get_x')">copy</button>
<button onclick="copyCommand('brew_install')">copy</button>
<input type="text"
id="get_x"
id="brew_install"
value="brew install siege">
</div>
<div class="container">
<button onclick="copyCommand('siege_command')">copy</button>
<input type="text"
id="siege_command"
value="siege --benchmark --concurrent=128 --time=30s http://localhost:4242">
</div>

Expand Down Expand Up @@ -232,7 +241,7 @@ <h3>POST</h3>
<button onclick="copyCommand('post_body')">copy</button>
<input type="text"
id="post_body"
value="curl -i -X POST --data &quot;request body is recognized&quot; localhost:4242/cgi-bin/post_simple.py">
value="curl -i -X POST --data &quot;request body is recognized&quot; localhost:4343/cgi-bin/post_simple.py">
</div>
</ul>
</ul>
Expand Down Expand Up @@ -268,7 +277,8 @@ <h3>DELETE</h3>

<h3>Bonus</h3>
<ul>
<li><a href="http://localhost:4343/cgi-bin/hello.sh">hello.sh</a>
<li><a href="http://localhost:4343/cgi-bin/hello.sh">CGI(hello.sh)</a>
<li><a href="http://localhost:4343/cgi-bin/hello.pl">CGI(hello.pl)</a>
<li><a href="/dynamic/cookie-login">Login (cookie)</a>
<li><a href="/dynamic/session-login">Login (session)</a>
</ul>
Expand Down
1 change: 1 addition & 0 deletions html/redirect_to_google.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
redirect to google.com
Loading

0 comments on commit 6bce3d1

Please sign in to comment.