Merge branch 'master' into extend-confserver-logging
This commit is contained in:
commit
75aa74f39c
13 changed files with 365 additions and 111 deletions
1
tests/passwd
Normal file
1
tests/passwd
Normal file
|
|
@ -0,0 +1 @@
|
|||
test-client:$6$e9026a738b07b5a1$WaoYMI61aIPhhjfe3FG3uzV1oqyRdLi/TvLbBbvvzFyJ7T6PrileHGkzKkJUMLGQm/dhcq0fUT8mcu2kVcjbX/
|
||||
1
tests/passwd_bad
Normal file
1
tests/passwd_bad
Normal file
|
|
@ -0,0 +1 @@
|
|||
test-client:badhash
|
||||
|
|
@ -133,7 +133,7 @@ async def test_login(aiohttp_client):
|
|||
assert "username" in jsonresp["data"]
|
||||
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
||||
# Test global_e without user
|
||||
resp = await client.get("/v1/private/us/en/dev_1234/global_e/1/0/0/user/login")
|
||||
|
|
@ -167,6 +167,25 @@ async def test_login(aiohttp_client):
|
|||
assert "uid" in jsonresp["data"]
|
||||
assert "username" in jsonresp["data"]
|
||||
|
||||
# Add a bot to db that doesn't have a did
|
||||
newbot = {
|
||||
"class": "dev_1234",
|
||||
"company": "com_123",
|
||||
#"did": self.did,
|
||||
"name": "sn_1234",
|
||||
"resource": "res_1234",
|
||||
}
|
||||
bumper.bot_full_upsert(newbot)
|
||||
|
||||
resp = await client.get("/v1/private/us/en/dev_1234/ios/1/0/0/user/login")
|
||||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
jsonresp = json.loads(text)
|
||||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
assert "accessToken" in jsonresp["data"]
|
||||
assert "uid" in jsonresp["data"]
|
||||
assert "username" in jsonresp["data"]
|
||||
|
||||
|
||||
async def test_logout(aiohttp_client):
|
||||
remove_existing_db()
|
||||
|
|
@ -527,6 +546,11 @@ async def test_getProductIotMap(aiohttp_client):
|
|||
assert jsonresp["code"] == bumper.RETURN_API_SUCCESS
|
||||
|
||||
|
||||
# Test getPimFile
|
||||
resp = await client.get("/api/pim/file/get/123")
|
||||
assert resp.status == 200
|
||||
|
||||
|
||||
async def test_getUsersAPI(aiohttp_client):
|
||||
remove_existing_db()
|
||||
bumper.db = "tests/tmp.db" # Set db location for testing
|
||||
|
|
@ -936,3 +960,5 @@ async def test_dim_devmanager(aiohttp_client):
|
|||
test_resp = json.loads(text)
|
||||
assert test_resp["ret"] == "fail"
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -379,6 +379,26 @@ 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},
|
||||
}
|
||||
|
||||
await mqtt_server.broker_coro()
|
||||
|
||||
# Test helperbot connect
|
||||
|
|
@ -420,6 +440,170 @@ async def test_mqttserver():
|
|||
) # Check fake_bot is connected
|
||||
await fake_bot.Client.disconnect()
|
||||
|
||||
# Test file auth client connect
|
||||
test_client = bumper.MQTTHelperBot(mqtt_address)
|
||||
test_client.client_id = "test-file-auth"
|
||||
# await test_client.start_helper_bot()
|
||||
test_client.Client = hbmqtt.client.MQTTClient(
|
||||
client_id=test_client.client_id, config={"check_hostname": False, "auto_reconnect": False, "reconnect_retries": 1}
|
||||
)
|
||||
|
||||
# good user/pass
|
||||
await test_client.Client.connect(
|
||||
f"mqtts://test-client:abc123!@{test_client.address[0]}:{test_client.address[1]}/",
|
||||
cafile=bumper.ca_cert, cleansession=True
|
||||
)
|
||||
|
||||
assert (
|
||||
test_client.Client._connected_state._value == True
|
||||
) # Check client is connected
|
||||
await test_client.Client.disconnect()
|
||||
assert (
|
||||
test_client.Client._connected_state._value == False
|
||||
) # 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
|
||||
)
|
||||
|
||||
assert (
|
||||
test_client.Client._connected_state._value == False
|
||||
) # Check client is connected
|
||||
|
||||
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},
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
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:
|
||||
|
||||
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},
|
||||
}
|
||||
|
||||
await mqtt_server.broker_coro()
|
||||
|
||||
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()
|
||||
|
||||
except:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue