diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 92e1d7b..67bf267 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -12,8 +12,9 @@ services: - "5281:5281" environment: DOMAIN: localhost - E2E_POLICY_CHAT: optional - E2E_POLICY_MUC: optional + #E2E_POLICY_CHAT: optional + #E2E_POLICY_MUC: optional + E2E_POLICY_WHITELIST: "admin@localhost" LOG_LEVEL: debug PROSODY_ADMINS: "admin@localhost, admin2@localhost" extra_hosts: diff --git a/tests/test.zsh b/tests/test.zsh index 4fad65f..c7b9186 100755 --- a/tests/test.zsh +++ b/tests/test.zsh @@ -19,14 +19,24 @@ generateCert "pubsub.localhost" generateCert "proxy.localhost" generateCert "upload.localhost" -sudo docker-compose up -d + # If updates are available --> update and create new version with 'pip-chill > requirements.txt' -sudo docker exec tests_prosody_1 /bin/bash -c "/entrypoint.sh register admin localhost 12345678" +sudo docker-compose down \ +&& sudo docker-compose up -d \ +\ +&& sudo docker exec tests_prosody_1 /bin/bash -c "/entrypoint.sh register admin localhost 12345678" \ +&& sudo docker exec tests_prosody_1 /bin/bash -c "/entrypoint.sh register user localhost 12345678" \ +&& sudo docker exec tests_prosody_1 /bin/bash -c "/entrypoint.sh register user2 localhost 12345678" \ +\ +&& python -m venv venv \ +&& source venv/bin/activate \ +&& pip install -r requirements.txt \ +&& pytest \ +&& deactivate \ +&& sleep 1 \ +&& sudo docker-compose logs | grep "message to" \ +&& sudo docker-compose logs | grep "type='error'" -python -m venv venv -source venv/bin/activate -pip install -r requirements.txt # If updates are available --> update and create new version with 'pip-chill > requirements.txt' -pytest -deactivate +# TODO Call bats and create tests to check log output sudo docker-compose down diff --git a/tests/test_prosody.py b/tests/test_prosody.py index 3c73893..4eae692 100644 --- a/tests/test_prosody.py +++ b/tests/test_prosody.py @@ -4,9 +4,9 @@ import asyncio import pytest @pytest.fixture -def client(): +def client(client_username): - jid = aioxmpp.JID.fromstr("admin@localhost") + jid = aioxmpp.JID.fromstr(client_username) password = "12345678" client = aioxmpp.PresenceManagedClient( @@ -19,10 +19,11 @@ def client(): return client @pytest.fixture -def client_with_messageDispatcher(client): +def client_with_message_dispatcher(client): def message_received(msg): print(msg) print(msg.body) + assert msg.body == "Hello World!" # obtain an instance of the service message_dispatcher = client.summon( @@ -38,9 +39,37 @@ def client_with_messageDispatcher(client): return client @pytest.mark.asyncio -async def test_sendMessage(client_with_messageDispatcher): - client = client_with_messageDispatcher - recipient_jid = aioxmpp.JID.fromstr("admin@localhost") +@pytest.mark.parametrize("client_username", ["admin@localhost"]) +async def test_send_message_from_admin_to_user(client): + recipient_jid = aioxmpp.JID.fromstr("user@localhost") + async with client.connected() as stream: + msg = aioxmpp.Message( + to=recipient_jid, + type_=aioxmpp.MessageType.CHAT, + ) + # None is for "default language" + msg.body[None] = "Hello World!" + + await client.send(msg) + +@pytest.mark.asyncio +@pytest.mark.parametrize("client_username", ["admin@localhost"]) +async def test_send_message_from_admin_to_user2(client): + recipient_jid = aioxmpp.JID.fromstr("user2@localhost") + async with client.connected() as stream: + msg = aioxmpp.Message( + to=recipient_jid, + type_=aioxmpp.MessageType.CHAT, + ) + # None is for "default language" + msg.body[None] = "Hello World!" + + await client.send(msg) + +@pytest.mark.asyncio +@pytest.mark.parametrize("client_username", ["user@localhost"]) +async def test_send_message_from_user_to_user2(client): + recipient_jid = aioxmpp.JID.fromstr("user2@localhost") async with client.connected() as stream: msg = aioxmpp.Message( to=recipient_jid,