From 469187e4f1043356a7b53b1328d52381ea334f17 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 18 Jul 2014 23:26:16 +0200 Subject: [PATCH] Catch unkown domain in validate_url --- umap/tests/test_views.py | 5 +++++ umap/views.py | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/umap/tests/test_views.py b/umap/tests/test_views.py index 4f7933de..fb7f00bd 100644 --- a/umap/tests/test_views.py +++ b/umap/tests/test_views.py @@ -55,6 +55,11 @@ class TestsValidateProxyURL(TestCase): with self.assertRaises(AssertionError): validate_url(request) + def test_unkown_domain_raises(self): + request = self.buildRequest("http://xlkjdkjsdlkjfd.com") + with self.assertRaises(AssertionError): + validate_url(request) + class TestsProxy(TestCase): diff --git a/umap/views.py b/umap/views.py index eb52422a..7563041e 100644 --- a/umap/views.py +++ b/umap/views.py @@ -207,8 +207,11 @@ def validate_url(request): assert referer.hostname == local.hostname assert toproxy.hostname != "localhost" assert toproxy.netloc != local.netloc - # clean this when in python 3.4 - ipaddress = socket.gethostbyname(toproxy.hostname) + try: + # clean this when in python 3.4 + ipaddress = socket.gethostbyname(toproxy.hostname) + except: + raise AssertionError() assert not ipaddress.startswith('127.') assert not ipaddress.startswith('192.168.') return url