mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
Test URL escaping in directory listing.
This commit is contained in:
parent
b7038c8329
commit
897e85a46e
@ -3,6 +3,9 @@ import unittest
|
|||||||
import socket
|
import socket
|
||||||
import signal
|
import signal
|
||||||
import re
|
import re
|
||||||
|
import os
|
||||||
|
|
||||||
|
WWWROOT = "tmp.httpd.tests"
|
||||||
|
|
||||||
class Conn:
|
class Conn:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -11,7 +14,7 @@ class Conn:
|
|||||||
self.s.connect(("0.0.0.0", self.port))
|
self.s.connect(("0.0.0.0", self.port))
|
||||||
# connect throws socket.error on connection refused
|
# connect throws socket.error on connection refused
|
||||||
|
|
||||||
def get(self, url, http_ver=None, endl="\n",
|
def get(self, url, http_ver="1.0", endl="\n",
|
||||||
req_hdrs={"User-Agent": "test.py"}):
|
req_hdrs={"User-Agent": "test.py"}):
|
||||||
req = "GET "+url
|
req = "GET "+url
|
||||||
if http_ver is not None:
|
if http_ver is not None:
|
||||||
@ -66,6 +69,17 @@ class TestCases(unittest.TestCase):
|
|||||||
"You requested an invalid URL: %s\n"%path,
|
"You requested an invalid URL: %s\n"%path,
|
||||||
'Generated by darkhttpd')
|
'Generated by darkhttpd')
|
||||||
|
|
||||||
|
def test_dirlist_escape(self):
|
||||||
|
fn = WWWROOT+"/escape#this"
|
||||||
|
open(fn, "w").write("x"*12345)
|
||||||
|
try:
|
||||||
|
resp = Conn().get("/")
|
||||||
|
finally:
|
||||||
|
os.unlink(fn)
|
||||||
|
status, hdrs, body = parse(resp)
|
||||||
|
self.assertEquals(ord("#"), 0x23)
|
||||||
|
self.assertContains(body, "escape%23this", "12345")
|
||||||
|
|
||||||
def nerf(s):
|
def nerf(s):
|
||||||
return re.sub("[^a-zA-Z0-9]", "_", s)
|
return re.sub("[^a-zA-Z0-9]", "_", s)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user