Skip to content

Commit

Permalink
Merge pull request nsupdate-info#492 from PhrozenByte/bugfix/connecti…
Browse files Browse the repository at this point in the history
…vity-test

Fix connectivity test when editing domains
  • Loading branch information
ThomasWaldmann authored Apr 12, 2023
2 parents 4be3638 + c3721f4 commit 9b683e8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Fixes:

- fixed misc. crashes
- fixed Domain.generate_ns_secret() storing bytes object into Domain.nameserver_update_secret leading to trying to insert the string representation of the bytes object, so 91 characters in a varchar(88)
- fixed connectivity test when editing domains, #479

Other changes:

Expand Down
9 changes: 6 additions & 3 deletions src/nsupdate/main/dnstools.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,16 @@ def check_ip(ipaddr, keys=('ipv4', 'ipv6')):
return keys[af == dns.inet.AF_INET6]


def check_domain(domain):
def check_domain(domain, nameserver_ip):
fqdn = FQDN(host="connectivity-test", domain=domain)

from .models import Domain
d = Domain.objects.get(name=domain)
# temporarily set domain to available to allow add/update/deletes
# temporarily update domain to allow add/update/deletes
domain_available_state = d.available
domain_nameserver_ip = d.nameserver_ip
d.available = True
d.nameserver_ip = nameserver_ip
d.save()

try:
Expand All @@ -123,8 +125,9 @@ def check_domain(domain):
raise NameServerNotAvailable(str(e))

finally:
# reset domain available
# reset domain
d.available = domain_available_state
d.nameserver_ip = domain_nameserver_ip
d.save()


Expand Down
2 changes: 1 addition & 1 deletion src/nsupdate/main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def clean(self):

if self.cleaned_data['available']:
try:
check_domain(self.instance.name)
check_domain(self.instance.name, cleaned_data['nameserver_ip'])

except (NameServerNotAvailable, ):
raise forms.ValidationError(
Expand Down

0 comments on commit 9b683e8

Please sign in to comment.