Changeset - 9bc79c136d4f
[Not reviewed]
0 2 0
Branko Majic (branko) - 10 months ago 2025-01-22 15:22:57
branko@majic.rs
MAR-233: Replace hping3 with nmap in connectivity tests for the xmpp_server role:

- Parametrize the connectivity tests instead of running them in a
loop.
2 files changed with 6 insertions and 13 deletions:
0 comments (0 inline, 0 general)
roles/xmpp_server/molecule/default/prepare.yml
Show inline comments
 
@@ -90,29 +90,24 @@
 
        state: present
 
      with_dict:
 
        192.168.56.11: "ldap-server backup-server"
 
        192.168.56.21: "client-bookworm"
 
        192.168.56.31: "parameters-mandatory domain1 proxy.domain1 conference.domain1"
 
        192.168.56.32: "parameters-optional domain2 proxy.domain2 conference.domain2 domain3 proxy.domain3 conference.domain3"
 

	
 
- name: Prepare, helpers
 
  hosts: clients
 
  become: true
 
  tasks:
 

	
 
    - name: Install tool for testing TCP connectivity
 
      ansible.builtin.apt:
 
        name: hping3
 
        state: present
 

	
 
    - name: Deploy CA certificate
 
      ansible.builtin.copy:
 
        src: tests/data/x509/ca/level1.cert.pem
 
        dest: /usr/local/share/ca-certificates/testca.crt
 
        owner: root
 
        group: root
 
        mode: "0644"
 
      notify:
 
        - Update CA certificate cache
 

	
 
    - name: Install console-based XMPP client (for interactive testing)
 
      ansible.builtin.apt:
roles/xmpp_server/molecule/default/tests/test_client.py
Show inline comments
 
import os
 

	
 
import pytest
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('clients')
 

	
 

	
 
def test_connectivity(host):
 
@pytest.mark.parametrize('server', ['parameters-mandatory', 'parameters-optional'])
 
@pytest.mark.parametrize('port', [5222, 5223, 5000, 5269])
 
def test_connectivity(host, server, port):
 
    """
 
    Tests connectivity to the XMPP server (ports that should be reachable).
 
    """
 

	
 
    with host.sudo():
 

	
 
        for server in ["parameters-mandatory",
 
                       "parameters-optional"]:
 
            # c2s plaintext, c2s TLS, file proxy, s2s.
 
            for port in [5222, 5223, 5000, 5269]:
 

	
 
                ping = host.run('hping3 -S -p %s -c 1 %s', str(port), server)
 
                assert ping.rc == 0
 
        scan = host.run('nmap -p %s -oG - %s', str(port), server)
 
        assert scan.rc == 0
 
        assert "Ports: %d/open/tcp//" % port in scan.stdout
 

	
 

	
 
@pytest.mark.parametrize("username, password, domain", [
 
    ["john.doe", "johnpassword", "domain1"],
 
    ["jane.doe", "janepassword", "domain2"],
 
])
 
def test_tls(host, username, password, domain):
 
    """
 
    Tests if TLS works as expected.
 
    """
 

	
 
    send = host.run(f"echo 'Hello' | go-sendxmpp --debug "
0 comments (0 inline, 0 general)