-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow non-ssl rpc clients (2) (#17510)
* allow non-ssl rpc clients (2) * add missing tests * another test
- Loading branch information
Showing
6 changed files
with
112 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from chia.cmds.cmds_util import get_any_service_client | ||
from chia.rpc.rpc_client import RpcClient | ||
from tests.util.misc import RecordingWebServer | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_get_any_service_client_works_without_ssl( | ||
root_path_populated_with_config: Path, | ||
recording_web_server: RecordingWebServer, | ||
) -> None: | ||
expected_result = {"success": True, "keepy": "uppy"} | ||
|
||
async with get_any_service_client( | ||
client_type=RpcClient, | ||
rpc_port=recording_web_server.web_server.listen_port, | ||
root_path=root_path_populated_with_config, | ||
use_ssl=False, | ||
) as [rpc_client, _]: | ||
result = await rpc_client.fetch(path="", request_json={"response": expected_result}) | ||
|
||
assert result == expected_result |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from pathlib import Path | ||
from typing import Any, Dict, Optional | ||
|
||
import pytest | ||
|
||
from chia.rpc.rpc_client import RpcClient | ||
from chia.util.ints import uint16 | ||
from tests.util.misc import Marks, RecordingWebServer, datacases | ||
|
||
|
||
@dataclass | ||
class InvalidCreateCase: | ||
id: str | ||
root_path: Optional[Path] = None | ||
net_config: Optional[Dict[str, Any]] = None | ||
marks: Marks = () | ||
|
||
|
||
@datacases( | ||
InvalidCreateCase(id="just root path", root_path=Path("/root/path")), | ||
InvalidCreateCase(id="just net config", net_config={}), | ||
) | ||
@pytest.mark.anyio | ||
async def test_rpc_client_create_raises_for_invalid_root_path_net_config_combinations( | ||
case: InvalidCreateCase, | ||
) -> None: | ||
with pytest.raises(ValueError, match="Either both or neither of"): | ||
await RpcClient.create( | ||
self_hostname="", | ||
port=uint16(0), | ||
root_path=case.root_path, | ||
net_config=case.net_config, | ||
) | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_rpc_client_works_without_ssl(recording_web_server: RecordingWebServer) -> None: | ||
expected_result = {"success": True, "daddy": "putdown"} | ||
|
||
async with RpcClient.create_as_context( | ||
self_hostname=recording_web_server.web_server.hostname, | ||
port=recording_web_server.web_server.listen_port, | ||
) as rpc_client: | ||
result = await rpc_client.fetch(path="", request_json={"response": expected_result}) | ||
|
||
assert result == expected_result |