Skip to content

custom-https-server CI #7

custom-https-server CI

custom-https-server CI #7

Workflow file for this run

# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: custom-https-server CI
on:
workflow_dispatch:
schedule:
- cron: "0 9 1 * *"
jobs:
test-server:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip install psutil requests
- name: Test server on port 8080
working-directory: ./custom-https-server
run: |
set -e
# Launch server in background
python3 custom_https_server.py --path . --port 8080 > /tmp/server.log 2>&1 &
SERVER_PID=$!
echo "Server PID: $SERVER_PID"
# Give server time to start and generate certificates
echo "Waiting for server to start..."
sleep 10
# Check if server is running
if ! ps -p $SERVER_PID > /dev/null; then
echo "❌ Server failed to start"
echo "=== Server logs ==="
cat /tmp/server.log
exit 1
fi
echo "✅ Server process is running"
echo "=== Server logs ==="
cat /tmp/server.log
# Check port binding
echo -e "\n=== Checking port binding ==="
netstat -tlnp 2>/dev/null | grep 8080 || echo "Port check not available"
# Test with verbose output on 0.0.0.0 (localhost binding)
echo -e "\n=== Testing HTTPS on localhost:8080 ==="
if curl -k -v --max-time 10 https://localhost:8080 2>&1 | tee /tmp/curl.log; then
echo "✅ Server responding to requests"
else
CURL_CODE=$?
echo "⚠️ Curl failed with code: $CURL_CODE (trying 0.0.0.0)"
# Try 0.0.0.0 directly
if curl -k -v --max-time 10 https://0.0.0.0:8080 2>&1 | tee /tmp/curl2.log; then
echo "✅ Server responding on 0.0.0.0"
else
echo "❌ Both localhost and 0.0.0.0 failed"
cat /tmp/curl.log
cat /tmp/curl2.log
kill $SERVER_PID 2>/dev/null || true
exit 1
fi
fi
kill $SERVER_PID 2>/dev/null || true
- name: Test server on port 8081 with file serving
run: |
set -e
# Create test file
echo "Hello from /tmp" > /tmp/test.txt
# Launch server in background
python3 ./custom-https-server/custom_https_server.py --path /tmp --port 8081 > /tmp/server8081.log 2>&1 &
SERVER_PID=$!
echo "Server PID: $SERVER_PID"
# Give server time to start
sleep 10
# Check if server is running
if ! ps -p $SERVER_PID > /dev/null; then
echo "❌ Server failed to start"
echo "=== Server logs ==="
cat /tmp/server8081.log
exit 1
fi
echo "✅ Server process is running"
# Test file serving with HTTPS on localhost
echo -e "\n=== Testing file serving on localhost:8081 ==="
if curl -k -v --max-time 10 https://localhost:8081/test.txt 2>&1 | tee /tmp/curl8081.log; then
echo "✅ File served successfully"
else
CURL_CODE=$?
echo "⚠️ localhost failed with code: $CURL_CODE (trying 0.0.0.0)"
# Try 0.0.0.0 directly
if curl -k -v --max-time 10 https://0.0.0.0:8081/test.txt 2>&1 | tee /tmp/curl8081b.log; then
echo "✅ File served successfully on 0.0.0.0"
else
echo "❌ File serving failed on both localhost and 0.0.0.0"
cat /tmp/curl8081.log
kill $SERVER_PID 2>/dev/null || true
exit 1
fi
fi
kill $SERVER_PID 2>/dev/null || true
- name: Test with authentication
run: |
set -e
# Launch server with basic auth in background
python3 ./custom-https-server/custom_https_server.py \
--path /tmp --port 8082 --user testuser --pass testpass &
SERVER_PID=$!
echo "Server PID: $SERVER_PID"
sleep 5
# Test without auth (should fail)
echo "Testing without authentication..."
HTTP_CODE=$(curl -k --silent --output /dev/null --write-out "%{http_code}" \
--max-time 5 https://127.0.0.1:8082 2>/dev/null || echo "000")
if [ "$HTTP_CODE" == "401" ]; then
echo "✅ Correctly rejected unauthenticated request"
else
echo "⚠️ Unexpected response code: $HTTP_CODE (expected 401)"
fi
# Test with auth (should succeed)
echo "Testing with authentication..."
HTTP_CODE=$(curl -k --silent --output /dev/null --write-out "%{http_code}" \
--user testuser:testpass --max-time 5 \
https://127.0.0.1:8082 2>/dev/null || echo "000")
if [ "$HTTP_CODE" == "200" ]; then
echo "✅ Authentication successful"
else
echo "⚠️ Auth test returned code: $HTTP_CODE"
fi
kill $SERVER_PID 2>/dev/null || true