From 021e0031a80c9175d5f5f311d6b290b9c2b7a80f Mon Sep 17 00:00:00 2001 From: Nick Bottone Date: Wed, 11 Nov 2026 01:12:39 -0500 Subject: [PATCH 1/2] fix: enforce the minimum high-score client version --- highscores/lib.py | 24 ++++++++++++++++++++++-- highscores/tests.py | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/highscores/lib.py b/highscores/lib.py index 3c2b889..ebe0a38 100644 --- a/highscores/lib.py +++ b/highscores/lib.py @@ -2,6 +2,7 @@ from django.core.mail import send_mail from django.utils import timezone import logging +import re from .models import Score, CleanCodeSubmission, ExemptedIP from .forms import ScoreForm @@ -15,6 +16,8 @@ USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36' +MINIMUM_CLIENT_VERSION = '21.3e' + WRONG_ROBOT_MESSAGE = 'Double-check the robot type that you selected!' HIGHER_SCORE_MESSAGE = 'You already have a submission with an equal or higher score than this!' ERROR_WRONG_GAME_MESSAGE = 'There is something wrong with your clean code! Are you submitting for the right game?' @@ -597,13 +600,30 @@ def clean_code_decryption(score_obj: Score) -> None: score_obj.decrypted_code = cipher.decrypt(data).decode("utf-8") +def _client_version_key(version: str) -> tuple[int, int, str]: + match = re.fullmatch(r"v?([0-9]+)\.([0-9]+)([a-z])", version) + if match is None: + raise ValueError("Invalid client version") + major, minor, revision = match.groups() + return int(major), int(minor), revision + + def check_generic_game_settings(score_obj: Score, auto_or_teleop: str) -> Union[str, None]: """ Checks if the universal game settings are valid. :return: None if the settings are valid, or a response with an error message if they are not. """ - if (not score_obj.client_version or float(score_obj.client_version[1:5]) < 20.0): + if not score_obj.client_version: + return WRONG_VERSION_MESSAGE + + version, prerelease_marker, _ = score_obj.client_version.partition("_p") + try: + version_key = _client_version_key(version) + except ValueError: + return ERROR_CORRUPT_CODE_MESSAGE + + if version_key < _client_version_key(MINIMUM_CLIENT_VERSION): return WRONG_VERSION_MESSAGE - if "_p" in score_obj.client_version: + if prerelease_marker: return PRERELEASE_MESSAGE if score_obj.leaderboard.auto_or_teleop != auto_or_teleop: return WRONG_AUTO_OR_TELEOP_MESSAGE diff --git a/highscores/tests.py b/highscores/tests.py index 7ce503c..855eb8a 100644 --- a/highscores/tests.py +++ b/highscores/tests.py @@ -1,3 +1,35 @@ -from django.test import TestCase +import pytest -# Create your tests here. +from . import lib +from .models import Leaderboard, Score + + +@pytest.mark.parametrize( + ("version", "expected"), + [ + (None, lib.WRONG_VERSION_MESSAGE), + ("v21.2z", lib.WRONG_VERSION_MESSAGE), + ("v21.3d", lib.WRONG_VERSION_MESSAGE), + ("v21.3e", None), + ("21.3e", None), + ("v21.3f", None), + ("v21.10a", None), + ("v22.0a", None), + ("v21.3e_p1", lib.PRERELEASE_MESSAGE), + ("invalid", lib.ERROR_CORRUPT_CODE_MESSAGE), + ], +) +def test_high_score_client_version(version, expected): + score = Score(client_version=version, leaderboard=Leaderboard(auto_or_teleop="TELE")) + + assert lib.check_generic_game_settings(score, "TELE") == expected + + +def test_changing_minimum_client_version(monkeypatch): + monkeypatch.setattr(lib, "MINIMUM_CLIENT_VERSION", "21.10b") + score = Score(client_version="v21.10a", leaderboard=Leaderboard(auto_or_teleop="TELE")) + + assert lib.check_generic_game_settings(score, "TELE") == lib.WRONG_VERSION_MESSAGE + + score.client_version = "v21.10b" + assert lib.check_generic_game_settings(score, "TELE") is None From db38f9dfc9b2ac22cc20a22b65e8bd5a41341104 Mon Sep 17 00:00:00 2001 From: Nick Bottone Date: Wed, 11 Nov 2026 01:14:07 -0500 Subject: [PATCH 2/2] test: import high-score models by their Django app path --- highscores/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/highscores/tests.py b/highscores/tests.py index 855eb8a..37ef552 100644 --- a/highscores/tests.py +++ b/highscores/tests.py @@ -1,7 +1,7 @@ import pytest -from . import lib -from .models import Leaderboard, Score +from highscores import lib +from highscores.models import Leaderboard, Score @pytest.mark.parametrize(