Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_call_raises_custom_error(self):
client = Client()
responses.add(
responses.POST, client.server, json={"error": {"code": 1, "message": "Custom message"}}, status=200
)
with pytest.raises(ClientException, match=r"Custom message") as e:
client.call("aria2.method")
assert e.code == 1
def test_does_not_insert_secret_with_unknown_method_call(self):
# create client with secret
secret = "hello"
client = Client(secret=secret)
responses.add_callback(responses.POST, client.server, callback=self.call_params_callback)
# create params
params = ["param1", "param2"]
# call function and assert result
resp = client.call("other.method", params, insert_secret=True)
assert secret not in resp
def test_insert_secret_with_system_multicall(self):
# create client with secret
secret = "hello"
client = Client(secret=secret)
responses.add_callback(responses.POST, client.server, callback=self.call_params_callback)
# create params
params = [
[
{"methodName": client.ADD_URI, "params": ["param1", "param2"]},
{"methodName": client.ADD_URI, "params": ["param3", "param4"]},
]
]
# copy params and insert secret
expected_params = deepcopy(params)
for param in expected_params[0]:
param["params"].insert(0, f"token:{secret}")
# call function and assert result
session_path = self.tmp_dir / "_session.txt"
with open(session_path, "w") as stream:
stream.write("\n".join(session))
command.append(f"--input-file={session_path}")
else:
if not session.exists():
raise ValueError(f"no such session: {session}")
command.append(f"--input-file={session}")
if secret:
command.append(f"--rpc-secret={secret}")
self.command = command
self.process = None
# create the client with port
self.client = aria2p.Client(port=self.port, secret=secret)
# create the API instance
self.api = aria2p.API(self.client)
def test_does_not_insert_secret_if_told_so(self):
# create client with secret
secret = "hello"
client = Client(secret=secret)
responses.add_callback(responses.POST, client.server, callback=self.call_params_callback)
# create params
params = ["param1", "param2"]
# call function and assert result
resp = client.call("other.method", params, insert_secret=False)
assert secret not in resp
def test_client_str_returns_client_server(self):
host = "https://example.com/"
port = 7100
client = Client(host, port)
assert client.server == f"{host.rstrip('/')}:{port}/jsonrpc" == str(client)
def test_listen_to_notifications_no_server(self):
client = Client(port=7035)
client.listen_to_notifications(timeout=1)
def test_insert_secret_with_multicall2(self):
# create client with secret
secret = "hello"
client = Client(secret=secret)
responses.add_callback(responses.POST, client.server, callback=self.call_params_callback)
# create params
params_1 = ["2089b05ecca3d829"]
params_2 = ["2fa07b6e85c40205"]
calls = [(client.REMOVE, params_1), (client.REMOVE, params_2)]
# copy params and insert secret
expected_params = [
[
{"methodName": client.REMOVE, "params": deepcopy(params_1)},
{"methodName": client.REMOVE, "params": deepcopy(params_2)},
]
]
for param in expected_params[0]:
param["params"].insert(0, f"token:{secret}")