mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
Add tests for --forward-https.
This commit is contained in:
parent
4fd6a1067c
commit
1759a7a7d9
@ -119,6 +119,15 @@ runtests() {
|
|||||||
kill $PID
|
kill $PID
|
||||||
wait $PID
|
wait $PID
|
||||||
|
|
||||||
|
echo "===> run --forward-https tests"
|
||||||
|
./a.out $DIR --port $PORT --forward-https \
|
||||||
|
>>test.out.stdout 2>>test.out.stderr &
|
||||||
|
PID=$!
|
||||||
|
kill -0 $PID || exit 1
|
||||||
|
python3 test_forward_https.py
|
||||||
|
kill $PID
|
||||||
|
wait $PID
|
||||||
|
|
||||||
if [[ -s test.out.stderr ]]; then
|
if [[ -s test.out.stderr ]]; then
|
||||||
echo "FAIL: stderr should have been empty."
|
echo "FAIL: stderr should have been empty."
|
||||||
exit 1
|
exit 1
|
||||||
|
34
devel/test_forward_https.py
Executable file
34
devel/test_forward_https.py
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# This is run by the "run-tests" script.
|
||||||
|
import unittest
|
||||||
|
from test import TestHelper, Conn, parse
|
||||||
|
|
||||||
|
class TestForward(TestHelper):
|
||||||
|
def test_without_header(self):
|
||||||
|
resp = self.get('/', req_hdrs={'Host': 'example.com'})
|
||||||
|
status, hdrs, body = parse(resp)
|
||||||
|
self.assertContains(status, '200 OK')
|
||||||
|
|
||||||
|
def test_https_redirect(self):
|
||||||
|
resp = self.get('/foo/bar', req_hdrs={
|
||||||
|
'Host': 'example.com',
|
||||||
|
'X-Forwarded-Proto': 'http',
|
||||||
|
})
|
||||||
|
status, hdrs, body = parse(resp)
|
||||||
|
self.assertContains(status, '301 Moved Permanently')
|
||||||
|
expect = 'https://example.com/foo/bar'
|
||||||
|
self.assertEqual(hdrs['Location'], expect)
|
||||||
|
self.assertContains(body, expect)
|
||||||
|
|
||||||
|
def test_no_redirect(self):
|
||||||
|
resp = self.get('/', req_hdrs={
|
||||||
|
'Host': 'example.com',
|
||||||
|
'X-Forwarded-Proto': 'https', # Already https.
|
||||||
|
})
|
||||||
|
status, hdrs, body = parse(resp)
|
||||||
|
self.assertContains(status, '200 OK')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
|
# vim:set ts=4 sw=4 et:
|
Loading…
Reference in New Issue
Block a user