Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a remaining case of bug #85 #100

Merged
merged 2 commits into from
Jun 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,4 @@ Contributors
- Sebastian Hanula 2012/12/17
- Aaron Spaulding, 2013/01/20
- Hadrien David, 2013/01/23
- Daniel Werner, 2013/06/03
11 changes: 11 additions & 0 deletions pyramid_debugtoolbar/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,14 @@ def test_in_multi(self):

def test_in_network(self):
self.assertTrue(self._callFUT('127.0.0.1', ['127.0.0.1/24']))

class Test_last_proxy(unittest.TestCase):
def _callFUT(self, addr):
from pyramid_debugtoolbar.utils import last_proxy
return last_proxy(addr)

def test_single_host(self):
self.assertEqual(self._callFUT('192.168.1.2'), '192.168.1.2')

def test_multiple_hosts(self):
self.assertEqual(self._callFUT('192.168.1.1, 192.168.1.2'), '192.168.1.2')
3 changes: 2 additions & 1 deletion pyramid_debugtoolbar/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pyramid_debugtoolbar.utils import EXC_ROUTE_NAME
from pyramid_debugtoolbar.utils import logger
from pyramid_debugtoolbar.utils import addr_in
from pyramid_debugtoolbar.utils import last_proxy
from pyramid.httpexceptions import WSGIHTTPException


Expand Down Expand Up @@ -121,7 +122,7 @@ def toolbar_tween(request):
exclude)))

if request.remote_addr:
last_proxy_addr = request.remote_addr.split(',').pop().strip()
last_proxy_addr = last_proxy(request.remote_addr)

if last_proxy_addr is None \
or starts_with_excluded \
Expand Down
2 changes: 2 additions & 0 deletions pyramid_debugtoolbar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,5 @@ def addr_in(addr, hosts):
return True
return False

def last_proxy(addr):
return addr.split(',').pop().strip()
8 changes: 5 additions & 3 deletions pyramid_debugtoolbar/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
from pyramid_debugtoolbar.utils import format_sql
from pyramid_debugtoolbar.utils import get_setting
from pyramid_debugtoolbar.utils import addr_in
from pyramid_debugtoolbar.utils import last_proxy
from pyramid_debugtoolbar.toolbar import IRequestAuthorization


def valid_host(info, request):
hosts = get_setting(request.registry.settings, 'hosts')
remote_addr = request.remote_addr
if remote_addr is None:
if request.remote_addr is None:
return False

return addr_in(request.remote_addr, hosts)
last_proxy_addr = last_proxy(request.remote_addr)

return addr_in(last_proxy_addr, hosts)


def valid_request(info, request):
Expand Down