Permalink
Browse files

feat(useDnsServer): add field in admin view, use in resolver if defin…

…ed. unit tests
  • Loading branch information...
Florian VANDENBULCKE
Florian VANDENBULCKE committed Oct 5, 2018
1 parent cc26b4b commit 55f6347bbf1df4f0a8c161b1dbc935ab29124ace
Showing with 29 additions and 4 deletions.
  1. +3 −2 Dockerfile.dev
  2. +9 −0 modoboa/admin/app_settings.py
  3. +5 −0 modoboa/admin/lib.py
  4. +10 −1 modoboa/admin/tests/test_mx.py
  5. +2 −1 modoboa/core/tests/test_views.py
@@ -2,13 +2,14 @@ FROM python:3.6-alpine
MAINTAINER Antoine Nguyen <tonio@ngyn.org>
RUN apk add --update python3-dev libffi-dev gcc musl-dev libxml2-dev libxslt-dev \
RUN apk add --update openssl python3-dev libffi-dev gcc musl-dev libxml2-dev libxslt-dev \
libressl-dev jpeg-dev \
&& rm -rf /var/cache/apk/*
WORKDIR /tmp
COPY requirements.txt /tmp
RUN pip install -r requirements.txt
COPY test-requirements.txt /tmp
RUN pip install -r requirements.txt -r test-requirements.txt
RUN mkdir /code
WORKDIR /code
@@ -10,6 +10,7 @@
from django.conf import settings
from django.utils.encoding import force_text
from django.utils.translation import ugettext as _, ugettext_lazy
from django.forms.fields import GenericIPAddressField
from modoboa.lib.form_utils import SeparatorField, YesNoField
from modoboa.lib.sysutils import exec_cmd
@@ -78,6 +79,14 @@ class AdminParametersForm(param_forms.AdminParametersForm):
)
)
use_specific_dns_server = GenericIPAddressField(
label=ugettext_lazy("Use specific DNS server"),
required=False,
help_text=ugettext_lazy(
"Give specific DNS server instead of local server configuration"
)
)
mbsep = SeparatorField(label=ugettext_lazy("Mailboxes"))
handle_mailboxes = YesNoField(
@@ -175,6 +175,11 @@ def get_domain_mx_list(domain):
"""Return a list of MX IP address for domain."""
result = []
logger = logging.getLogger("modoboa.admin")
use_specific_dns_server = param_tools.get_global_parameter("use_specific_dns_server")
if use_specific_dns_server :
dns.resolver.default_resolver.nameservers = [use_specific_dns_server]
try:
dns_answers = dns.resolver.query(domain, "MX")
except dns.resolver.NXDOMAIN as e:
@@ -14,6 +14,7 @@
from modoboa.core import factories as core_factories
from modoboa.lib.tests import ModoTestCase
from modoboa.parameters import tools as param_tools
from . import utils
from .. import factories, models
from ..lib import get_domain_mx_list
@@ -107,7 +108,15 @@ def test_single_domain_update(
management.call_command(
"modo", "check_mx", "--domain", "toto.com")
@mock.patch("socket.getaddrinfo")
@mock.patch.object(dns.resolver.Resolver, "query")
def test_get_domain_mx_list_with_dsn_server(self, mock_query, mock_getaddrinfo):
mock_query.side_effect = utils.mock_dns_query_result
mock_getaddrinfo.side_effect = utils.mock_ip_query_result
self.set_global_parameter("use_specific_dns_server","123.45.67.89")
get_domain_mx_list("does-not-exist.example.com")
@mock.patch("socket.getaddrinfo")
@mock.patch.object(dns.resolver.Resolver, "query")
def test_get_domain_mx_list_logging(self, mock_query, mock_getaddrinfo):
@@ -67,7 +67,8 @@
"core-random_password_length": "8",
"admin-create_alias_on_mbox_rename": False,
"admin-dkim_keys_storage_dir": "",
"admin-dkim_default_key_length": 1024
"admin-dkim_default_key_length": 1024,
"admin-use_specific_dns_server": "193.43.55.67"
}

0 comments on commit 55f6347

Please sign in to comment.