Changeset - 3c51248b600c
[Not reviewed]
0 4 0
Branko Majic (branko) - 2 months ago 2024-03-03 11:38:32
branko@majic.rs
MAR-192: Switch to using go-sendxmpp where possible for testing XMPP server role:

- The sendxmpp in Debian 12 Bookworm is quite broken at this point,
and go-sendxmpp is somewhat close in terms of interface etc.
- Fix a number of tests related to sending messages.
4 files changed with 58 insertions and 27 deletions:
0 comments (0 inline, 0 general)
roles/xmpp_server/molecule/default/molecule.yml
Show inline comments
 
@@ -38,7 +38,11 @@ platforms:
 
    groups:
 
      - clients
 
      - bullseye
 
    box: debian/bullseye64
 
    # Use Bookworm client box for testing Bullseye servers to avoid
 
    # duplication of test code in test_client.py due to missing
 
    # functional build of go-sendxmpp for the Bullseye release (glibc
 
    # mismatch in prebuilt package).
 
    box: debian/bookworm64
 
    memory: 256
 
    cpus: 1
 
    provider_raw_config_args:
roles/xmpp_server/molecule/default/prepare.yml
Show inline comments
 
@@ -183,7 +183,7 @@
 

	
 
    - name: Install console-based XMPP tool (for non-interactive testing)
 
      apt:
 
        name: sendxmpp
 
        name: go-sendxmpp
 
        state: present
 

	
 
    - name: Create dedicated group for testing
 
@@ -308,8 +308,10 @@
 

	
 
    - name: Install console-based XMPP tool (for non-interactive testing)
 
      apt:
 
        name: sendxmpp
 
        name: "{{ sendxmpp_package }}"
 
        state: present
 
      vars:
 
        sendxmpp_package: "{% if ansible_distribution_release == 'bullseye' %}sendxmpp{% else %}go-sendxmpp{% endif %}"
 

	
 
    - name: Deploy small Lua script for listing the enabled modules in Prosody
 
      copy:
roles/xmpp_server/molecule/default/tests/test_backup.py
Show inline comments
 
@@ -12,15 +12,30 @@ def test_backup(host):
 
    Tests if Prosody data directory is correctly backed-up.
 
    """
 

	
 
    # Deliver a couple of messages in order to make sure the directory structure
 
    # is created.
 
    send = host.run("echo 'Hello' | sendxmpp --tls-ca-path /usr/local/share/ca-certificates/testca.crt "
 
                    "-t -u jane.doe -p janepassword -j domain2:5222 jane.doe@domain2")
 
    assert send.rc == 0
 

	
 
    send = host.run("echo 'Hello' | sendxmpp --tls-ca-path /usr/local/share/ca-certificates/testca.crt "
 
                    "-t -u mick.doe -p mickpassword -j domain3:5222 mick.doe@domain3")
 
    assert send.rc == 0
 
    distribution_release = host.ansible("setup")["ansible_facts"]["ansible_distribution_release"]
 

	
 
    # Ugly, but functional for now.
 
    if distribution_release == "bullseye":
 
        # Deliver a couple of messages in order to make sure the directory structure
 
        # is created.
 
        send = host.run("echo 'Hello' | sendxmpp --tls-ca-path /usr/local/share/ca-certificates/testca.crt "
 
                        "-t -u jane.doe -p janepassword -j domain2:5222 jane.doe@domain2")
 
        assert send.rc == 0
 

	
 
        send = host.run("echo 'Hello' | sendxmpp --tls-ca-path /usr/local/share/ca-certificates/testca.crt "
 
                        "-t -u mick.doe -p mickpassword -j domain3:5222 mick.doe@domain3")
 
        assert send.rc == 0
 
    else:
 
        send = host.run(f"echo 'Hello' | go-sendxmpp --debug "
 
                        f"--username jane.doe@domain2 --password janepassword --jserver domain2:5222 "
 
                        f"jane.doe@domain2")
 
        assert send.rc == 0
 

	
 
        send = host.run(f"echo 'Hello' | go-sendxmpp --debug "
 
                        f"--username mick.doe@domain3 --password mickpassword --jserver domain3:5222 "
 
                        f"mick.doe@domain3")
 
        assert send.rc == 0
 

	
 

	
 
    with host.sudo():
 

	
roles/xmpp_server/molecule/default/tests/test_client.py
Show inline comments
 
@@ -34,13 +34,17 @@ def test_tls(host, username, password, domain):
 
    Tests if TLS works as expected.
 
    """
 

	
 
    send = host.run(f"echo 'Hello' | sendxmpp --tls-ca-path /usr/local/share/ca-certificates/testca.crt "
 
                    f"-t -u {username} -p {password} -j {domain}:5222 {username}@{domain}")
 
    send = host.run(f"echo 'Hello' | go-sendxmpp --debug "
 
                    f"--username {username}@{domain} --password {password} --jserver {domain}:5222 "
 
                    f"{username}@{domain}")
 
    assert send.rc == 0
 
    assert "<body>Hello</body>" in send.stderr
 

	
 
    send = host.run(f"echo 'Hello' | sendxmpp --tls-ca-path /usr/local/share/ca-certificates/testca.crt "
 
                    f"-e -u {username} -p {password} -j {domain}:5223 {username}@{domain}")
 
    send = host.run(f"echo 'Hello' | go-sendxmpp --debug --tls "
 
                    f"--username {username}@{domain} --password {password} --jserver {domain}:5223 "
 
                    f"{username}@{domain}")
 
    assert send.rc == 0
 
    assert "<body>Hello</body>" in send.stderr
 

	
 

	
 
