mirror of
https://github.com/trailofbits/algo.git
synced 2025-09-02 10:03:01 +02:00
* fix: Fix IPv6 address selection on BSD systems (#1843) BSD systems return IPv6 addresses in the order they were added to the interface, not sorted by scope like Linux. This causes ansible_default_ipv6 to contain link-local addresses (fe80::) with interface suffixes (%em0) instead of global addresses, breaking certificate generation. This fix: - Adds a new task file to properly select global IPv6 addresses on BSD - Filters out link-local addresses and interface suffixes - Falls back to ansible_all_ipv6_addresses when needed - Ensures certificates are generated with valid global IPv6 addresses The workaround is implemented in Algo rather than waiting for the upstream Ansible issue (#16977) to be fixed, which has been open since 2016. Fixes #1843 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * chore: Remove duplicate condition in BSD IPv6 facts Removed redundant 'global_ipv6_address is not defined' condition that was checked twice in the same when clause. * improve: simplify regex for IPv6 interface suffix removal Change regex from '(.*)%.*' to '%.*' for better readability and performance when stripping interface suffixes from IPv6 addresses. The simplified regex is equivalent but more concise and easier to understand. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: resolve yamllint trailing spaces in BSD IPv6 test Remove trailing spaces from test_bsd_ipv6.yml to ensure CI passes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: resolve yamllint issues across repository - Remove trailing spaces from server.yml, WireGuard test files, and keys.yml - Add missing newlines at end of test files - Ensure all YAML files pass yamllint validation for CI 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
86 lines
2.8 KiB
YAML
86 lines
2.8 KiB
YAML
---
|
|
# Test WireGuard async result structure handling
|
|
# This simulates the async_status result structure to verify our fix
|
|
- name: Test WireGuard async result handling
|
|
hosts: localhost
|
|
gather_facts: no
|
|
vars:
|
|
# Simulate the actual structure that async_status with with_items returns
|
|
# This is the key insight: async_status results contain the original item info
|
|
mock_wg_genkey_results:
|
|
results:
|
|
- item: "user1" # This comes from the original wg_genkey.results item
|
|
stdout: "mock_private_key_1" # This is the command output
|
|
changed: true
|
|
rc: 0
|
|
failed: false
|
|
finished: true
|
|
- item: "10.10.10.1" # This comes from the original wg_genkey.results item
|
|
stdout: "mock_private_key_2" # This is the command output
|
|
changed: true
|
|
rc: 0
|
|
failed: false
|
|
finished: true
|
|
wireguard_pki_path: "/tmp/test-wireguard-pki"
|
|
|
|
tasks:
|
|
- name: Create test directories
|
|
file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
mode: '0700'
|
|
loop:
|
|
- "{{ wireguard_pki_path }}/private"
|
|
- "{{ wireguard_pki_path }}/preshared"
|
|
|
|
- name: Test private key saving (using with_items like the actual code)
|
|
copy:
|
|
dest: "{{ wireguard_pki_path }}/private/{{ item.item }}"
|
|
content: "{{ item.stdout }}"
|
|
mode: "0600"
|
|
when: item.changed
|
|
with_items: "{{ mock_wg_genkey_results.results }}"
|
|
|
|
- name: Verify files were created correctly
|
|
stat:
|
|
path: "{{ wireguard_pki_path }}/private/{{ item }}"
|
|
register: file_check
|
|
loop:
|
|
- "user1"
|
|
- "10.10.10.1"
|
|
|
|
- name: Assert files exist
|
|
assert:
|
|
that:
|
|
- item.stat.exists
|
|
- item.stat.mode == "0600"
|
|
msg: "Private key file should exist with correct permissions"
|
|
loop: "{{ file_check.results }}"
|
|
|
|
- name: Verify file contents
|
|
slurp:
|
|
src: "{{ wireguard_pki_path }}/private/{{ item }}"
|
|
register: file_contents
|
|
loop:
|
|
- "user1"
|
|
- "10.10.10.1"
|
|
|
|
- name: Assert file contents are correct
|
|
assert:
|
|
that:
|
|
- (file_contents.results[0].content | b64decode) == "mock_private_key_1"
|
|
- (file_contents.results[1].content | b64decode) == "mock_private_key_2"
|
|
msg: "File contents should match expected values"
|
|
|
|
# Test the error handling path too
|
|
- name: Test error condition handling
|
|
debug:
|
|
msg: "Would display error for {{ item.item }}"
|
|
when: item.rc is defined and item.rc != 0
|
|
loop: "{{ mock_wg_genkey_results.results }}"
|
|
# This should not trigger since our mock data has rc: 0
|
|
|
|
- name: Cleanup test directory
|
|
file:
|
|
path: "{{ wireguard_pki_path }}"
|
|
state: absent
|