Skip to content

Commit 9f989d3

Browse files
committed
chore: add HTTP/2 tests
1 parent 6001b02 commit 9f989d3

File tree

3 files changed

+73
-32
lines changed

3 files changed

+73
-32
lines changed

.github/workflows/verifyimage.yml

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,92 @@ jobs:
8888
README.md \
8989
"${{ matrix.target }}.env"
9090
echo "Starting container ${{ matrix.target }}-verification"
91+
# The backend is a dummy
9192
docker run \
9293
--pull "never" \
9394
-d \
9495
--name ${{ matrix.target }}-test \
9596
--env-file "${{ matrix.target }}.env" \
97+
-p 8080:8080 \
98+
-e BACKEND=http://localhost:9999 \
9699
"${{ matrix.target }}-verification"
97-
sleep 30
98-
docker logs ${{ matrix.target }}-test
99100
100101
- name: Verify ${{ matrix.target }}
101102
run: |
102-
[ $(docker inspect ${{ matrix.target }}-test --format='{{.State.Running}}') = 'true' ]
103-
if grep -q "nginx "<<< "${{ matrix.target }}"; then
104-
curl -q -D headers.txt http://localhost:8080/?test=../../etc/passwd
103+
HOST_AND_PORT="localhost:8080"
104+
counter=10
105+
while true; do
106+
printf "Checking whether container is running..."
107+
if [ $(docker inspect ${{ matrix.target }}-test --format='{{.State.Running}}') = 'true' ]; then
108+
echo "ok"
109+
printf "Trying to connect..."
110+
if curl -s --connect-timeout 5 --max-time 1 "${HOST_AND_PORT}" > /dev/null 2>&1; then
111+
echo "ok"
112+
break
113+
fi
114+
fi
115+
116+
echo "failed"
117+
((counter--))
118+
if [ ${counter} -gt 0 ]; then
119+
echo "Will retry in 5 seconds"
120+
sleep 5
121+
else
122+
printf "No more retries. Here'se the log output from the container\n\n\n"
123+
docker logs ${{ matrix.target }}-test
124+
exit 1
125+
fi
126+
done
127+
128+
if grep -q "nginx"<<< "${{ matrix.target }}"; then
129+
printf "\n\n### nginx tests ###\n\n"
130+
131+
printf "Storing headers for sample attack..."
132+
curl -s -D headers.txt -o /dev/null "${HOST_AND_PORT}/?test=../../etc/passwd"
133+
printf "...done\n\n\n"
134+
135+
printf "Check status 403..."
105136
grep -q "HTTP/1.1 403 Forbidden" headers.txt
137+
printf yes\n\n\n"
138+
139+
printf "Check 'Access-Control-Allow-Origin' header..."
106140
grep -q "Access-Control-Allow-Origin: *" headers.txt
141+
printf yes\n\n\n"
142+
143+
printf "Check 'Access-Control-Max-Age' header..."
107144
grep -q "Access-Control-Max-Age: 3600" headers.txt
145+
printf yes\n\n\n"
146+
147+
printf "Check 'Access-Control-Allow-Methods' header..."
108148
grep -q "Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS" headers.txt
149+
printf yes\n\n\n"
150+
151+
printf "Check 'Access-Control-Allow-Headers'..."
109152
grep -q "Access-Control-Allow-Headers: *" headers.txt
153+
printf yes\n\n\n"
154+
155+
echo "### nginx tests - done ###"
110156
fi
111157
158+
printf "\n\n### generic tests ###\n\n"
159+
160+
echo "Test HTTP/2 upgrade..."
161+
curl -v --http2 --no-progress-meter -o /dev/null "${HOST_AND_PORT}" 2>&1 | tee out.txt
162+
grep -iP "< 101 Switching Protocols|< HTTP/2" < out.txt | tee out2.txt
163+
wc -l out2.txt | grep -qoP "\d+" | xargs -I % test % -eq 2
164+
rm out*.txt
165+
printf ...yes\n\n\n"
166+
167+
echo "Test HTTP/2 prior knowledge..."
168+
curl -v --http2-prior-knowledge --no-progress-meter -o /dev/null "${HOST_AND_PORT}"
169+
curl -v --http2-prior-knowledge --no-progress-meter -o /dev/null "${HOST_AND_PORT}" 2>&1 | tee out.txt
170+
grep --help
171+
grep -i "< HTTP/2" out.txt
172+
grep -iv "< 101 Switching Protocols" out.txt
173+
printf ...yes\n\n\n"
174+
175+
echo "### generic tests - done ###"
176+
112177
- name: Checkout CRS
113178
uses: actions/checkout@v4
114179
with:

apache/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ENV \
7171
APACHE_ERRORLOG_FORMAT='"[%{u}t] [%-m:%l] [pid %P:tid %T] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i"' \
7272
APACHE_LOGFORMAT='"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' \
7373
APACHE_METRICS_LOGFORMAT='"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""' \
74-
BACKEND=http://localhost:8080 \
74+
BACKEND=http://localhost:80 \
7575
BACKEND_WS=ws://localhost:8081 \
7676
ERRORLOG='/proc/self/fd/2' \
7777
H2_DIRECT=on \

docker-compose.yaml

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
# This docker-compose file starts owasp/modsecurity-crs
2-
#
3-
# ATTENTION!
4-
# Some of the environment variables at the bottom of this
5-
# docker-compose.yaml file and TLS are only available
6-
# for self-built images based on Dockerfile-2.9-apache,
7-
# and only if build args SETTLS and SETPROXY were set during
8-
# the build of the parent owasp/modsecurity:2.9-apache image.
9-
102
x-defaults: &default-settings
113
environment:
124
SERVERNAME: localhost
@@ -29,18 +21,6 @@ x-defaults: &default-settings
2921
# New in CRS 4
3022
REPORTING_LEVEL: 2
3123

32-
#######################################################
33-
# Reverse Proxy mode
34-
# (only available if SETPROXY was enabled during the
35-
# parent ModSecurity image)
36-
#######################################################
37-
# PROXYLOCATION: Application Backend of Reverse Proxy
38-
# PROXYLOCATION: http://app:8000/
39-
#
40-
# If needed: add own httpd-proxy.conf (only available if SETPROXY
41-
# was enabled during build of parent ModSecurity image)
42-
# - ./httpd-proxy.conf:/usr/local/apache2/conf/extra/httpd-proxy.conf
43-
4424
#######################################################
4525
# Various CRS Variables with Default Values
4626
#######################################################
@@ -73,8 +53,6 @@ x-defaults: &default-settings
7353

7454
#######################################################
7555
# Add TLS server certificate and key
76-
# (only available if SETPROXY was enabled during the
77-
# parent ModSecurity image)
7856
#######################################################
7957
# - ./server.crt:/usr/local/apache2/conf/server.crt
8058
# - ./server.key:/usr/local/apache2/conf/server.key
@@ -83,15 +61,13 @@ services:
8361
crs-apache:
8462
image: owasp/modsecurity-crs:apache
8563
ports:
86-
- "80:8080"
87-
# only available if SETTLS was enabled:
64+
- "8080:8080"
8865
- "443:8443"
8966
<<: *default-settings
9067

9168
crs-nginx:
9269
image: owasp/modsecurity-crs:nginx
9370
ports:
94-
- "80:8080"
95-
# only available if SETTLS was enabled:
71+
- "8080:8080"
9672
- "443:8443"
9773
<<: *default-settings

0 commit comments

Comments
 (0)