Skip to content

Commit

Permalink
Replace mirror.cgi with Python
Browse files Browse the repository at this point in the history
The ordering of "echo" and "cat" output was messed up in CI on Alpine
and Fedora, apparently sh (unlike bash) doesn't ensure order in
stdout.
  • Loading branch information
airtower-luna committed Apr 7, 2024
1 parent ef1a29c commit d644ea7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
30 changes: 14 additions & 16 deletions test/data/secret/mirror.cgi → test/data/secret/mirror.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh
#!/usr/bin/python3
#
# Mirror CGI script: Return the request body to the sender
#
# Copyright 2020 Fiona Klute
# Copyright 2024 Fiona Klute
#
# Licensed under the Apache License, Version 2.0 (the "License"); you
# may not use this file except in compliance with the License. You
Expand All @@ -15,18 +15,16 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
import os
import sys

case "${REQUEST_METHOD}" in
("POST")
echo "Status: 200 OK"
# mirror the incoming content type
echo "Content-Type: ${CONTENT_TYPE}\n"
# return the incoming data
cat -
;;
(*)
echo "Status: 405 Method Not Allowed"
echo "Content-Type: text/plain\n"
echo "Unsupported HTTP method."
;;
esac
if os.environ['REQUEST_METHOD'] == 'POST':
# mirror the incoming content type
print('Status: 200 OK\n'
f'Content-Type: {os.environ["CONTENT_TYPE"]}\n')
for line in sys.stdin:
print(line, end='')
else:
print('Status: 405 Method Not Allowed\n'
'Content-Type: text/plain\n\n'
'Unsupported HTTP method.')
1 change: 1 addition & 0 deletions test/tests/35_client_reauth/apache.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ GnuTLSCache ${DEFAULT_CACHE}

<Directory ${srcdir}/data/>
Options +ExecCGI
AddHandler cgi-script .py
</Directory>

<VirtualHost _default_:${TEST_PORT}>
Expand Down
6 changes: 5 additions & 1 deletion test/tests/35_client_reauth/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
test
- !request
method: POST
path: /secret/mirror.cgi
path: /secret/mirror.py
headers:
'Content-Type': 'text/plain'
body: |
GNUTLS_E_GOT_APPLICATION_DATA can (randomly, depending on
timing) happen with a request containing a body. According to
Expand All @@ -27,6 +29,8 @@
is appropriate.
expect:
status: 200
headers:
'Content-Type': 'text/plain'
body:
exactly: |
GNUTLS_E_GOT_APPLICATION_DATA can (randomly, depending on
Expand Down

0 comments on commit d644ea7

Please sign in to comment.