# SPDX-License-Identifier: BSD-3-Clause
---
- name: Play for testing wireless connection
  hosts: all
  vars:
    interface: wlan0
  tasks:
    - name: "INIT: wireless tests"
      debug:
        msg: "##################################################"
    - name: Include the task 'setup_mock_wifi_wpa3_owe.yml'
      include_tasks: tasks/setup_mock_wifi_wpa3_owe.yml
    - name: Test wireless connection with OWE
      block:
        - name: "TEST: wireless connection with OWE"
          debug:
            msg: "##################################################"
        - name: Import network role
          import_role:
            name: linux-system-roles.network
          vars:
            network_allow_restart: true
            network_connections:
              - name: "{{ interface }}"
                state: up
                type: wireless
                ip:
                  address:
                    - 203.0.113.2/24
                  dhcp4: "no"
                  auto6: "no"
                wireless:
                  ssid: "hostapd-owe"
                  key_mgmt: "owe"

        - name: "Verify connection profile"
          shell: nmcli c show {{ interface }} | grep 802-11-wireless-security.key-mgmt
          register: key_mgmt
          ignore_errors: true
          changed_when: false

        - name: "Assert that OWE is configured correctly"
          assert:
            that:
              - "'owe' in key_mgmt.stdout"
            msg: "OWE is configured incorrectly"
      always:
        - name: Clean up the test device and the connection profile
          tags:
            - "tests::cleanup"
          block:
            - name: Import network role
              import_role:
                name: linux-system-roles.network
              vars:
                network_connections:
                  - name: "{{ interface }}"
                    persistent_state: absent
                    state: down
              failed_when: false
            - name: Include the task 'cleanup_mock_wifi.yml'
              include_tasks: tasks/cleanup_mock_wifi.yml
            - name: Verify network state restored to default
              include_tasks: tasks/check_network_dns.yml
