From ff2b4ec9c3fa80ab06ed1556030163db5ad3317a Mon Sep 17 00:00:00 2001 From: Pedro Ferreira Date: Thu, 26 Feb 2026 09:05:47 +0000 Subject: [PATCH 1/3] fix(localhost): add unit tests --- subjects/localhost/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/subjects/localhost/README.md b/subjects/localhost/README.md index a2f05eefbd..85635204b2 100644 --- a/subjects/localhost/README.md +++ b/subjects/localhost/README.md @@ -78,6 +78,15 @@ In the file you should be able to specify the following: > Attention: `siege` is a stressing tool, use it ONLY to test your own server. Do **NEVER** use it on any server/website without the owner's permission. If you do so you would have illegally DDoSed a server and could face serious troubles. +### Unit Tests + +You must implement unit tests within your `Localhost` project to ensure your protocol parsing and configuration logic are robust. Specifically, your tests should: + +- Verify **HTTP Request Parsing** by ensuring headers, methods (GET, POST, DELETE), and body content (including chunked encoding) are correctly extracted from raw byte streams. +- Verify **Configuration Validation** by ensuring the server correctly identifies conflicting ports, invalid paths, and out-of-bounds body size limits during startup. +- Test **Route Matching** logic to confirm that requests are mapped to the correct directory roots, CGI scripts, or redirections based on the configuration file. +- Verify **Status Code Generation** by ensuring the internal logic returns the correct `4xx` or `5xx` codes for malformed requests or missing files before the response is sent. + ### Bonus - Handle at least one more `CGI`. - Rewrite the project in another programming language (can be `C++` or `C`). From 06a7ad2e3defb0b87c27f127e0e9f3900885b50d Mon Sep 17 00:00:00 2001 From: Pedro Ferreira Date: Thu, 26 Feb 2026 09:07:06 +0000 Subject: [PATCH 2/3] fix(localhost): add unit tests --- subjects/localhost/audit/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/subjects/localhost/audit/README.md b/subjects/localhost/audit/README.md index c08a6cc3de..91e10a4fac 100644 --- a/subjects/localhost/audit/README.md +++ b/subjects/localhost/audit/README.md @@ -97,6 +97,16 @@ You'll configure multiple servers simultaneously, each with different configurat ###### Check if there is no hanging connection. +#### Unit Tests + +###### Do all tests pass without errors? + +###### Are there specific tests for **HTTP Request Parsing** (e.g., verifying that headers and chunked bodies are correctly parsed)? + +###### Are there tests for **Configuration Validation** (e.g., checking that the server detects duplicate ports or invalid routes)? + +###### Are there tests for **Route Matching** to ensure requests are directed to the correct handlers or CGI scripts? + #### General ###### +There's more than one CGI system such as [Python,C++,Perl]. From a586c6b211c57ecd0d1f638bb0f2efebfa9e3a45 Mon Sep 17 00:00:00 2001 From: Pedro Ferreira Date: Mon, 2 Mar 2026 10:52:30 +0000 Subject: [PATCH 3/3] fix(localhost): prettier --- subjects/localhost/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/subjects/localhost/README.md b/subjects/localhost/README.md index 85635204b2..5096592ce2 100644 --- a/subjects/localhost/README.md +++ b/subjects/localhost/README.md @@ -6,7 +6,6 @@ This protocol is used by servers and clients (usually browsers) to serve content Here you will learn the basics of the protocol and a good place to start could be the [HTTP/1.1 RFC](https://www.rfc-editor.org/rfc/rfc9112.html). - ### Instructions - The project must be written in `Rust`. @@ -20,6 +19,7 @@ Here you will learn the basics of the protocol and a good place to start could b You goal is to write your very own server, which will use `HTTP` protocol to serve static web pages to browsers. For your server you must guarantee the following behavior: + - It **never** crashes. - All requests timeout if they are taking too long. - It can listen on multiple ports and instantiate multiple servers at the same time. @@ -39,13 +39,14 @@ For your server you must guarantee the following behavior: - You should set the right status for each response. #### The CGI + - Based on the file extension the server will execute the corresponding `CGI` (for example `.php` or `.py`). - You need to implement only one `CGI` of your choice. - You are allowed to fork a new process to run the `CGI`. - `CGI` expects the file to process as first argument and `EOF` as end of the body. - Pay attention to the directory where the `CGI` will run for correct relative paths handling. - The `CGI` will check `PATH_INFO` environment variable to define the full path. - + #### Configuration File In the file you should be able to specify the following: @@ -69,6 +70,7 @@ In the file you should be able to specify the following: > There is no need to pass through `epoll` when reading the configuration file. #### Testing your server + - Do stress tests with `siege -b [IP]:[PORT]`, it must stay available at all costs (availability should be up to 99.5, it will be tested during audits). - Create tests for as many cases as you can (redirections, bad configuration files, static and dynamic pages, default error pages and so on). - You will be requested to provide and explain your tests during the audits. @@ -88,5 +90,6 @@ You must implement unit tests within your `Localhost` project to ensure your pro - Verify **Status Code Generation** by ensuring the internal logic returns the correct `4xx` or `5xx` codes for malformed requests or missing files before the response is sent. ### Bonus + - Handle at least one more `CGI`. - Rewrite the project in another programming language (can be `C++` or `C`).