Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforces secure chat improvements #678

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions mcstatus/status_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ class JavaStatusResponse(BaseStatusResponse):
"""
players: JavaStatusPlayers
version: JavaStatusVersion
enforces_secure_chat: bool
enforces_secure_chat: bool | None
"""Whether the server enforces secure chat (every message is signed up with a key).

.. seealso::
`Signed Chat explanation <https://gist.github.com/kennytv/ed783dd244ca0321bbd882c347892874>`_,
`22w17a changelog, where this was added <https://www.minecraft.net/nl-nl/article/minecraft-snapshot-22w17a>`_.

.. versionadded:: 11.1.0
"""
icon: str | None
"""The icon of the server. In `Base64 <https://en.wikipedia.org/wiki/Base64>`_ encoded PNG image format.

Expand All @@ -133,7 +141,7 @@ def build(cls, raw: RawJavaResponse, latency: float = 0) -> Self:
players=JavaStatusPlayers.build(raw["players"]),
version=JavaStatusVersion.build(raw["version"]),
motd=Motd.parse(raw["description"], bedrock=False),
enforces_secure_chat=raw.get("enforcesSecureChat", False),
enforces_secure_chat=raw.get("enforcesSecureChat"),
icon=raw.get("favicon"),
latency=latency,
)
Expand Down
11 changes: 4 additions & 7 deletions tests/status_response/test_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class TestJavaStatusResponse(BaseStatusResponseTest):
"players": {"max": 20, "online": 0},
"version": {"name": "1.8-pre1", "protocol": 44},
"description": "A Minecraft Server",
"enforcesSecureChat": True,
"favicon": "data:image/png;base64,foo",
}

Expand All @@ -19,26 +20,22 @@ class TestJavaStatusResponse(BaseStatusResponseTest):
("version", JavaStatusVersion("1.8-pre1", 44)),
("motd", Motd.parse("A Minecraft Server", bedrock=False)),
("latency", 0),
("enforces_secure_chat", True),
("icon", "data:image/png;base64,foo"),
("raw", RAW),
]
OPTIONAL_FIELDS = [("favicon", "icon")], {
OPTIONAL_FIELDS = [("favicon", "icon"), ("enforcesSecureChat", "enforces_secure_chat")], {
"players": {"max": 20, "online": 0},
"version": {"name": "1.8-pre1", "protocol": 44},
"description": "A Minecraft Server",
"enforcesSecureChat": True,
"favicon": "data:image/png;base64,foo",
}

@pytest.fixture(scope="class")
def build(self):
return JavaStatusResponse.build(self.RAW) # type: ignore # dict[str, Unknown] cannot be assigned to TypedDict

@pytest.mark.parametrize("value", (True, False, object()))
def test_enforces_secure_chat(self, value):
raw = self.RAW.copy()
raw["enforcesSecureChat"] = value
assert JavaStatusResponse.build(raw, 0).enforces_secure_chat is value # type: ignore # dict[str, Unknown] cannot be assigned to TypedDict


@BaseStatusResponseTest.construct
class TestJavaStatusPlayers(BaseStatusResponseTest):
Expand Down
Loading