forked from Narcissus/pylibmeshctrl
Compare commits
1 Commits
fix/bad-au
...
fix/raw-ev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
564d466ff9 |
@@ -2,9 +2,7 @@ class MeshCtrlError(Exception):
|
|||||||
"""
|
"""
|
||||||
Base class for Meshctrl errors
|
Base class for Meshctrl errors
|
||||||
"""
|
"""
|
||||||
def __init__(self, message, *args, **kwargs):
|
pass
|
||||||
self.message = message
|
|
||||||
super().__init__(message, *args, **kwargs)
|
|
||||||
|
|
||||||
class ServerError(MeshCtrlError):
|
class ServerError(MeshCtrlError):
|
||||||
"""
|
"""
|
||||||
@@ -27,7 +25,6 @@ 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("server_event", _)
|
self._eventer.off("raw", _)
|
||||||
|
|
||||||
async def events(self, filter=None):
|
async def events(self, filter=None):
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -140,20 +140,17 @@ 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:
|
||||||
await asyncio.wait_for(self.initialized.wait(), 10)
|
async with asyncio.TaskGroup() as tg:
|
||||||
await _check_errs(self)
|
tg.create_task(asyncio.wait_for(self.initialized.wait(), 10))
|
||||||
await asyncio.wait_for(self._socket_open.wait(), 10)
|
tg.create_task(asyncio.wait_for(self._socket_open.wait(), 10))
|
||||||
finally:
|
finally:
|
||||||
await _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")
|
||||||
return await f(self, *args, **kwargs)
|
return await f(self, *args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ 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):
|
||||||
@@ -79,17 +77,6 @@ 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