From d064d7b3deb0ac8f34dc38524c2f177076c8bbfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sara=20Aim=C3=A9e=20Smiseth?= <51710585+SaraSmiseth@users.noreply.github.com> Date: Tue, 6 Oct 2020 18:02:05 +0200 Subject: [PATCH] wip tests 6 --- tests/docker-compose.yml | 2 +- tests/test.zsh | 6 ++++- tests/test_prosody.py | 58 +++++++++++++++++++++++++++++++++------- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 67bf267..42b844a 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -14,7 +14,7 @@ services: DOMAIN: localhost #E2E_POLICY_CHAT: optional #E2E_POLICY_MUC: optional - E2E_POLICY_WHITELIST: "admin@localhost" + E2E_POLICY_WHITELIST: "admin@localhost, user1@localhost" LOG_LEVEL: debug PROSODY_ADMINS: "admin@localhost, admin2@localhost" extra_hosts: diff --git a/tests/test.zsh b/tests/test.zsh index c7b9186..96f81c3 100755 --- a/tests/test.zsh +++ b/tests/test.zsh @@ -25,8 +25,9 @@ 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 user1 localhost 12345678" \ && sudo docker exec tests_prosody_1 /bin/bash -c "/entrypoint.sh register user2 localhost 12345678" \ +&& sudo docker exec tests_prosody_1 /bin/bash -c "/entrypoint.sh register user3 localhost 12345678" \ \ && python -m venv venv \ && source venv/bin/activate \ @@ -37,6 +38,9 @@ sudo docker-compose down \ && sudo docker-compose logs | grep "message to" \ && sudo docker-compose logs | grep "type='error'" +# Received[c2s]: +# Should be five times in log + # 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 4eae692..e6c39bc 100644 --- a/tests/test_prosody.py +++ b/tests/test_prosody.py @@ -1,13 +1,13 @@ +import aiosasl import aioxmpp import aioxmpp.dispatcher import asyncio import pytest @pytest.fixture -def client(client_username): +def client(client_username, password): jid = aioxmpp.JID.fromstr(client_username) - password = "12345678" client = aioxmpp.PresenceManagedClient( jid, @@ -39,9 +39,9 @@ def client_with_message_dispatcher(client): return client @pytest.mark.asyncio -@pytest.mark.parametrize("client_username", ["admin@localhost"]) -async def test_send_message_from_admin_to_user(client): - recipient_jid = aioxmpp.JID.fromstr("user@localhost") +@pytest.mark.parametrize("client_username, password", [("admin@localhost", "12345678")]) +async def test_send_message_from_admin_to_user1(client): + recipient_jid = aioxmpp.JID.fromstr("user1@localhost") async with client.connected() as stream: msg = aioxmpp.Message( to=recipient_jid, @@ -53,7 +53,7 @@ async def test_send_message_from_admin_to_user(client): await client.send(msg) @pytest.mark.asyncio -@pytest.mark.parametrize("client_username", ["admin@localhost"]) +@pytest.mark.parametrize("client_username, password", [("admin@localhost", "12345678")]) async def test_send_message_from_admin_to_user2(client): recipient_jid = aioxmpp.JID.fromstr("user2@localhost") async with client.connected() as stream: @@ -61,21 +61,59 @@ async def test_send_message_from_admin_to_user2(client): 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): +@pytest.mark.parametrize("client_username, password", [("user1@localhost", "12345678")]) +async def test_send_message_from_user1_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, password", [("user2@localhost", "12345678")]) +async def test_send_message_from_user2_to_user3(client): + recipient_jid = aioxmpp.JID.fromstr("user3@localhost") + async with client.connected() as stream: + msg = aioxmpp.Message( + to=recipient_jid, + type_=aioxmpp.MessageType.CHAT, + ) + msg.body[None] = "Hello World!" + + await client.send(msg) + +@pytest.mark.asyncio +@pytest.mark.parametrize("client_username, password", [("user2@localhost", "12345678")]) +async def test_send_message_from_user2_to_nonexisting(client): + recipient_jid = aioxmpp.JID.fromstr("nonexisting@localhost") + async with client.connected() as stream: + msg = aioxmpp.Message( + to=recipient_jid, + type_=aioxmpp.MessageType.CHAT, + ) + msg.body[None] = "Hello World!" + + await client.send(msg) + +@pytest.mark.asyncio +@pytest.mark.parametrize("client_username, password", [("user2@localhost", "wrong password")]) +async def test_can_not_log_in_with_wrong_password(client): + with pytest.raises(aiosasl.AuthenticationFailure): + recipient_jid = aioxmpp.JID.fromstr("nonexisting@localhost") + async with client.connected() as stream: + msg = aioxmpp.Message( + to=recipient_jid, + type_=aioxmpp.MessageType.CHAT, + ) + msg.body[None] = "Hello World!" + + await client.send(msg)