Compare commits
No commits in common. "20d4998c6374df859d219ff26231c2f7357bc02e" and "464d721af65a2fe36261fde933544e3627e38a8d" have entirely different histories.
20d4998c63
...
464d721af6
@ -4,5 +4,3 @@ PASSWORD = bottestpassword
|
|||||||
NICK = xmppbot
|
NICK = xmppbot
|
||||||
ROOM1 = testroom1@conference.localhost
|
ROOM1 = testroom1@conference.localhost
|
||||||
ROOM2 = testroom2@conference.localhost
|
ROOM2 = testroom2@conference.localhost
|
||||||
HOST = 127.0.0.1
|
|
||||||
PORT = 25222
|
|
||||||
|
37
test/test.sh
37
test/test.sh
@ -1,16 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Check if docker is installed
|
|
||||||
if ! command -v docker run &> /dev/null
|
|
||||||
then
|
|
||||||
echo "No docker detected. If you are running debian based system, you can install docker with"
|
|
||||||
echo "sudo apt install docker.io"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Docker detected"
|
|
||||||
|
|
||||||
# Run ejabberd docker as a daemon
|
# Run ejabberd docker as a daemon
|
||||||
echo "Starting ejabberd docker container"
|
|
||||||
docker run --name xmppbot-test -d -p 25222:5222 ejabberd/ecs
|
docker run --name xmppbot-test -d -p 25222:5222 ejabberd/ecs
|
||||||
|
|
||||||
# Wait few seconds for ejabberd to boot
|
# Wait few seconds for ejabberd to boot
|
||||||
@ -26,34 +15,12 @@ docker exec -it xmppbot-test bin/ejabberdctl create_room testroom1 conference.lo
|
|||||||
docker exec -it xmppbot-test bin/ejabberdctl create_room testroom2 conference.localhost localhost
|
docker exec -it xmppbot-test bin/ejabberdctl create_room testroom2 conference.localhost localhost
|
||||||
|
|
||||||
# Run xmpp mirror bot
|
# Run xmpp mirror bot
|
||||||
echo "Running xmpp mirror bot"
|
python3 ../xmppmirror &
|
||||||
python3 ../xmppmirror & XMPPMIRRORPID=$!
|
|
||||||
|
|
||||||
# Run xmpp test bot
|
# Run xmpp test bot
|
||||||
echo "Running test bot"
|
python3 testbot
|
||||||
python3 testbot & TESTBOTPID=$!
|
|
||||||
|
|
||||||
# Wait for bots to connect
|
|
||||||
sleep 10
|
|
||||||
|
|
||||||
# Wait certain amount of time for every test message in the file
|
|
||||||
for i in $(cat testmsgs.txt); do sleep 5; done
|
|
||||||
|
|
||||||
# Kill bots
|
|
||||||
if ps -p $XMPPMIRRORPID > /dev/null
|
|
||||||
then
|
|
||||||
echo "Killing xmpp mirror bot"
|
|
||||||
kill $XMPPMIRRORPID
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ps -p $TESTBOTPID > /dev/null
|
|
||||||
then
|
|
||||||
echo "Killing test bot"
|
|
||||||
kill $TESTBOTPID
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Stop and remove containter
|
# Stop and remove containter
|
||||||
echo "Stopping and removing docker container"
|
|
||||||
docker stop xmppbot-test
|
docker stop xmppbot-test
|
||||||
docker rm xmppbot-test
|
docker rm xmppbot-test
|
||||||
|
|
||||||
|
41
test/testbot
41
test/testbot
@ -3,7 +3,6 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import slixmpp
|
import slixmpp
|
||||||
import configparser
|
import configparser
|
||||||
import time
|
|
||||||
|
|
||||||
CONFIG_PATH = "./testconfig.ini"
|
CONFIG_PATH = "./testconfig.ini"
|
||||||
|
|
||||||
@ -32,23 +31,14 @@ def allmsgsrecv():
|
|||||||
for i in results2:
|
for i in results2:
|
||||||
if i[2] == 0:
|
if i[2] == 0:
|
||||||
return False
|
return False
|
||||||
return ret
|
|
||||||
|
|
||||||
# Print results and exit
|
# Print results and exit
|
||||||
def printandexit():
|
def printandexit():
|
||||||
print("Results of test:")
|
print("Results of test:")
|
||||||
print("Room1 -> Room2:")
|
|
||||||
for i in results1:
|
for i in results1:
|
||||||
if i[2] == 0:
|
print(i[0].rstrip + " : " + str(round(i[2]-i[1],2)) + " secounds")
|
||||||
print(i[0] + " : Not recieved")
|
|
||||||
else:
|
|
||||||
print(i[0].rstrip() + " : " + str(round(i[2]-i[1],2)) + " secounds")
|
|
||||||
print("Room2 -> Room1:")
|
|
||||||
for i in results2:
|
for i in results2:
|
||||||
if i[2] == 0:
|
print(i[0].rstrip + " : " + str(round(i[2]-i[1],2)) + " secounds")
|
||||||
print(i[0] + " : Not recieved")
|
|
||||||
else:
|
|
||||||
print(i[0].rstrip() + " : " + str(round(i[2]-i[1],2)) + " secounds")
|
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
def show_version():
|
def show_version():
|
||||||
@ -91,26 +81,19 @@ class MUCBot(slixmpp.ClientXMPP):
|
|||||||
|
|
||||||
def muc_message(self, msg):
|
def muc_message(self, msg):
|
||||||
rtime=time.time()
|
rtime=time.time()
|
||||||
if msg['mucnick'] == self.nick:
|
rcpt=msg['from'].bare
|
||||||
return
|
|
||||||
body="%(body)s" % msg
|
body="%(body)s" % msg
|
||||||
unknownmsg = True
|
|
||||||
if self.room1 in str(msg['from']):
|
if self.room1 in str(msg['from']):
|
||||||
for i in results2:
|
for i in results2:
|
||||||
if "admin: " + i[0] == body:
|
if i[0] == body:
|
||||||
i[2] = rtime
|
i[2] = rtime
|
||||||
unknownmsg = False
|
|
||||||
|
|
||||||
if self.room2 in str(msg['from']):
|
if self.room2 in str(msg['from']):
|
||||||
for i in results1:
|
for i in results1:
|
||||||
if "admin: " + i[0] == body:
|
if i[0] == body:
|
||||||
i[2] = rtime
|
i[2] = rtime
|
||||||
unknownmsg = False
|
|
||||||
|
|
||||||
if unknownmsg:
|
if allmsgsrecv:
|
||||||
print("Unknown message recieved: " + body)
|
|
||||||
|
|
||||||
if allmsgsrecv() is True:
|
|
||||||
printandexit()
|
printandexit()
|
||||||
|
|
||||||
|
|
||||||
@ -131,13 +114,6 @@ if __name__ == '__main__':
|
|||||||
NICK = config.get('credentials', 'NICK')
|
NICK = config.get('credentials', 'NICK')
|
||||||
ROOM1 = config.get('credentials', 'ROOM1')
|
ROOM1 = config.get('credentials', 'ROOM1')
|
||||||
ROOM2 = config.get('credentials', 'ROOM2')
|
ROOM2 = config.get('credentials', 'ROOM2')
|
||||||
HOST = None
|
|
||||||
PORT = 5222
|
|
||||||
if "host" in config.options('credentials'):
|
|
||||||
HOST = config.get('credentials', 'HOST')
|
|
||||||
if "port" in config.options('credentials'):
|
|
||||||
PORT = config.get('credentials', 'PORT')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
xmpp = MUCBot(JID, PASSWORD, NICK, ROOM1, ROOM2)
|
xmpp = MUCBot(JID, PASSWORD, NICK, ROOM1, ROOM2)
|
||||||
@ -146,9 +122,6 @@ if __name__ == '__main__':
|
|||||||
xmpp.register_plugin('xep_0199') # XMPP Ping
|
xmpp.register_plugin('xep_0199') # XMPP Ping
|
||||||
|
|
||||||
# Connect to the XMPP server and start processing XMPP stanzas.
|
# Connect to the XMPP server and start processing XMPP stanzas.
|
||||||
if HOST != None:
|
xmpp.connect(address=("localhost",25222))
|
||||||
xmpp.connect(address=(HOST,int(PORT)))
|
|
||||||
else:
|
|
||||||
xmpp.connect()
|
|
||||||
xmpp.process(forever=False)
|
xmpp.process(forever=False)
|
||||||
|
|
||||||
|
@ -4,5 +4,3 @@ PASSWORD = admintestpassword
|
|||||||
NICK = admin
|
NICK = admin
|
||||||
ROOM1 = testroom1@conference.localhost
|
ROOM1 = testroom1@conference.localhost
|
||||||
ROOM2 = testroom2@conference.localhost
|
ROOM2 = testroom2@conference.localhost
|
||||||
HOST = 127.0.0.1
|
|
||||||
PORT = 25222
|
|
||||||
|
11
xmppmirror
11
xmppmirror
@ -59,12 +59,6 @@ if __name__ == '__main__':
|
|||||||
NICK = config.get('credentials', 'NICK')
|
NICK = config.get('credentials', 'NICK')
|
||||||
ROOM1 = config.get('credentials', 'ROOM1')
|
ROOM1 = config.get('credentials', 'ROOM1')
|
||||||
ROOM2 = config.get('credentials', 'ROOM2')
|
ROOM2 = config.get('credentials', 'ROOM2')
|
||||||
HOST = None
|
|
||||||
PORT = 5222
|
|
||||||
if "host" in config.options('credentials'):
|
|
||||||
HOST = config.get('credentials', 'HOST')
|
|
||||||
if "port" in config.options('credentials'):
|
|
||||||
PORT = config.get('credentials', 'PORT')
|
|
||||||
|
|
||||||
|
|
||||||
xmpp = MUCBot(JID, PASSWORD, NICK, ROOM1, ROOM2)
|
xmpp = MUCBot(JID, PASSWORD, NICK, ROOM1, ROOM2)
|
||||||
@ -73,9 +67,6 @@ if __name__ == '__main__':
|
|||||||
xmpp.register_plugin('xep_0199') # XMPP Ping
|
xmpp.register_plugin('xep_0199') # XMPP Ping
|
||||||
|
|
||||||
# Connect to the XMPP server and start processing XMPP stanzas.
|
# Connect to the XMPP server and start processing XMPP stanzas.
|
||||||
if HOST != None:
|
xmpp.connect()
|
||||||
xmpp.connect(address=(HOST,int(PORT)))
|
|
||||||
else:
|
|
||||||
xmpp.connect()
|
|
||||||
xmpp.process()
|
xmpp.process()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user