mirror of
https://github.com/HuFlungDu/pylibmeshctrl.git
synced 2026-02-20 13:42:11 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a657cee48 | ||
|
|
03441161b2 | ||
|
|
24adf3baa5 |
@@ -30,7 +30,7 @@ class Session(object):
|
|||||||
domain (str): Domain to connect to
|
domain (str): Domain to connect to
|
||||||
password (str): Password with which to connect. Can also be password generated from token.
|
password (str): Password with which to connect. Can also be password generated from token.
|
||||||
loginkey (str|bytes): Key from already handled login. Overrides username/password.
|
loginkey (str|bytes): Key from already handled login. Overrides username/password.
|
||||||
proxy (str): "url:port" to use for proxy server NOTE: This is currently not implemented due to a limitation of the undersying websocket library. Upvote the issue if you find this important.
|
proxy (str): "url:port" to use for proxy server
|
||||||
token (str): Login token. This appears to be superfluous
|
token (str): Login token. This appears to be superfluous
|
||||||
ignore_ssl (bool): Ignore SSL errors
|
ignore_ssl (bool): Ignore SSL errors
|
||||||
auto_reconnect (bool): In case of server failure, attempt to auto reconnect. All outstanding requests will be killed.
|
auto_reconnect (bool): In case of server failure, attempt to auto reconnect. All outstanding requests will be killed.
|
||||||
@@ -46,9 +46,19 @@ class Session(object):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, url, user=None, domain=None, password=None, loginkey=None, proxy=None, token=None, ignore_ssl=False, auto_reconnect=False):
|
def __init__(self, url, user=None, domain=None, password=None, loginkey=None, proxy=None, token=None, ignore_ssl=False, auto_reconnect=False):
|
||||||
if len(url) < 5 or ((not url.startswith('wss://')) and (not url.startswith('ws://'))):
|
parsed = urllib.parse.urlparse(url)
|
||||||
|
|
||||||
|
if parsed.scheme not in ("wss", "ws"):
|
||||||
raise ValueError("Invalid URL")
|
raise ValueError("Invalid URL")
|
||||||
|
|
||||||
|
port = 80
|
||||||
|
if parsed.port is None:
|
||||||
|
if parsed.scheme == "wss":
|
||||||
|
port = 443
|
||||||
|
p = list(parsed)
|
||||||
|
p[1] = f"{parsed.hostname}:{port}"
|
||||||
|
url = urllib.parse.urlunparse(p)
|
||||||
|
|
||||||
if (not url.endswith('/')):
|
if (not url.endswith('/')):
|
||||||
url += '/'
|
url += '/'
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ def compare_dict(dict1, dict2):
|
|||||||
def _check_socket(f):
|
def _check_socket(f):
|
||||||
@functools.wraps(f)
|
@functools.wraps(f)
|
||||||
async def wrapper(self, *args, **kwargs):
|
async def wrapper(self, *args, **kwargs):
|
||||||
await self.initialized.wait()
|
await asyncio.wait_for(self.initialized.wait(), 10)
|
||||||
if not self.alive and self._main_loop_error is not None:
|
if not self.alive and self._main_loop_error is not None:
|
||||||
raise self._main_loop_error
|
raise self._main_loop_error
|
||||||
elif not self.alive:
|
elif not self.alive:
|
||||||
@@ -153,3 +153,6 @@ def _process_websocket_exception(exc):
|
|||||||
if isinstance(exc, (ssl.SSLCertVerificationError, TimeoutError)):
|
if isinstance(exc, (ssl.SSLCertVerificationError, TimeoutError)):
|
||||||
return exc
|
return exc
|
||||||
return tmp
|
return tmp
|
||||||
|
|
||||||
|
class Proxy(object):
|
||||||
|
pass
|
||||||
@@ -36,4 +36,21 @@ async def test_ssl(env):
|
|||||||
except* ssl.SSLCertVerificationError:
|
except* ssl.SSLCertVerificationError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise Exception("Invalid SSL certificate accepted")
|
raise Exception("Invalid SSL certificate accepted")
|
||||||
|
|
||||||
|
async def test_urlparse():
|
||||||
|
# This tests the url port adding necessitated by python-socks. Our test environment doesn't use 443, so this is just a quick sanity test.
|
||||||
|
try:
|
||||||
|
async with meshctrl.Session("wss://localhost", user="unprivileged", password="Not a real password", ignore_ssl=True) as s:
|
||||||
|
pass
|
||||||
|
except* TimeoutError:
|
||||||
|
#We're not running a server, so timeout is our expected outcome
|
||||||
|
pass
|
||||||
|
|
||||||
|
# This tests our check for wss/ws url schemes
|
||||||
|
try:
|
||||||
|
async with meshctrl.Session("https://localhost", user="unprivileged", password="Not a real password", ignore_ssl=True) as s:
|
||||||
|
pass
|
||||||
|
except* ValueError:
|
||||||
|
#We're not running a server, so timeout is our expected outcome
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user