From 8adcfc011024b39a0e5388b6860ea432975b90b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Skaza?= Date: Fri, 3 Nov 2023 15:27:02 +0100 Subject: [PATCH] misc fixes - pass files_directory_name - fix files key not found - fix tests on 3.8 --- ctfcli/cli/challenges.py | 4 ++-- ctfcli/core/challenge.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ctfcli/cli/challenges.py b/ctfcli/cli/challenges.py index 9ec3767..0b389f4 100644 --- a/ctfcli/cli/challenges.py +++ b/ctfcli/cli/challenges.py @@ -862,7 +862,7 @@ def healthcheck(self, challenge: str = None) -> int: click.secho("Success! Challenge passed the healthcheck.", fg="green") return 0 - def mirror(self, challenge: str = None, ignore: Union[str, Tuple[str]] = ()) -> int: + def mirror(self, challenge: str = None, files_directory: str = "dist", ignore: Union[str, Tuple[str]] = ()) -> int: config = Config() challenge_keys = [challenge] @@ -910,7 +910,7 @@ def mirror(self, challenge: str = None, ignore: Union[str, Tuple[str]] = ()) -> for challenge in challenges: try: if not challenge.verify(ignore=ignore): - challenge.mirror(ignore=ignore) + challenge.mirror(files_directory_name=files_directory, ignore=ignore) else: click.secho( f"Challenge '{challenge['name']}' is already in sync. Skipping mirroring.", diff --git a/ctfcli/core/challenge.py b/ctfcli/core/challenge.py index 66e6dbd..d6f8992 100644 --- a/ctfcli/core/challenge.py +++ b/ctfcli/core/challenge.py @@ -2,7 +2,7 @@ import subprocess from os import PathLike from pathlib import Path -from typing import Dict, List, Optional, Tuple, Union, Any +from typing import Any, Dict, List, Optional, Tuple, Union import click import yaml @@ -568,7 +568,7 @@ def lint(self, skip_hadolint=False, flag_format="flag{") -> bool: # Note: files won't be included for two reasons: # 1. To avoid downloading them unnecessarily, e.g., when they are ignored # 2. Because it's dependent on the implementation whether to save them (mirror) or just compare (verify) - def _normalize_challenge(self, challenge_data: dict[str, Any]): + def _normalize_challenge(self, challenge_data: Dict[str, Any]): challenge = {} copy_keys = ["name", "category", "value", "type", "state", "connection_info"] @@ -699,7 +699,7 @@ def verify(self, ignore: Tuple[str] = ()) -> bool: # Handle a special case for files, unless they are ignored if "files" not in ignore: - local_files = {Path(f).name: f for f in challenge["files"]} + local_files = {Path(f).name: f for f in challenge.get("files", [])} remote_files = {f.split("/")[-1].split("?token=")[0]: f for f in remote_challenge["files"]} # Check if there are no extra local files