middleware: remove DNS usage from maintenance middleware (#65096)

This commit is contained in:
Emmanuel Cazenave 2022-05-11 11:31:55 +02:00
parent 8a7c81561c
commit 905ccd9ac8
2 changed files with 0 additions and 17 deletions

View File

@ -14,8 +14,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import dns.exception
import dns.resolver
from django.conf import settings
from django.http import HttpResponse
from django.utils.translation import ugettext as _
@ -25,14 +23,6 @@ def pass_through(remote_addr):
pass_through_ips = getattr(settings, 'MAINTENANCE_PASS_THROUGH_IPS', [])
if remote_addr in pass_through_ips:
return True
pass_through_ddns = getattr(settings, 'MAINTENANCE_PASS_THROUGH_DDNS', None)
if pass_through_ddns:
domain = '.'.join(reversed(remote_addr.split('.'))) + '.' + pass_through_ddns
try:
answers = dns.resolver.query(domain, 'A', lifetime=1)
return any(answer.address for answer in answers)
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.exception.DNSException):
return False
return False

View File

@ -17,10 +17,3 @@ def test_maintenance_middleware(app, admin_user, db, monkeypatch, settings):
settings.MAINTENANCE_PASS_THROUGH_IPS = []
resp = app.get('/', status=503)
settings.MAINTENANCE_PASS_THROUGH_DDNS = 'ddns.foo.bar'
with mock.patch('dns.resolver.resolve', return_value=[mock.Mock(address='127.0.0.2')]):
resp = app.get('/')
assert resp.status_code == 200
with mock.patch('dns.resolver.resolve', return_value=[]):
resp = app.get('/', status=503)