Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unbound_dot: allow requests without domain parameter set #77

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions plugins/module_utils/main/unbound_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def __init__(self, module: AnsibleModule, result: dict, session: Session = None)
self.dot = {}

def check(self) -> None:
validate_domain(module=self.m, domain=self.p['domain'])
if not is_unset(self.p['domain']):
validate_domain(module=self.m, domain=self.p['domain'])
validate_port(module=self.m, port=self.p['port'])

if not is_unset(self.p['verify']) and \
Expand All @@ -50,7 +51,11 @@ def check(self) -> None:
f"nor a valid hostname!"
)

self.b.find(match_fields=['domain', 'target'])
if is_unset(self.p['domain']):
self.b.find(match_fields=['target'])

else:
self.b.find(match_fields=['domain', 'target'])

if self.p['state'] == 'present':
self.r['diff']['after'] = self.b.build_diff(data=self.p)
Expand Down
9 changes: 5 additions & 4 deletions tests/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@

- name: Cleanup Unbound DNS-over-TLS
ansibleguy.opnsense.unbound_dot:
domain: "{{ item.d }}"
target: "{{ item.t }}"
target: "{{ item }}"
state: 'absent'
reload: false # speed
loop:
- {d: 'dot.opnsense.test.ansibleguy.net', t: '1.1.1.1'}
- {d: 'dot.opnsense.test.ansibleguy.net', t: '1.1.1.2'}
- '1.1.1.1'
- '1.1.1.2'
- '1.1.1.3'
- '1.1.1.4'

- name: Cleanup Unbound DNS-Forwarding's
ansibleguy.opnsense.unbound_forward:
Expand Down
47 changes: 43 additions & 4 deletions tests/unbound_dot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,54 @@
opn3.data | length != 1
when: not ansible_check_mode

- name: Adding 3 without domain
ansibleguy.opnsense.unbound_dot:
target: '1.1.1.3'
verify: 'dot.opnsense.test.ansibleguy.net'
reload: false # speed
register: opn6
failed_when: >
opn6.failed or
not opn6.changed

- name: Changing 3 port
ansibleguy.opnsense.unbound_dot:
target: '1.1.1.3'
verify: 'dot.opnsense.test.ansibleguy.net'
port: 853
reload: false # speed
register: opn6
failed_when: >
opn6.failed or
not opn6.changed

- name: Removing 3
ansibleguy.opnsense.unbound_dot:
target: '1.1.1.3'
verify: 'dot.opnsense.test.ansibleguy.net'
state: 'absent'
reload: false
when: not ansible_check_mode

- name: Adding 4 without domain or verify
ansibleguy.opnsense.unbound_dot:
target: '1.1.1.4'
reload: false # speed
register: opn7
failed_when: >
opn7.failed or
not opn7.changed

- name: Cleanup
ansibleguy.opnsense.unbound_dot:
domain: "{{ item.d }}"
target: "{{ item.t }}"
target: "{{ item }}"
state: 'absent'
reload: false
loop:
- {d: 'dot.opnsense.test.ansibleguy.net', t: '1.1.1.1'}
- {d: 'dot.opnsense.test.ansibleguy.net', t: '1.1.1.2'}
- '1.1.1.1'
- '1.1.1.2'
- '1.1.1.3'
- '1.1.1.4'
when: not ansible_check_mode

- name: Listing dots
Expand Down
Loading