Example #1
0
async def test_confserver_exceptions():
    with LogCapture() as l:

        conf_server = bumper.ConfServer(("127.0.0.1", 8007), usessl=True)
        conf_server.confserver_app()
        conf_server.site = web.TCPSite

        #bind permission
        conf_server.site.start = mock.Mock(side_effect=OSError(
            1,
            "error while attempting to bind on address ('127.0.0.1', 8007): permission denied"
        ))
        await conf_server.start_server()

        #asyncio Cancel
        conf_server.site = web.TCPSite
        conf_server.site.start = mock.Mock(side_effect=asyncio.CancelledError)
        await conf_server.start_server()

        #general exception
        conf_server.site = web.TCPSite
        conf_server.site.start = mock.Mock(side_effect=Exception(1, "general"))
        await conf_server.start_server()

    l.check_present((
        "confserver", "ERROR",
        "error while attempting to bind on address ('127.0.0.1', 8007): permission denied"
    ))
Example #2
0
#!/usr/bin/env python3

import logging
import bumper
import sys, socket

logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s %(levelname)-8s %(message)s')

conf_address = (socket.gethostbyname(socket.gethostname()), 8007)
xmpp_address = (socket.gethostbyname(socket.gethostname()), 5223)

# start conf server (async)
conf_server = bumper.ConfServer(conf_address, ssl=False, async=True)

# start xmpp server (sync)
xmpp_server = bumper.XMPPServer(xmpp_address)

conf_server.disconnect()
Example #3
0
xmpp_address = (listen_host, 5223)
mqtt_address = (listen_host, 8883)

# start mqtt server on port 8883 (async)
mqtt_server = bumper.MQTTServer(mqtt_address,
                                run_async=True,
                                bumper_bots=bumper.bumper_bots_var,
                                bumper_clients=bumper.bumper_clients_var)
time.sleep(1.5)  #Wait for broker startup
# start mqtt_helperbot (async)
mqtt_helperbot = bumper.MQTTHelperBot(mqtt_address,
                                      run_async=True,
                                      bumper_bots=bumper.bumper_bots_var,
                                      bumper_clients=bumper.bumper_clients_var)
# start conf server on port 443 (async) - Used for most https calls
conf_server = bumper.ConfServer(conf_address_443,
                                usessl=True,
                                run_async=True,
                                bumper_bots=bumper.bumper_bots_var,
                                bumper_clients=bumper.bumper_clients_var,
                                helperbot=mqtt_helperbot)
# start conf server on port 8007 (async) - Used for a load balancer request
conf_server_2 = bumper.ConfServer(conf_address_8007,
                                  usessl=False,
                                  run_async=True,
                                  bumper_bots=bumper.bumper_bots_var,
                                  bumper_clients=bumper.bumper_clients_var,
                                  helperbot=mqtt_helperbot)
# start xmpp server on port 5223 (sync)
xmpp_server = bumper.XMPPServer(xmpp_address)
Example #4
0
async def test_confserver_no_ssl():
    conf_server = bumper.ConfServer(("127.0.0.1", 111111), usessl=False)
    conf_server.confserver_app()
    asyncio.create_task(conf_server.start_server())
Example #5
0
def create_app(loop):
    confserver = bumper.ConfServer("127.0.0.1:11111", False)
    confserver.confserver_app()
    return confserver.app
Example #6
0
def create_confserver():
    return bumper.ConfServer("127.0.0.1:11111", False)
Example #7
0
from nose.tools import *
import mock
import bumper
import asyncio
import os
import json
import tinydb
from aiohttp.test_utils import TestClient, TestServer, loop_context
from aiohttp import request

confserver = bumper.ConfServer("127.0.0.1:11111", False, mock.MagicMock)
confserver.confserver_app()
app = confserver.app


def async_return(result):
    f = asyncio.Future()
    f.set_result(result)
    return f


def test_disconnect():
    confserver.disconnect()


def test_base():
    if os.path.exists("tests/tmp.db"):
        os.remove("tests/tmp.db")  # Remove existing db
    bumper.db = "tests/tmp.db"  # Set db location for testing
    loop = asyncio.get_event_loop()
    client = TestClient(TestServer(app), loop=loop)
Example #8
0
def main():
    args = sys.argv

    if len(args) > 0:
        if "--debug" in args:
            logging.basicConfig(
                level=logging.DEBUG,
                format=
                "[%(asctime)s] :: %(levelname)s :: %(name)s :: %(module)s :: %(funcName)s :: %(lineno)d :: %(message)s",
            )
        else:
            logging.basicConfig(
                level=logging.INFO,
                format=
                "[%(asctime)s] :: %(levelname)s :: %(name)s :: %(message)s",
            )
            # format="[%(asctime)s] :: %(levelname)s :: %(name)s :: %(module)s :: %(funcName)s :: %(lineno)d :: %(message)s")

    if platform.system() == "Darwin":  # If a Mac, use 0.0.0.0 for listening
        listen_host = "0.0.0.0"
    else:
        listen_host = socket.gethostbyname(socket.gethostname())
        #listen_host = "localhost"  # Try this if the above doesn't work

    conf_address_443 = (listen_host, 443)
    conf_address_8007 = (listen_host, 8007)
    xmpp_address = (listen_host, 5223)
    mqtt_address = (listen_host, 8883)

    xmpp_server = bumper.XMPPServer(xmpp_address)
    mqtt_server = bumper.MQTTServer(mqtt_address)
    mqtt_helperbot = bumper.MQTTHelperBot(mqtt_address)
    conf_server = bumper.ConfServer(conf_address_443,
                                    usessl=True,
                                    helperbot=mqtt_helperbot)
    conf_server_2 = bumper.ConfServer(conf_address_8007,
                                      usessl=False,
                                      helperbot=mqtt_helperbot)

    # add user
    # users = bumper.bumper_users_var.get()
    # user1 = bumper.BumperUser('user1')
    # user1.add_device('devid')
    # user1.add_bot('bot_did')
    # users.append(user1)
    # bumper.bumper_users_var.set(users)

    # start xmpp server on port 5223 (sync)
    xmpp_server.run(run_async=True)  # Start in new thread

    # start mqtt server on port 8883 (async)
    mqtt_server.run(run_async=True)  # Start in new thread

    time.sleep(1.5)  # Wait for broker startup

    # start mqtt_helperbot (async)
    mqtt_helperbot.run(run_async=True)  # Start in new thread

    # start conf server on port 443 (async) - Used for most https calls
    conf_server.run(run_async=True)  # Start in new thread

    # start conf server on port 8007 (async) - Used for a load balancer request
    conf_server_2.run(run_async=True)  # Start in new thread

    while True:
        try:
            time.sleep(30)
            bumper.revoke_expired_tokens()
            disconnected_clients = bumper.get_disconnected_xmpp_clients()
            for client in disconnected_clients:
                xmpp_server.remove_client_byuid(client["userid"])

        except KeyboardInterrupt:
            bumper.bumperlog.info("Bumper Exiting - Keyboard Interrupt")
            print("Bumper Exiting")
            exit(0)