fix tests
- added kwargs for mqttserver init - passwd_file and allow_anonymous - removed unused tests and sleeps
This commit is contained in:
parent
cb693b5cf6
commit
6da98acdad
3 changed files with 58 additions and 171 deletions
|
|
@ -62,7 +62,7 @@ async def test_base(aiohttp_client):
|
|||
|
||||
# Start MQTT
|
||||
mqtt_address = ("127.0.0.1", 8883)
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address)
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address, password_file="tests/passwd")
|
||||
bumper.mqtt_server = mqtt_server
|
||||
await mqtt_server.broker_coro()
|
||||
|
||||
|
|
@ -84,7 +84,6 @@ async def test_base(aiohttp_client):
|
|||
mqtt_helperbot.Client.disconnect()
|
||||
|
||||
await mqtt_server.broker.shutdown()
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
bumper.xmpp_server.disconnect()
|
||||
|
||||
|
|
@ -95,7 +94,7 @@ async def test_restartService(aiohttp_client):
|
|||
|
||||
# Start MQTT
|
||||
mqtt_address = ("127.0.0.1", 8883)
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address)
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address, password_file="tests/passwd")
|
||||
bumper.mqtt_server = mqtt_server
|
||||
await mqtt_server.broker_coro()
|
||||
|
||||
|
|
@ -123,7 +122,6 @@ async def test_restartService(aiohttp_client):
|
|||
|
||||
mqtt_helperbot.Client.disconnect()
|
||||
await mqtt_server.broker.shutdown()
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
xmpp_server.disconnect()
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import time
|
|||
|
||||
async def test_helperbot_message():
|
||||
mqtt_address = ("127.0.0.1", 8883)
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address)
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address, password_file="tests/passwd")
|
||||
await mqtt_server.broker_coro()
|
||||
|
||||
with LogCapture() as l:
|
||||
|
|
@ -154,12 +154,11 @@ async def test_helperbot_message():
|
|||
mqtt_helperbot.Client.disconnect()
|
||||
|
||||
await mqtt_server.broker.shutdown()
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
|
||||
async def test_helperbot_expire_message():
|
||||
mqtt_address = ("127.0.0.1", 8883)
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address)
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address, password_file="tests/passwd")
|
||||
await mqtt_server.broker_coro()
|
||||
|
||||
with LogCapture("helperbot") as l:
|
||||
|
|
@ -188,7 +187,7 @@ async def test_helperbot_expire_message():
|
|||
"payload": expire_msg_payload,
|
||||
} in mqtt_helperbot.command_responses # check message is in command_responses
|
||||
|
||||
await asyncio.sleep(0.2)
|
||||
await asyncio.sleep(0.1)
|
||||
mqtt_helperbot.expire_msg_seconds = (
|
||||
0.1
|
||||
) # Set expire message seconds to 0.1 so we don't wait 10 seconds
|
||||
|
|
@ -221,12 +220,12 @@ async def test_helperbot_expire_message():
|
|||
mqtt_helperbot.Client.disconnect()
|
||||
|
||||
await mqtt_server.broker.shutdown()
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
|
||||
|
||||
async def test_helperbot_sendcommand():
|
||||
mqtt_address = ("127.0.0.1", 8883)
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address)
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address, password_file="tests/passwd")
|
||||
await mqtt_server.broker_coro()
|
||||
|
||||
mqtt_helperbot = bumper.MQTTHelperBot(mqtt_address)
|
||||
|
|
@ -370,7 +369,7 @@ async def test_helperbot_sendcommand():
|
|||
mqtt_helperbot.Client.disconnect()
|
||||
|
||||
await mqtt_server.broker.shutdown()
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
|
||||
|
||||
async def test_mqttserver():
|
||||
|
|
@ -381,26 +380,7 @@ async def test_mqttserver():
|
|||
|
||||
mqtt_address = ("127.0.0.1", 8883)
|
||||
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address)
|
||||
|
||||
mqtt_server.default_config = {
|
||||
"listeners": {
|
||||
"default": {"type": "tcp"},
|
||||
"tls1": {
|
||||
"bind": "{}:{}".format(mqtt_address[0], mqtt_address[1]),
|
||||
"ssl": "on",
|
||||
"certfile": bumper.server_cert,
|
||||
"keyfile": bumper.server_key,
|
||||
},
|
||||
},
|
||||
"sys_interval": 10,
|
||||
"auth": {
|
||||
"allow-anonymous": True, # Set to True to allow anonymous authentication
|
||||
"password-file": "tests/passwd", # For file auth, set user:hash in passwd file see (https://hbmqtt.readthedocs.io/en/latest/references/hbmqtt.html#configuration-example)
|
||||
"plugins": ["bumper"], # Bumper plugin provides auth and handling of bots/clients connecting
|
||||
},
|
||||
"topic-check": {"enabled": False},
|
||||
}
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address, password_file="tests/passwd", allow_anonymous=True)
|
||||
|
||||
await mqtt_server.broker_coro()
|
||||
|
||||
|
|
@ -466,148 +446,47 @@ async def test_mqttserver():
|
|||
) # Check client is disconnected
|
||||
|
||||
# bad password
|
||||
try:
|
||||
await test_client.Client.connect(
|
||||
f"mqtts://test-client:notvalid!@{test_client.address[0]}:{test_client.address[1]}/",
|
||||
cafile=bumper.ca_cert, cleansession=True
|
||||
)
|
||||
with LogCapture() as l:
|
||||
try:
|
||||
await test_client.Client.connect(
|
||||
f"mqtts://test-client:notvalid!@{test_client.address[0]}:{test_client.address[1]}/",
|
||||
cafile=bumper.ca_cert, cleansession=True
|
||||
)
|
||||
|
||||
except Exception as ae:
|
||||
pass
|
||||
|
||||
assert (
|
||||
test_client.Client._connected_state._value == False
|
||||
) # Check client is connected
|
||||
l.check_present(
|
||||
("mqttserver", "INFO", "File Authentication Failed - Username: test-client - ClientID: test-file-auth"),
|
||||
order_matters=False
|
||||
)
|
||||
# no username in file
|
||||
try:
|
||||
await test_client.Client.connect(
|
||||
f"mqtts://test-client-noexist:notvalid!@{test_client.address[0]}:{test_client.address[1]}/",
|
||||
cafile=bumper.ca_cert, cleansession=True
|
||||
)
|
||||
|
||||
except Exception as ae:
|
||||
pass
|
||||
|
||||
# no username in file
|
||||
try:
|
||||
await test_client.Client.connect(
|
||||
f"mqtts://test-client-noexist:notvalid!@{test_client.address[0]}:{test_client.address[1]}/",
|
||||
cafile=bumper.ca_cert, cleansession=True
|
||||
)
|
||||
|
||||
assert (
|
||||
test_client.Client._connected_state._value == False
|
||||
) # Check client is connected
|
||||
|
||||
except Exception as ae:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
await mqtt_server.broker.shutdown()
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
async def test_passwordfile_badhash_mqttserver():
|
||||
mqtt_address = ("127.0.0.1", 8883)
|
||||
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address)
|
||||
|
||||
mqtt_server.default_config = {
|
||||
"listeners": {
|
||||
"default": {"type": "tcp"},
|
||||
"tls1": {
|
||||
"bind": "{}:{}".format(mqtt_address[0], mqtt_address[1]),
|
||||
"ssl": "on",
|
||||
"certfile": bumper.server_cert,
|
||||
"keyfile": bumper.server_key,
|
||||
},
|
||||
},
|
||||
"sys_interval": 10,
|
||||
"auth": {
|
||||
"allow-anonymous": True, # Set to True to allow anonymous authentication
|
||||
"password-file": "tests/passwd_bad", # For file auth, set user:hash in passwd file see (https://hbmqtt.readthedocs.io/en/latest/references/hbmqtt.html#configuration-example)
|
||||
"plugins": ["bumper"], # Bumper plugin provides auth and handling of bots/clients connecting
|
||||
},
|
||||
"topic-check": {"enabled": False},
|
||||
}
|
||||
except Exception as ae:
|
||||
pass
|
||||
|
||||
await mqtt_server.broker_coro()
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
# bad password
|
||||
try:
|
||||
test_client = bumper.MQTTHelperBot(mqtt_address)
|
||||
|
||||
await test_client.Client.connect(
|
||||
f"mqtts://test-client:notvalid!@{test_client.address[0]}:{test_client.address[1]}/",
|
||||
cafile=bumper.ca_cert, cleansession=True
|
||||
l.check_present(
|
||||
("mqttserver", "INFO", 'File Authentication Failed - No Entry for Username: test-client-noexist - ClientID: test-file-auth'),
|
||||
order_matters=False
|
||||
)
|
||||
|
||||
assert (
|
||||
test_client.Client._connected_state._value == False
|
||||
) # Check client is connected
|
||||
|
||||
|
||||
except Exception as ae:
|
||||
pass
|
||||
|
||||
await mqtt_server.broker.shutdown()
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
|
||||
async def test_nofileauth_mqttserver():
|
||||
try:
|
||||
with LogCapture() as l:
|
||||
|
||||
mqtt_address = ("127.0.0.1", 8883)
|
||||
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address)
|
||||
|
||||
mqtt_server.default_config = {
|
||||
"listeners": {
|
||||
"default": {"type": "tcp"},
|
||||
"tls1": {
|
||||
"bind": "{}:{}".format(mqtt_address[0], mqtt_address[1]),
|
||||
"ssl": "on",
|
||||
"certfile": bumper.server_cert,
|
||||
"keyfile": bumper.server_key,
|
||||
},
|
||||
},
|
||||
"sys_interval": 10,
|
||||
"auth": {
|
||||
"allow-anonymous": True, # Set to True to allow anonymous authentication
|
||||
"password-file": "tests/passwd-notfound", # For file auth, set user:hash in passwd file see (https://hbmqtt.readthedocs.io/en/latest/references/hbmqtt.html#configuration-example)
|
||||
"plugins": ["bumper"], # Bumper plugin provides auth and handling of bots/clients connecting
|
||||
},
|
||||
"topic-check": {"enabled": False},
|
||||
}
|
||||
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address, password_file="tests/passwd-notfound")
|
||||
await mqtt_server.broker_coro()
|
||||
await mqtt_server.broker.shutdown()
|
||||
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
async def test_passwordfile_opt_missing_mqttserver():
|
||||
try:
|
||||
|
||||
mqtt_address = ("127.0.0.1", 8883)
|
||||
|
||||
mqtt_server = bumper.MQTTServer(mqtt_address)
|
||||
|
||||
mqtt_server.default_config = {
|
||||
"listeners": {
|
||||
"default": {"type": "tcp"},
|
||||
"tls1": {
|
||||
"bind": "{}:{}".format(mqtt_address[0], mqtt_address[1]),
|
||||
"ssl": "on",
|
||||
"certfile": bumper.server_cert,
|
||||
"keyfile": bumper.server_key,
|
||||
},
|
||||
},
|
||||
"sys_interval": 10,
|
||||
"auth": {
|
||||
"allow-anonymous": True, # Set to True to allow anonymous authentication
|
||||
|
||||
"plugins": ["bumper"], # Bumper plugin provides auth and handling of bots/clients connecting
|
||||
},
|
||||
"topic-check": {"enabled": False},
|
||||
}
|
||||
|
||||
await mqtt_server.broker_coro()
|
||||
await mqtt_server.broker.shutdown()
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
except:
|
||||
pass
|
||||
l.check_present(
|
||||
("hbmqtt.broker.plugins.bumper", "WARNING", 'Password file tests/passwd-notfound not found'),
|
||||
order_matters=False
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue