2024-11-01 12:00:16 -07:00
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
import asyncio
|
|
|
|
|
thisdir = os.path.dirname(os.path.realpath(__file__))
|
2024-11-20 15:23:03 -08:00
|
|
|
# sys.path.append(os.path.realpath(f"{thisdir}/../src"))
|
2024-11-01 12:00:16 -07:00
|
|
|
import meshctrl
|
2024-11-20 15:23:03 -08:00
|
|
|
import ssl
|
|
|
|
|
import requests
|
2024-11-01 12:00:16 -07:00
|
|
|
|
2024-11-20 15:23:03 -08:00
|
|
|
async def test_sanity(env):
|
2024-12-02 13:39:40 -08:00
|
|
|
async with meshctrl.Session(env.mcurl, user="unprivileged", password=env.users["unprivileged"], ignore_ssl=True) as s:
|
2024-12-03 17:46:57 -08:00
|
|
|
got_pong = asyncio.Event()
|
|
|
|
|
async def _():
|
|
|
|
|
async for raw in s.raw_messages():
|
|
|
|
|
if raw == '{action:"pong"}':
|
|
|
|
|
got_pong.set()
|
|
|
|
|
break
|
|
|
|
|
ping_task = None
|
|
|
|
|
async with asyncio.TaskGroup() as tg:
|
|
|
|
|
tg.create_task(asyncio.wait_for(_(), timeout=5))
|
|
|
|
|
tg.create_task(asyncio.wait_for(got_pong.wait(), timeout=5))
|
|
|
|
|
ping_task = tg.create_task(s.ping(timeout=10))
|
|
|
|
|
print("\ninfo ping: {}\n".format(ping_task.result()))
|
2024-11-20 15:23:03 -08:00
|
|
|
print("\ninfo user_info: {}\n".format(await s.user_info()))
|
|
|
|
|
print("\ninfo server_info: {}\n".format(await s.server_info()))
|
|
|
|
|
pass
|
2024-11-01 12:00:16 -07:00
|
|
|
|
2024-11-20 15:23:03 -08:00
|
|
|
async def test_ssl(env):
|
|
|
|
|
try:
|
2024-12-02 13:39:40 -08:00
|
|
|
async with meshctrl.Session(env.mcurl, user="unprivileged", password=env.users["unprivileged"], ignore_ssl=False) as s:
|
2024-11-20 15:23:03 -08:00
|
|
|
pass
|
|
|
|
|
except* ssl.SSLCertVerificationError:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
raise Exception("Invalid SSL certificate accepted")
|