diff --git a/roles/xmpp_server/molecule/default/tests/test_client.py b/roles/xmpp_server/molecule/default/tests/test_client.py index c099fd7c3bb6cf1ecbb38e22f5b38d3a0992609c..7925f1e4f7552b708133eff6d4d4c267fba502c1 100644 --- a/roles/xmpp_server/molecule/default/tests/test_client.py +++ b/roles/xmpp_server/molecule/default/tests/test_client.py @@ -1,4 +1,5 @@ import os +import time import uuid import pytest @@ -153,3 +154,89 @@ def test_http_file_upload(host, username, password, domain, server): assert uploaded_file.group == "prosody" assert uploaded_file.mode == 0o640 assert uploaded_file.content_string == expected_content + + +@pytest.mark.parametrize("username, password, domain, server", [ + ["john.doe", "johnpassword", "domain1", "parameters-mandatory"], + ["jane.doe", "janepassword", "domain2", "parameters-optional"], + ["mick.doe", "mickpassword", "domain3", "parameters-optional"], +]) +def test_http_file_share_size_limit(host, username, password, domain, server): + """ + Tests the maximum file size for files uploaded via XEP-0363. + """ + + file_size_limit = 10 * 1024 * 1024 + + # Find the host that serves the domain. Used for validating uploaded content. + ansible_facts = host.ansible("setup")["ansible_facts"] + ansible_distribution_release = ansible_facts['ansible_distribution_release'] + ansible_runner = testinfra.utils.ansible_runner.AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']) + server_host = ansible_runner.get_host(ansible_runner.get_hosts(f'{server}-{ansible_distribution_release}')[0]) + + # Clean up leftovers from previous run. + with server_host.sudo(): + server_host.run("rm -rf %s/*", f"/var/lib/prosody/upload%2e{domain}/") + server_host.run("systemctl restart prosody") + time.sleep(1) + + # Test exact size limit. + create_sample_file = host.run("dd if=/dev/zero of=/tmp/http_file_upload_sample.txt bs=%sB count=1", str(file_size_limit)) + assert create_sample_file.rc == 0 + + send = host.run(f"go-sendxmpp --debug --username {username}@{domain} --password {password} --jserver {domain}:5222 " + f"--http-upload /tmp/http_file_upload_sample.txt " + f"{username}@{domain}") + assert "file-too-large" not in send.stderr + + # Test exceeded size limit. + create_sample_file = host.run("dd if=/dev/zero of=/tmp/http_file_upload_sample.txt bs=%sB count=1", str(file_size_limit + 1)) + assert create_sample_file.rc == 0 + + send = host.run(f"go-sendxmpp --debug --username {username}@{domain} --password {password} --jserver {domain}:5222 " + f"--http-upload /tmp/http_file_upload_sample.txt " + f"{username}@{domain}") + assert "file-too-large" in send.stderr + + +@pytest.mark.parametrize("username, password, domain, server", [ + ["john.doe", "johnpassword", "domain1", "parameters-mandatory"], + ["jane.doe", "janepassword", "domain2", "parameters-optional"], + ["mick.doe", "mickpassword", "domain3", "parameters-optional"], +]) +def test_http_file_share_daily_quota(host, username, password, domain, server): + """ + Tests the user's daily quota for files uploaded via XEP-0363. + """ + + file_size_limit = 10 * 1024 * 1024 + + # Find the host that serves the domain. Used for validating uploaded content. + ansible_facts = host.ansible("setup")["ansible_facts"] + ansible_distribution_release = ansible_facts['ansible_distribution_release'] + ansible_runner = testinfra.utils.ansible_runner.AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']) + server_host = ansible_runner.get_host(ansible_runner.get_hosts(f'{server}-{ansible_distribution_release}')[0]) + + # Clean up leftovers from previous run. + with server_host.sudo(): + server_host.run("rm -rf %s/*", f"/var/lib/prosody/upload%2e{domain}/") + server_host.run("systemctl restart prosody") + time.sleep(1) + + # Fill-up the daily quota. + create_sample_file = host.run("dd if=/dev/zero of=/tmp/http_file_upload_sample.txt bs=%sB count=1", str(file_size_limit)) + assert create_sample_file.rc == 0 + for _ in range(10): + send = host.run(f"go-sendxmpp --debug --username {username}@{domain} --password {password} --jserver {domain}:5222 " + f"--http-upload /tmp/http_file_upload_sample.txt " + f"{username}@{domain}") + assert send.rc == 0 + + # Test exceeded daily quota. + create_sample_file = host.run("dd if=/dev/zero of=/tmp/http_file_upload_sample.txt bs=1B count=1") + assert create_sample_file.rc == 0 + + send = host.run(f"go-sendxmpp --debug --username {username}@{domain} --password {password} --jserver {domain}:5222 " + f"--http-upload /tmp/http_file_upload_sample.txt " + f"{username}@{domain}") + assert "Daily quota reached" in send.stderr