From c8d53674089b0358c504ce839a6bb30936f42517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sara=20Aim=C3=A9e=20Smiseth?= <51710585+SaraSmiseth@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:24:23 +0200 Subject: [PATCH] wip tests 2 --- .gitignore | 1 + tests/docker-compose.yml | 15 +++++++----- tests/test.py | 50 ++++++++++++++++++++++++++++++++++++++++ tests/test.zsh | 18 +++++++++++---- 4 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 tests/test.py diff --git a/.gitignore b/.gitignore index 8e23fc8..002f5f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ data/* tests/certs/ +tests/venv/ diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 249f6ee..92e1d7b 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -11,13 +11,16 @@ services: - "5269:5269" - "5281:5281" environment: - DOMAIN: prosody - PROSODY_ADMINS: "admin@prosody, admin2@prosody" + DOMAIN: localhost + E2E_POLICY_CHAT: optional + E2E_POLICY_MUC: optional + LOG_LEVEL: debug + PROSODY_ADMINS: "admin@localhost, admin2@localhost" extra_hosts: - - "conference.prosody:127.0.0.1" - - "pubsub.prosody:127.0.0.1" - - "proxy.prosody:127.0.0.1" - - "upload.prosody:127.0.0.1" + - "conference.localhost:127.0.0.1" + - "pubsub.localhost:127.0.0.1" + - "proxy.localhost:127.0.0.1" + - "upload.localhost:127.0.0.1" volumes: - ./certs:/usr/local/etc/prosody/certs #- ./data:/usr/local/var/lib/prosody diff --git a/tests/test.py b/tests/test.py new file mode 100644 index 0000000..b80e383 --- /dev/null +++ b/tests/test.py @@ -0,0 +1,50 @@ +import asyncio +import aioxmpp +import aioxmpp.dispatcher + +jid = aioxmpp.JID.fromstr("admin@localhost") +recipient_jid = aioxmpp.JID.fromstr("admin@localhost") +password = "12345678" + +client = aioxmpp.PresenceManagedClient( + jid, + aioxmpp.make_security_layer( + password, + no_verify=True + ), +) + +def message_received(msg): + print(msg) + print(msg.body) + +# obtain an instance of the service +message_dispatcher = client.summon( + aioxmpp.dispatcher.SimpleMessageDispatcher +) + +# register a message callback here +message_dispatcher.register_callback( + aioxmpp.MessageType.CHAT, + None, + message_received, +) + +async def sendMessage(): + 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) + +def main(): + loop = asyncio.get_event_loop() + loop.run_until_complete(sendMessage()) + loop.close() + +if __name__ == '__main__': + main() diff --git a/tests/test.zsh b/tests/test.zsh index a1a43b3..870e43a 100755 --- a/tests/test.zsh +++ b/tests/test.zsh @@ -11,8 +11,16 @@ generateCert() { cd ../../ } -generateCert "prosody" -generateCert "conference.prosody" -generateCert "pubsub.prosody" -generateCert "proxy.prosody" -generateCert "upload.prosody" +generateCert "localhost" +generateCert "conference.localhost" +generateCert "pubsub.localhost" +generateCert "proxy.localhost" +generateCert "upload.localhost" + +sudo docker-compose up -d + +sudo docker exec tests_prosody_1 /bin/bash -c "/entrypoint.sh register admin localhost 12345678" + +python test.py + +sudo docker-compose down