summaryrefslogtreecommitdiffstats
path: root/ipapython
diff options
context:
space:
mode:
authorPetr Spacek <pspacek@redhat.com>2016-03-07 13:24:31 +0100
committerPetr Vobornik <pvoborni@redhat.com>2016-04-28 18:46:06 +0200
commit41464b74f43ab0a7f9ad650bdaac19308fc7ff5c (patch)
tree42ac75db398820119cf13cae4bfddc1581595056 /ipapython
parentbd32b48eb0180b73c3bd769b7ea2b369a095c000 (diff)
downloadfreeipa-41464b74f43ab0a7f9ad650bdaac19308fc7ff5c.tar.gz
freeipa-41464b74f43ab0a7f9ad650bdaac19308fc7ff5c.tar.xz
freeipa-41464b74f43ab0a7f9ad650bdaac19308fc7ff5c.zip
Add assert_absolute_dnsname() helper to ipapython.dnsutil
Sanity check for zone names and such should be the same everywhere. This new function will be a replacement for ad-hoc checks. https://fedorahosted.org/freeipa/ticket/5710 Reviewed-By: Martin Basti <mbasti@redhat.com>
Diffstat (limited to 'ipapython')
-rw-r--r--ipapython/dnsutil.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/ipapython/dnsutil.py b/ipapython/dnsutil.py
index 0cab0f497..7f0a094f2 100644
--- a/ipapython/dnsutil.py
+++ b/ipapython/dnsutil.py
@@ -166,3 +166,22 @@ EMPTY_ZONES = [DNSName(aez).make_absolute() for aez in [
# RFC 7534
"EMPTY.AS112.ARPA",
]]
+
+
+def assert_absolute_dnsname(name):
+ """Raise AssertionError if name is not DNSName or is not absolute.
+
+ >>> assert_absolute_dnsname(DNSName('absolute.name.example.'))
+ >>> assert_absolute_dnsname(DNSName('relative.name.example'))
+ Traceback (most recent call last):
+ ...
+ AssertionError: name must be absolute, ...
+ >>> assert_absolute_dnsname('absolute.string.example.')
+ Traceback (most recent call last):
+ ...
+ AssertionError: name must be DNSName instance, ...
+ """
+
+ assert isinstance(name, DNSName), ("name must be DNSName instance, "
+ "got '%s'" % type(name))
+ assert name.is_absolute(), "name must be absolute, got '%s'" % name