@pytest.mark.parametrize("username, password, domain", [
 
@@ -49,12 +53,15 @@ def test_tls(host, username, password, domain):
 
])
 
def test_authentication_requires_tls(host, username, password, domain):
 
    """
 
    Tests if authentication must be done over TLS.
 
    Tests if STARTTLS is required.
 
    """
 

	
 
    command = host.run(f"echo 'Hello' | sendxmpp --tls-ca-path /usr/local/share/ca-certificates/testca.crt "
 
                       f"-u {username} -p {password} -j {domain}:5222 {username}@{domain} -d")
 
    assert "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required/></starttls>" in command.stderr
 
    send = host.run(f"echo 'Hello' | go-sendxmpp --debug "
 
                    f"--username {username}@{domain} --password {password} --jserver {domain}:5222 "
 
                    f"{username}@{domain}")
 

	
 
    assert send.rc == 0
 
    assert "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required/></starttls>" in send.stderr
 

	
 

	
 
@pytest.mark.parametrize("username, password, domain", [
 
@@ -67,12 +74,14 @@ def test_authentication(host, username, password, domain):
 
    Tests if authentication works correctly.
 
    """
 

	
 
    send = host.run(f"echo 'Hello' | sendxmpp --tls-ca-path /usr/local/share/ca-certificates/testca.crt "
 
                    f"-t -u {username} -p {password} -j {domain}:5222 {username}@{domain}")
 
    send = host.run(f"echo 'Hello' | go-sendxmpp --debug "
 
                    f"--username {username}@{domain} --password {password} --jserver {domain}:5222 "
 
                    f"{username}@{domain}")
 
    assert send.rc == 0
 

	
 
    send = host.run(f"echo 'Hello' | sendxmpp --tls-ca-path /usr/local/share/ca-certificates/testca.crt "
 
                    f"-e -u {username} -p {password} -j {domain}:5223 {username}@{domain}")
 
    send = host.run(f"echo 'Hello' | go-sendxmpp --debug --tls "
 
                    f"--username {username}@{domain} --password {password} --jserver {domain}:5223 "
 
                    f"{username}@{domain}")
 
    assert send.rc == 0
 

	
 

	
 
@@ -86,7 +95,8 @@ def test_unauthorized_users_rejected(host, target_username, target_domain):
 
    group) are rejected from accessing the XMPP server.
 
    """
 

	
 
    send = host.run(f"echo 'Hello' | sendxmpp --tls-ca-path /usr/local/share/ca-certificates/testca.crt "
 
                    f"-t -u noxmpp -p noxmpppassword -j {target_domain}:5222 {target_username}@{target_domain}")
 
    send = host.run(f"echo 'Hello' | go-sendxmpp --debug "
 
                    f"--username noxmpp@{target_domain} --password noxmpppassword --jserver {target_domain}:5222 "
 
                    f"{target_username}@{target_domain}")
 
    assert send.rc != 0
 
    assert "Error 'AuthSend': error: not-authorized[?]" in send.stderr
 
    assert "Unable to authorize you with the authentication credentials you've sent" in send.stderr
0 comments (0 inline, 0 general)