forked from Narcissus/pylibmeshctrl
Compare commits
2 Commits
fix/raw-ev
...
fix/bad-au
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe4c2fe874 | ||
|
|
bb7cf17cd3 |
@@ -2,7 +2,9 @@ class MeshCtrlError(Exception):
|
|||||||
"""
|
"""
|
||||||
Base class for Meshctrl errors
|
Base class for Meshctrl errors
|
||||||
"""
|
"""
|
||||||
pass
|
def __init__(self, message, *args, **kwargs):
|
||||||
|
self.message = message
|
||||||
|
super().__init__(message, *args, **kwargs)
|
||||||
|
|
||||||
class ServerError(MeshCtrlError):
|
class ServerError(MeshCtrlError):
|
||||||
"""
|
"""
|
||||||
@@ -25,6 +27,7 @@ class FileTransferError(MeshCtrlError):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, message, stats):
|
def __init__(self, message, stats):
|
||||||
self.stats = stats
|
self.stats = stats
|
||||||
|
super().__init__(message)
|
||||||
|
|
||||||
class FileTransferCancelled(FileTransferError):
|
class FileTransferCancelled(FileTransferError):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -533,7 +533,7 @@ class Session(object):
|
|||||||
data = await event_queue.get()
|
data = await event_queue.get()
|
||||||
yield data
|
yield data
|
||||||
finally:
|
finally:
|
||||||
self._eventer.off("raw", _)
|
self._eventer.off("server_event", _)
|
||||||
|
|
||||||
async def events(self, filter=None):
|
async def events(self, filter=None):
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -140,17 +140,20 @@ def compare_dict(dict1, dict2):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def _check_socket(f):
|
def _check_socket(f):
|
||||||
|
async def _check_errs(self):
|
||||||
|
if not self.alive and self._main_loop_error is not None:
|
||||||
|
raise self._main_loop_error
|
||||||
|
elif not self.alive and self.initialized.is_set():
|
||||||
|
raise exceptions.SocketError("Socket Closed")
|
||||||
|
|
||||||
@functools.wraps(f)
|
@functools.wraps(f)
|
||||||
async def wrapper(self, *args, **kwargs):
|
async def wrapper(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
async with asyncio.TaskGroup() as tg:
|
await asyncio.wait_for(self.initialized.wait(), 10)
|
||||||
tg.create_task(asyncio.wait_for(self.initialized.wait(), 10))
|
await _check_errs(self)
|
||||||
tg.create_task(asyncio.wait_for(self._socket_open.wait(), 10))
|
await asyncio.wait_for(self._socket_open.wait(), 10)
|
||||||
finally:
|
finally:
|
||||||
if not self.alive and self._main_loop_error is not None:
|
await _check_errs(self)
|
||||||
raise self._main_loop_error
|
|
||||||
elif not self.alive and self.initialized.is_set():
|
|
||||||
raise exceptions.SocketError("Socket Closed")
|
|
||||||
return await f(self, *args, **kwargs)
|
return await f(self, *args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import meshctrl
|
|||||||
import requests
|
import requests
|
||||||
import random
|
import random
|
||||||
import io
|
import io
|
||||||
|
import traceback
|
||||||
|
import time
|
||||||
thisdir = os.path.dirname(os.path.realpath(__file__))
|
thisdir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
async def test_admin(env):
|
async def test_admin(env):
|
||||||
@@ -77,6 +79,17 @@ async def test_users(env):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise Exception("Connected with no password")
|
raise Exception("Connected with no password")
|
||||||
|
|
||||||
|
start = time.time()
|
||||||
|
try:
|
||||||
|
async with meshctrl.Session(env.mcurl, user="admin", password="The wrong password", ignore_ssl=True) as admin_session:
|
||||||
|
pass
|
||||||
|
except* meshctrl.exceptions.ServerError as eg:
|
||||||
|
assert str(eg.exceptions[0]) == "Invalid Auth" or eg.exceptions[0].message == "Invalid Auth", "Didn't get invalid auth message"
|
||||||
|
assert time.time() - start < 10, "Invalid auth wasn't raised until after timeout"
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise Exception("Connected with bad password")
|
||||||
async with meshctrl.Session(env.mcurl+"/", user="admin", password=env.users["admin"], ignore_ssl=True) as admin_session,\
|
async with meshctrl.Session(env.mcurl+"/", user="admin", password=env.users["admin"], ignore_ssl=True) as admin_session,\
|
||||||
meshctrl.Session(env.mcurl, user="privileged", password=env.users["privileged"], ignore_ssl=True) as privileged_session,\
|
meshctrl.Session(env.mcurl, user="privileged", password=env.users["privileged"], ignore_ssl=True) as privileged_session,\
|
||||||
meshctrl.Session(env.mcurl, user="unprivileged", password=env.users["unprivileged"], ignore_ssl=True) as unprivileged_session:
|
meshctrl.Session(env.mcurl, user="unprivileged", password=env.users["unprivileged"], ignore_ssl=True) as unprivileged_session:
|
||||||
|
|||||||
Reference in New Issue
Block a user