summaryrefslogtreecommitdiffstats
path: root/ansible_collections/community/dns/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 16:18:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 16:18:34 +0000
commit3667197efb7b18ec842efd504785965911f8ac4b (patch)
tree0b986a4bc6879d080b100666a97cdabbc9ca1f28 /ansible_collections/community/dns/tests
parentAdding upstream version 9.5.1+dfsg. (diff)
downloadansible-3667197efb7b18ec842efd504785965911f8ac4b.tar.xz
ansible-3667197efb7b18ec842efd504785965911f8ac4b.zip
Adding upstream version 10.0.0+dfsg.upstream/10.0.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/community/dns/tests')
-rw-r--r--ansible_collections/community/dns/tests/integration/targets/filter_txt/tasks/main.yml44
-rw-r--r--ansible_collections/community/dns/tests/unit/plugins/inventory/test_hetzner_dns_records.py4
-rw-r--r--ansible_collections/community/dns/tests/unit/plugins/inventory/test_hosttech_dns_records.py4
-rw-r--r--ansible_collections/community/dns/tests/unit/plugins/lookup/test_lookup.py102
-rw-r--r--ansible_collections/community/dns/tests/unit/plugins/lookup/test_lookup_as_dict.py97
-rw-r--r--ansible_collections/community/dns/tests/unit/plugins/module_utils/resolver_helper.py3
-rw-r--r--ansible_collections/community/dns/tests/unit/plugins/modules/test_hetzner_dns_record_set_info.py19
-rw-r--r--ansible_collections/community/dns/tests/unit/plugins/plugin_utils/test_unsafe.py133
8 files changed, 337 insertions, 69 deletions
diff --git a/ansible_collections/community/dns/tests/integration/targets/filter_txt/tasks/main.yml b/ansible_collections/community/dns/tests/integration/targets/filter_txt/tasks/main.yml
index c0afffcea..63c7d8424 100644
--- a/ansible_collections/community/dns/tests/integration/targets/filter_txt/tasks/main.yml
+++ b/ansible_collections/community/dns/tests/integration/targets/filter_txt/tasks/main.yml
@@ -47,3 +47,47 @@
'"foo" "bar"' | community.dns.unquote_txt == "foobar"
- >
'foo "bar baz" bam' | community.dns.unquote_txt == "foobar bazbam"
+
+- name: quote_txt failure - input not string
+ set_fact:
+ output: "{{ 1 | community.dns.quote_txt }}"
+ register: quote_failure_1
+ ignore_errors: true
+
+- name: quote_txt failure - always_quote not a boolean
+ set_fact:
+ output: "{{ '' | community.dns.quote_txt(always_quote=1) }}"
+ register: quote_failure_2
+ ignore_errors: true
+
+- name: quote_txt failure - character_encoding has invalid value
+ set_fact:
+ output: "{{ '' | community.dns.quote_txt(character_encoding='foo') }}"
+ register: quote_failure_3
+ ignore_errors: true
+
+- name: unquote_txt failure - input not string
+ set_fact:
+ output: "{{ 1 | community.dns.unquote_txt }}"
+ register: unquote_failure_1
+ ignore_errors: true
+
+- name: unquote_txt failure - character_encoding has invalid value
+ set_fact:
+ output: "{{ '' | community.dns.unquote_txt(character_encoding='foo') }}"
+ register: unquote_failure_2
+ ignore_errors: true
+
+- name: Validate errors
+ assert:
+ that:
+ - quote_failure_1 is failed
+ - quote_failure_1.msg == 'Input for community.dns.quote_txt must be a string'
+ - quote_failure_2 is failed
+ - quote_failure_2.msg == 'always_quote must be a boolean, not 1'
+ - quote_failure_3 is failed
+ - quote_failure_3.msg == "character_encoding must be \"decimal\" or \"octal\", not 'foo'"
+ - unquote_failure_1 is failed
+ - unquote_failure_1.msg == 'Input for community.dns.unquote_txt must be a string'
+ - unquote_failure_2 is failed
+ - unquote_failure_2.msg == "character_encoding must be \"decimal\" or \"octal\", not 'foo'"
diff --git a/ansible_collections/community/dns/tests/unit/plugins/inventory/test_hetzner_dns_records.py b/ansible_collections/community/dns/tests/unit/plugins/inventory/test_hetzner_dns_records.py
index 44f694708..2dadf2643 100644
--- a/ansible_collections/community/dns/tests/unit/plugins/inventory/test_hetzner_dns_records.py
+++ b/ansible_collections/community/dns/tests/unit/plugins/inventory/test_hetzner_dns_records.py
@@ -236,7 +236,7 @@ def test_inventory_file_simple(mocker):
plugin: community.dns.hetzner_dns_records
hetzner_token: foo
zone_name: example.com
- filters:
+ simple_filters:
type: A
""")}
@@ -289,7 +289,7 @@ def test_inventory_file_collision(mocker):
plugin: community.dns.hetzner_dns_records
hetzner_token: '{{ "foo" }}'
zone_name: '{{ "example." ~ "com" }}'
- filters:
+ simple_filters:
type:
- A
- AAAA
diff --git a/ansible_collections/community/dns/tests/unit/plugins/inventory/test_hosttech_dns_records.py b/ansible_collections/community/dns/tests/unit/plugins/inventory/test_hosttech_dns_records.py
index 11995198c..dd56623df 100644
--- a/ansible_collections/community/dns/tests/unit/plugins/inventory/test_hosttech_dns_records.py
+++ b/ansible_collections/community/dns/tests/unit/plugins/inventory/test_hosttech_dns_records.py
@@ -220,7 +220,7 @@ def test_inventory_file_simple(mocker):
plugin: community.dns.hosttech_dns_records
hosttech_token: foo
zone_name: example.com
- filters:
+ simple_filters:
type: A
""")}
@@ -270,7 +270,7 @@ def test_inventory_file_collision(mocker):
plugin: community.dns.hosttech_dns_records
hosttech_token: "{{ 'foo' }}"
zone_name: "{{ 'example' ~ '.com' }}"
- filters:
+ simple_filters:
type:
- A
- AAAA
diff --git a/ansible_collections/community/dns/tests/unit/plugins/lookup/test_lookup.py b/ansible_collections/community/dns/tests/unit/plugins/lookup/test_lookup.py
index 0982d8704..010fe8ac0 100644
--- a/ansible_collections/community/dns/tests/unit/plugins/lookup/test_lookup.py
+++ b/ansible_collections/community/dns/tests/unit/plugins/lookup/test_lookup.py
@@ -35,7 +35,8 @@ class TestLookup(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(dns.rrset.from_rdata(
@@ -57,29 +58,60 @@ class TestLookup(TestCase):
assert result[0] == '127.0.0.1'
assert result[1] == '127.0.0.2'
- def test_retry_success(self):
+ def test_no_search(self):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
'target': dns.name.from_unicode(u'www.example.com'),
+ 'search': False,
+ 'rdtype': dns.rdatatype.A,
+ 'lifetime': 10,
+ 'result': create_mock_answer(dns.rrset.from_rdata(
+ 'www.example.com',
+ 300,
+ dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, '127.0.0.1'),
+ dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, '127.0.0.2'),
+ )),
+ },
+ ],
+ })
+ with patch('dns.resolver.get_default_resolver', resolver):
+ with patch('dns.resolver.Resolver', resolver):
+ with patch('dns.query.udp', mock_query_udp([])):
+ result = self.lookup.run(['www.example.com'], search=False)
+
+ print(result)
+ assert len(result) == 2
+ assert result[0] == '127.0.0.1'
+ assert result[1] == '127.0.0.2'
+
+ def test_retry_success(self):
+ resolver = mock_resolver(['1.1.1.1'], {
+ ('1.1.1.1', ): [
+ {
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'raise': dns.exception.Timeout(timeout=10),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'raise': dns.exception.Timeout(timeout=10),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'raise': dns.exception.Timeout(timeout=10),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(dns.rrset.from_rdata(
@@ -105,25 +137,29 @@ class TestLookup(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'raise': dns.exception.Timeout(timeout=10),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'raise': dns.exception.Timeout(timeout=10),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'raise': dns.exception.Timeout(timeout=10),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'raise': dns.exception.Timeout(timeout=10),
@@ -143,7 +179,8 @@ class TestLookup(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.NXDOMAIN),
@@ -162,7 +199,8 @@ class TestLookup(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.NXDOMAIN),
@@ -181,7 +219,8 @@ class TestLookup(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.NXDOMAIN),
@@ -200,7 +239,8 @@ class TestLookup(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.NXDOMAIN),
@@ -220,7 +260,8 @@ class TestLookup(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.NXDOMAIN),
@@ -240,7 +281,8 @@ class TestLookup(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.SERVFAIL),
@@ -260,19 +302,22 @@ class TestLookup(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.SERVFAIL),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.SERVFAIL),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.NXDOMAIN),
@@ -291,19 +336,22 @@ class TestLookup(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.SERVFAIL),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.SERVFAIL),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.SERVFAIL),
@@ -323,7 +371,8 @@ class TestLookup(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'example.com'),
+ 'target': dns.name.from_unicode(u'example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.TXT,
'lifetime': 10,
'result': create_mock_answer(dns.rrset.from_rdata(
@@ -351,7 +400,8 @@ class TestLookup(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('2.2.2.2', '3.3.3.3'): [
{
- 'target': dns.name.from_unicode(u'example.org'),
+ 'target': dns.name.from_unicode(u'example.org', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.AAAA,
'lifetime': 10,
'result': create_mock_answer(dns.rrset.from_rdata(
@@ -397,7 +447,8 @@ class TestLookup(TestCase):
],
('1.2.3.4', '1::2', '2.2.2.2', '3.3.3.3'): [
{
- 'target': dns.name.from_unicode(u'example.org'),
+ 'target': dns.name.from_unicode(u'example.org', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.AAAA,
'lifetime': 10,
'result': create_mock_answer(dns.rrset.from_rdata(
@@ -477,7 +528,8 @@ class TestLookup(TestCase):
],
('3.3.3.3', ): [
{
- 'target': dns.name.from_unicode(u'example.org'),
+ 'target': dns.name.from_unicode(u'example.org', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.AAAA,
'lifetime': 5,
'raise': dns.resolver.NoAnswer(response=fake_query),
diff --git a/ansible_collections/community/dns/tests/unit/plugins/lookup/test_lookup_as_dict.py b/ansible_collections/community/dns/tests/unit/plugins/lookup/test_lookup_as_dict.py
index f29d73143..57c3655a9 100644
--- a/ansible_collections/community/dns/tests/unit/plugins/lookup/test_lookup_as_dict.py
+++ b/ansible_collections/community/dns/tests/unit/plugins/lookup/test_lookup_as_dict.py
@@ -35,7 +35,8 @@ class TestLookupAsDict(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(dns.rrset.from_rdata(
@@ -61,29 +62,64 @@ class TestLookupAsDict(TestCase):
'address': '127.0.0.2',
}
- def test_retry_success(self):
+ def test_no_search(self):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
'target': dns.name.from_unicode(u'www.example.com'),
+ 'search': False,
+ 'rdtype': dns.rdatatype.A,
+ 'lifetime': 10,
+ 'result': create_mock_answer(dns.rrset.from_rdata(
+ 'www.example.com',
+ 300,
+ dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, '127.0.0.1'),
+ dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, '127.0.0.2'),
+ )),
+ },
+ ],
+ })
+ with patch('dns.resolver.get_default_resolver', resolver):
+ with patch('dns.resolver.Resolver', resolver):
+ with patch('dns.query.udp', mock_query_udp([])):
+ result = self.lookup.run(['www.example.com'], search=False)
+
+ print(result)
+ assert len(result) == 2
+ assert result[0] == {
+ 'address': '127.0.0.1',
+ }
+ assert result[1] == {
+ 'address': '127.0.0.2',
+ }
+
+ def test_retry_success(self):
+ resolver = mock_resolver(['1.1.1.1'], {
+ ('1.1.1.1', ): [
+ {
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'raise': dns.exception.Timeout(timeout=10),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'raise': dns.exception.Timeout(timeout=10),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'raise': dns.exception.Timeout(timeout=10),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(dns.rrset.from_rdata(
@@ -113,25 +149,29 @@ class TestLookupAsDict(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'raise': dns.exception.Timeout(timeout=10),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'raise': dns.exception.Timeout(timeout=10),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'raise': dns.exception.Timeout(timeout=10),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'raise': dns.exception.Timeout(timeout=10),
@@ -151,7 +191,8 @@ class TestLookupAsDict(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.NXDOMAIN),
@@ -170,7 +211,8 @@ class TestLookupAsDict(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.NXDOMAIN),
@@ -190,7 +232,8 @@ class TestLookupAsDict(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.SERVFAIL),
@@ -210,19 +253,22 @@ class TestLookupAsDict(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.SERVFAIL),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.SERVFAIL),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.NXDOMAIN),
@@ -241,19 +287,22 @@ class TestLookupAsDict(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.SERVFAIL),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.SERVFAIL),
},
{
- 'target': dns.name.from_unicode(u'www.example.com'),
+ 'target': dns.name.from_unicode(u'www.example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.A,
'lifetime': 10,
'result': create_mock_answer(rcode=dns.rcode.SERVFAIL),
@@ -273,7 +322,8 @@ class TestLookupAsDict(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('1.1.1.1', ): [
{
- 'target': dns.name.from_unicode(u'example.com'),
+ 'target': dns.name.from_unicode(u'example.com', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.TXT,
'lifetime': 10,
'result': create_mock_answer(dns.rrset.from_rdata(
@@ -310,7 +360,8 @@ class TestLookupAsDict(TestCase):
resolver = mock_resolver(['1.1.1.1'], {
('2.2.2.2', '3.3.3.3'): [
{
- 'target': dns.name.from_unicode(u'example.org'),
+ 'target': dns.name.from_unicode(u'example.org', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.AAAA,
'lifetime': 10,
'result': create_mock_answer(dns.rrset.from_rdata(
@@ -358,7 +409,8 @@ class TestLookupAsDict(TestCase):
],
('1.2.3.4', '1::2', '2.2.2.2', '3.3.3.3'): [
{
- 'target': dns.name.from_unicode(u'example.org'),
+ 'target': dns.name.from_unicode(u'example.org', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.AAAA,
'lifetime': 10,
'result': create_mock_answer(dns.rrset.from_rdata(
@@ -440,7 +492,8 @@ class TestLookupAsDict(TestCase):
],
('3.3.3.3', ): [
{
- 'target': dns.name.from_unicode(u'example.org'),
+ 'target': dns.name.from_unicode(u'example.org', origin=None),
+ 'search': True,
'rdtype': dns.rdatatype.AAAA,
'lifetime': 5,
'raise': dns.resolver.NoAnswer(response=fake_query),
diff --git a/ansible_collections/community/dns/tests/unit/plugins/module_utils/resolver_helper.py b/ansible_collections/community/dns/tests/unit/plugins/module_utils/resolver_helper.py
index 7fa213c9f..71a0af989 100644
--- a/ansible_collections/community/dns/tests/unit/plugins/module_utils/resolver_helper.py
+++ b/ansible_collections/community/dns/tests/unit/plugins/module_utils/resolver_helper.py
@@ -22,7 +22,7 @@ def mock_resolver(default_nameservers, nameserver_resolve_sequence):
resolver = MagicMock()
resolver.nameservers = default_nameservers if configure else []
- def mock_resolver_resolve(target, rdtype=None, lifetime=None):
+ def mock_resolver_resolve(target, rdtype=None, lifetime=None, search=None):
resolver_index = tuple(sorted(resolver.nameservers))
assert resolver_index in nameserver_resolve_sequence, 'No resolver sequence for {0}'.format(resolver_index)
resolve_sequence = nameserver_resolve_sequence[resolver_index]
@@ -33,6 +33,7 @@ def mock_resolver(default_nameservers, nameserver_resolve_sequence):
assert target == resolve_data['target'], 'target: {0!r} vs {1!r}'.format(target, resolve_data['target'])
assert rdtype == resolve_data.get('rdtype'), 'rdtype: {0!r} vs {1!r}'.format(rdtype, resolve_data.get('rdtype'))
assert lifetime == resolve_data['lifetime'], 'lifetime: {0!r} vs {1!r}'.format(lifetime, resolve_data['lifetime'])
+ assert search == resolve_data.get('search'), 'search: {0!r} vs {1!r}'.format(search, resolve_data.get('search'))
if 'raise' in resolve_data:
raise resolve_data['raise']
diff --git a/ansible_collections/community/dns/tests/unit/plugins/modules/test_hetzner_dns_record_set_info.py b/ansible_collections/community/dns/tests/unit/plugins/modules/test_hetzner_dns_record_set_info.py
index a42add09d..e6894f97c 100644
--- a/ansible_collections/community/dns/tests/unit/plugins/modules/test_hetzner_dns_record_set_info.py
+++ b/ansible_collections/community/dns/tests/unit/plugins/modules/test_hetzner_dns_record_set_info.py
@@ -627,7 +627,7 @@ class TestHetznerDNSRecordSetInfoJSON(BaseTestModule):
assert result['set']['value'] == [u'"b\\195\\164r \\"with quotes\\" (use \\\\ to escape)"']
assert 'sets' not in result
- def test_get_single_txt_quoted_deprecation(self, mocker):
+ def test_get_single_txt_quoted_octal(self, mocker):
with patch('time.sleep', mock_sleep):
result = self.run_module_success(mocker, hetzner_dns_record_set_info, {
'hetzner_token': 'foo',
@@ -635,6 +635,7 @@ class TestHetznerDNSRecordSetInfoJSON(BaseTestModule):
'prefix': 'foo',
'type': 'TXT',
'txt_transformation': 'quoted',
+ 'txt_character_encoding': 'octal',
'_ansible_remote_tmp': '/tmp/tmp',
'_ansible_keep_remote_files': True,
}, [
@@ -678,19 +679,3 @@ class TestHetznerDNSRecordSetInfoJSON(BaseTestModule):
assert result['set']['type'] == 'TXT'
assert result['set']['value'] == [u'"b\\303\\244r \\"with quotes\\" (use \\\\ to escape)"']
assert 'sets' not in result
- assert 'deprecations' in result
- found = False
- for deprecation in result['deprecations']:
- if 'collection_name' in deprecation and deprecation['collection_name'] != 'community.dns':
- continue
- found = True
- assert deprecation['msg'] == (
- 'The default of the txt_character_encoding option will change from "octal" to "decimal" in community.dns 3.0.0.'
- ' This potentially affects you since you use txt_transformation=quoted.'
- ' You can explicitly set txt_character_encoding to "octal" to keep the current behavior,'
- ' or "decimal" to already now switch to the new behavior.'
- ' We recommend switching to the new behavior, and using check/diff mode to figure out potential changes'
- )
- assert deprecation['version'] == '3.0.0'
- assert deprecation.get('date') is None
- assert found
diff --git a/ansible_collections/community/dns/tests/unit/plugins/plugin_utils/test_unsafe.py b/ansible_collections/community/dns/tests/unit/plugins/plugin_utils/test_unsafe.py
new file mode 100644
index 000000000..cbda5f142
--- /dev/null
+++ b/ansible_collections/community/dns/tests/unit/plugins/plugin_utils/test_unsafe.py
@@ -0,0 +1,133 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2024, Felix Fontein <felix@fontein.de>
+# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# Make coding more python3-ish
+from __future__ import absolute_import, division, print_function
+
+__metaclass__ = type
+
+
+import pytest
+
+from ansible.utils.unsafe_proxy import AnsibleUnsafe
+
+from ansible_collections.community.dns.plugins.plugin_utils.unsafe import (
+ make_unsafe,
+)
+
+
+TEST_MAKE_UNSAFE = [
+ (
+ u'text',
+ [],
+ [
+ (),
+ ],
+ ),
+ (
+ u'{{text}}',
+ [
+ (),
+ ],
+ [],
+ ),
+ (
+ b'text',
+ [],
+ [
+ (),
+ ],
+ ),
+ (
+ b'{{text}}',
+ [
+ (),
+ ],
+ [],
+ ),
+ (
+ {
+ 'skey': 'value',
+ 'ukey': '{{value}}',
+ 1: [
+ 'value',
+ '{{value}}',
+ {
+ 1.0: '{{value}}',
+ 2.0: 'value',
+ },
+ ],
+ },
+ [
+ ('ukey', ),
+ (1, 1),
+ (1, 2, 1.0),
+ ],
+ [
+ ('skey', ),
+ (1, 0),
+ (1, 2, 2.0),
+ ],
+ ),
+ (
+ ['value', '{{value}}'],
+ [
+ (1, ),
+ ],
+ [
+ (0, ),
+ ],
+ ),
+]
+
+
+@pytest.mark.parametrize("value, check_unsafe_paths, check_safe_paths", TEST_MAKE_UNSAFE)
+def test_make_unsafe(value, check_unsafe_paths, check_safe_paths):
+ unsafe_value = make_unsafe(value)
+ assert unsafe_value == value
+ for check_path in check_unsafe_paths:
+ obj = unsafe_value
+ for elt in check_path:
+ obj = obj[elt]
+ assert isinstance(obj, AnsibleUnsafe)
+ for check_path in check_safe_paths:
+ obj = unsafe_value
+ for elt in check_path:
+ obj = obj[elt]
+ assert not isinstance(obj, AnsibleUnsafe)
+
+
+def test_make_unsafe_dict_key():
+ value = {
+ b'test': 1,
+ u'test': 2,
+ }
+ unsafe_value = make_unsafe(value)
+ assert unsafe_value == value
+ for obj in unsafe_value:
+ assert not isinstance(obj, AnsibleUnsafe)
+
+ value = {
+ b'{{test}}': 1,
+ u'{{test}}': 2,
+ }
+ unsafe_value = make_unsafe(value)
+ assert unsafe_value == value
+ for obj in unsafe_value:
+ assert isinstance(obj, AnsibleUnsafe)
+
+
+def test_make_unsafe_set():
+ value = set([b'test', u'test'])
+ unsafe_value = make_unsafe(value)
+ assert unsafe_value == value
+ for obj in unsafe_value:
+ assert not isinstance(obj, AnsibleUnsafe)
+
+ value = set([b'{{test}}', u'{{test}}'])
+ unsafe_value = make_unsafe(value)
+ assert unsafe_value == value
+ for obj in unsafe_value:
+ assert isinstance(obj, AnsibleUnsafe)