Skip to content

Commit

Permalink
tests(multi socket Ipv6): fix requests in test IPv6.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
552020 committed May 18, 2024
1 parent 8ec5b5c commit be27114
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 22 deletions.
20 changes: 8 additions & 12 deletions tests/multi_sockets/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,14 @@ FROM ubuntu:20.04

# Install necessary packages
RUN apt-get update && \
apt-get install -y build-essential curl vim
apt-get install -y build-essential curl vim iproute2 net-tools

# Set the working directory
WORKDIR /app

# Copy the entire project into the container
# Copy the entire project into the containerenet-tools
COPY . .


# List the contents of the /app directory to verify the presence of the Makefile
RUN echo "Contents of /app:" && ls -al /app

# List the contents of the tests directory to verify the structure
RUN echo "Contents of /app/tests:" && ls -al /app/tests

# List the contents of the multi_sockets directory to verify the structure
RUN echo "Contents of /app/tests/multi_sockets:" && ls -al /app/tests/multi_sockets

# Compile the project in the root directory where the Makefile is located
RUN make re -C /app
# Compile the project
Expand All @@ -33,6 +23,12 @@ WORKDIR /app/tests/multi_sockets
RUN chmod +x testIPv4.sh
RUN chmod +x testIPv6.sh
RUN chmod +x testIPv4+IPv6.sh
RUN chmod +x test_mixed.sh

# Enable IPv6 in the container
RUN sysctl -w net.ipv6.conf.all.disable_ipv6=0 && \
sysctl -w net.ipv6.conf.default.disable_ipv6=0 && \
sysctl -w net.ipv6.conf.lo.disable_ipv6=0

# Just start the shell
CMD ["/bin/bash"]
34 changes: 34 additions & 0 deletions tests/multi_sockets/multi_socket.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,40 @@ We send requests to:
- `127.0.0.3:8080`: "000"
- `127.0.0.1:8081`: "404"

### Docker IPv6 Setup Guide

#### 0. Enable IPv6 in Docker

To enable IPv6 support in Docker, follow these steps:

1. **Edit Docker daemon configuration**:
Edit the `/etc/docker/daemon.json` file to include the necessary IPv6 parameters:

```json
{
"ipv6": true,
"fixed-cidr-v6": "2001:db8:1::/64",
"experimental": true,
"ip6tables": true
}
```

Step 1 on Mac needs to be done in the Desktop app > Settings > Engine

2. **Restart Docker**:
Save the configuration file and restart the Docker daemon for the changes to take effect:

```sh
sudo systemctl restart docker
```

3. **Create an IPv6 network**:
Create a Docker network that uses IPv6:

```sh
docker network create --ipv6 --subnet 2001:db8:1::/64 ip6net
```

#### 1. Build the Docker Image

From the root of `webserv`:
Expand Down
9 changes: 0 additions & 9 deletions tests/multi_sockets/results.txt

This file was deleted.

33 changes: 32 additions & 1 deletion tests/multi_sockets/testIPv6.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Install net-tools if not present
if ! command -v netstat &> /dev/null; then
echo "Installing net-tools..."
apt-get update && apt-get install -y net-tools
fi

# Check if the webserv binary exists
if [ ! -f ./../../webserv ]; then
echo -e "${RED}Error: webserv binary not found!${NC}"
Expand All @@ -29,6 +35,18 @@ if ! ps -p $SERVER_PID > /dev/null; then
exit 1
fi

# Verify server is listening on the expected address and port
echo "Checking server listening ports..."
netstat -tuln | grep 8081 >> netstat_results.txt
netstat -tuln | grep 8080 >> netstat_results.txt
netstat -tuln | grep 8082 >> netstat_results.txt

# Check IPv6 configuration
echo "IPv6 configuration:"
ip -6 addr > ipv6_config.txt
ip -6 route >> ipv6_config.txt


# Function to store response
store_response() {
local url=$1
Expand All @@ -43,7 +61,8 @@ store_response() {

# Run curl commands and store responses
store_response "[::1]:8080" "404"
store_response "[::]:8081" "404"
# store_response "[::]:8081" "404"
store_response "[::0]:8081" "404"
store_response "[::1]:8082" "404"
store_response "[::2]:8080" "000"
store_response "[::3]:8080" "000"
Expand All @@ -58,4 +77,16 @@ echo "Test results:"
cat results.txt
rm results.txt

# Print netstat results
echo "Netstat results:"
cat netstat_results.txt
rm netstat_results.txt

# Print IPv6 configuration
echo "IPv6 configuration:"
cat ipv6_config.txt
rm ipv6_config.txt



echo "Test script completed."

0 comments on commit be27114

Please sign in to comment.