mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 08:02:54 +11:00
Shortcut to run coveraged tests
This commit is contained in:
parent
e50e1db73e
commit
516cea933f
3 changed files with 8 additions and 7 deletions
|
@ -3,6 +3,7 @@ source = dpaste
|
|||
branch = True
|
||||
omit =
|
||||
dpaste/migrations/*
|
||||
dpaste/south_migrations/*
|
||||
dpaste/tests/*
|
||||
dpaste/settings/*
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ tor_bl = (
|
|||
'{remote_addr}.{server_port}.{server_ip}'
|
||||
'.ip-port.exitlist.torproject.org')
|
||||
open_proxy_bl = ('{remote_addr}.dnsbl.proxybl.org')
|
||||
rev_ip = lambda ip: '.'.join(reversed(ip.split('.')))
|
||||
|
||||
rev_ip = lambda ip: '.'.join(reversed(ip.split('.'))) # pragma: no cover
|
||||
|
||||
response = """<html><body><h1>Access denied</h1>
|
||||
<p>It appears you're requesting this page from an open proxy or
|
||||
|
@ -15,7 +16,7 @@ statutory violation related posts in the past.</p>
|
|||
<p>If you think this is wrong, <a href="https://github.com/bartTC/dpaste">file
|
||||
a bug on Github please</a>.</p></body></html>"""
|
||||
|
||||
def in_blacklist(request, bl, ip=None):
|
||||
def in_blacklist(request, bl, ip=None): # pragma: no cover
|
||||
ip = ip or request.META['REMOTE_ADDR']
|
||||
try:
|
||||
server_ip = socket.gethostbyname(request.META['SERVER_NAME'])
|
||||
|
@ -37,15 +38,13 @@ def in_blacklist(request, bl, ip=None):
|
|||
return lookup == '127.0.0.2'
|
||||
|
||||
|
||||
class SuspiciousIPMiddleware(object):
|
||||
class SuspiciousIPMiddleware(object): # pragma: no cover
|
||||
|
||||
def process_request(self, request):
|
||||
|
||||
def check_tor():
|
||||
if not hasattr(request, '_is_tor_exit_node'):
|
||||
request._is_tor_exit_node = in_blacklist(request, tor_bl)
|
||||
return request._is_tor_exit_node
|
||||
|
||||
request.is_tor_exit_node = check_tor
|
||||
|
||||
def check_open_proxy():
|
||||
|
@ -53,13 +52,11 @@ class SuspiciousIPMiddleware(object):
|
|||
request._is_open_proxy = in_blacklist(
|
||||
request, open_proxy_bl)
|
||||
return request._is_open_proxy
|
||||
|
||||
request.is_open_proxy = check_open_proxy
|
||||
|
||||
def check_suspicious():
|
||||
return request.is_tor_exit_node() or request.is_open_proxy()
|
||||
|
||||
request.is_suspicious = check_suspicious
|
||||
|
||||
if request.method == 'POST' and request.is_suspicious():
|
||||
return HttpResponseBadRequest(response)
|
||||
|
|
3
runtests.sh
Normal file
3
runtests.sh
Normal file
|
@ -0,0 +1,3 @@
|
|||
coverage run --rcfile=./.coverage.rc runtests.py && \
|
||||
coverage html --rcfile=./.coverage.rc
|
||||
|
Loading…
Reference in a new issue