From 516cea933f11e20df2ac0c9454289330a40e326d Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Wed, 12 Aug 2015 06:56:34 +0200 Subject: [PATCH] Shortcut to run coveraged tests --- .coverage.rc | 1 + dpaste/middleware.py | 11 ++++------- runtests.sh | 3 +++ 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 runtests.sh diff --git a/.coverage.rc b/.coverage.rc index b7b5d0e..3742123 100644 --- a/.coverage.rc +++ b/.coverage.rc @@ -3,6 +3,7 @@ source = dpaste branch = True omit = dpaste/migrations/* + dpaste/south_migrations/* dpaste/tests/* dpaste/settings/* diff --git a/dpaste/middleware.py b/dpaste/middleware.py index c221240..d152c08 100644 --- a/dpaste/middleware.py +++ b/dpaste/middleware.py @@ -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 = """

Access denied

It appears you're requesting this page from an open proxy or @@ -15,7 +16,7 @@ statutory violation related posts in the past.

If you think this is wrong, file a bug on Github please.

""" -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) diff --git a/runtests.sh b/runtests.sh new file mode 100644 index 0000000..c0cd54b --- /dev/null +++ b/runtests.sh @@ -0,0 +1,3 @@ +coverage run --rcfile=./.coverage.rc runtests.py && \ +coverage html --rcfile=./.coverage.rc +