Skip to content

Commit

Permalink
Merge pull request #100 from ak0327/feature/test
Browse files Browse the repository at this point in the history
refactor
  • Loading branch information
ak0327 authored Mar 8, 2024
2 parents 6bce3d1 + fb72f4d commit c2e89b6
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 395 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D UNIT_TEST")

# LOCAL -----
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D DEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D USE_SELECT")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D USE_POLL")
# -----------

if(DEFINED CUSTOM_FLAGS)
Expand Down
16 changes: 6 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ NAME = webserv
CXX = c++
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -MMD -MP -pedantic
#CXXFLAGS += -g -fsanitize=address,undefined -fno-omit-frame-pointer
CXXFLAGS += -D USE_SELECT
#CXXFLAGS += -D USE_POLL
CXXFLAGS += -D DEBUG
#CXXFLAGS += -D DEBUG

# SRCS -------------------------------------------------------------------------
SRCS_DIR = srcs
Expand Down Expand Up @@ -207,9 +205,6 @@ RESPONSE_INCLUDES = $(SRCS_DIR)/$(RESPONSE_DIR) \
.PHONY : all
all : $(NAME)

.PHONY : bonus
all : $(NAME)

$(NAME) : $(OBJS)
$(CXX) $(CXXFLAGS) -o $@ $^

Expand All @@ -230,6 +225,9 @@ fclean : clean
.PHONY : re
re : fclean all

.PHONY : bonus
bonus : all

.PHONY : lint
lint :
python3 -m cpplint --recursive srcs \
Expand All @@ -240,8 +238,7 @@ lint :
run_unit_test :
. test/integration/prepare_test_file.sh; prepare_test_file
#cmake -S . -B build
# cmake -S . -B build -DCUSTOM_FLAGS="-D USE_SELECT"
cmake -S . -B build -DCUSTOM_FLAGS="-D USE_SELECT -D DEBUG"
cmake -S . -B build -DCUSTOM_FLAGS="-D DEBUG"
cmake --build build
# ./build/unit_test 2>/dev/null
./build/unit_test test/integration/integration_test.conf # leaks report
Expand All @@ -254,8 +251,7 @@ run_integration_test :

.PHONY : run_server_test
run_server_test :
cmake -S . -B build -DCUSTOM_FLAGS="-D USE_SELECT -D DEBUG"
#cmake -S . -B build -DCUSTOM_FLAGS="-D USE_SELECT "
cmake -S . -B build -DCUSTOM_FLAGS="-D DEBUG"
#cmake -S . -B build -DCUSTOM_FLAGS="-D DEBUG -D USE_SELECT"
cmake --build build
#./build/unit_test --gtest_filter=Server* 2>/dev/null
Expand Down
2 changes: 1 addition & 1 deletion conf/webserv.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
http {
recv_timeout 30s; # original; combined client_header_timeout and client_body_timeout
send_timeout 10s;
keepalive_timeout 30s; # 0: disable keep-alive
keepalive_timeout 20s; # 0: disable keep-alive

# static file server -------------------------------------------------------
server {
Expand Down
1 change: 1 addition & 0 deletions html/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

!*.html
!*.txt
!ng_type.ng

# test file
html/permission
Expand Down
29 changes: 29 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,35 @@ <h3>POST</h3>
value="diff html/images/image1.jpg html/upload/image1.jpg">
</div>

<li> upload within limits; 19MB
<div class="container">
<button onclick="copyCommand('prepare')">copy</button>
<input type="text"
id="prepare"
value="chmod +x test/integration/prepare_test_file.sh; . test/integration/prepare_test_file.sh; create_big_size_files">
</div>
<div class="container">
<button onclick="copyCommand('post_within_limits')">copy</button>
<input type="text"
id="post_within_limits"
value="curl -i -F &quot;file_name=@html/big_size/19MB.txt&quot; localhost:4242/upload/">
</div>
<div class="container">
<button onclick="copyCommand('diff_within_limits')">copy</button>
<input type="text"
id="diff_within_limits"
value="diff html/big_size/19MB.txt html/upload/19MB.txt">
</div>

<li> upload over limits; 20MB
<div class="container">
<button onclick="copyCommand('post_over_limits')">copy</button>
<input type="text"
id="post_over_limits"
value="curl -i -F &quot;file_name=@html/big_size/20MB.txt&quot; localhost:4242/upload/">
</div>


<li> post request body
<div class="container">
<button onclick="copyCommand('post_body')">copy</button>
Expand Down
1 change: 1 addition & 0 deletions html/ng_type.ng
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ng type
14 changes: 7 additions & 7 deletions srcs/HttpResponse/Dynamic/cookie_login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@


bool HttpResponse::is_logged_in_user() {
std::cout << RED << "is_logged_in_user" << RESET << std::endl;
// std::cout << RED << "is_logged_in_user" << RESET << std::endl;
Result<std::map<std::string, std::string>, ProcResult> result = this->request_.get_cookie();
if (result.is_err()) {
std::cout << RED << " get_cookie failue" << RESET << std::endl;
// std::cout << RED << " get_cookie failue" << RESET << std::endl;
return false;
}
std::map<std::string, std::string> cookies = result.ok_value();
Expand All @@ -35,10 +35,10 @@ bool HttpResponse::is_logged_in_user() {
return false;
}
if (cookie_expire <= now) {
std::cout << RED << "expired -> cookie: " << expire->second << ", now: " << now_date << RESET << std::endl;
// std::cout << RED << "expired -> cookie: " << expire->second << ", now: " << now_date << RESET << std::endl;
return false;
}
std::cout << RED << "not expire -> cookie: " << expire->second << ", now: " << now_date << RESET << std::endl;
// std::cout << RED << "not expire -> cookie: " << expire->second << ", now: " << now_date << RESET << std::endl;
}
return true;
}
Expand Down Expand Up @@ -77,10 +77,10 @@ std::string HttpResponse::get_expire_from_cookie() {


StatusCode HttpResponse::get_cookie_user_page() {
std::cout << RED << " get_cookie_user_page()" << RESET << std::endl;
// std::cout << RED << " get_cookie_user_page()" << RESET << std::endl;

if (is_logged_in_user()) {
std::cout << RED << " logged_in_user" << RESET << std::endl;
// std::cout << RED << " logged_in_user" << RESET << std::endl;
const std::string head = "<!doctype html>\n"
"<html lang=\"ja\">\n"
"<head>\n"
Expand Down Expand Up @@ -109,7 +109,7 @@ StatusCode HttpResponse::get_cookie_user_page() {
add_content_header("html");
return StatusOk;
} else {
std::cout << RED << " inactive user" << RESET << std::endl;
// std::cout << RED << " inactive user" << RESET << std::endl;

ReturnDirective redirect_to_login;
redirect_to_login.return_on = true;
Expand Down
3 changes: 2 additions & 1 deletion srcs/HttpResponse/HttpResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ ProcResult HttpResponse::send_request_body_to_cgi() {
if (result == Continue) {
return Continue;
}
shutdown(this->cgi_write_fd(), SHUT_WR);
this->cgi_handler_.close_write_fd();
// shutdown(this->cgi_write_fd(), SHUT_WR);
DEBUG_PRINT(YELLOW, "shutdown cgi write_fd");
if (result == Failure) {
StatusCode error_code = InternalServerError;
Expand Down
Loading

0 comments on commit c2e89b6

Please sign in to comment.