Merge pull request #33 from idle-org/features/typehunts

Features/typehunts
This commit is contained in:
Maximilien Rigaut 2022-06-27 14:54:31 +02:00 committed by GitHub
commit 53d751e3bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 105 additions and 148 deletions

View File

@ -3,13 +3,13 @@
A python script to detect whether your discord was tempered with in any noticeable way.
## Functionnement
DiscordHelper will provide a fast analysis over known malwares and progress it's analysis toward a complete sha1 checksum comparison against a known good install.
DiscordHelper will provide a fast analysis over known malwares and progress its analysis toward a complete sha1 checksum comparison against a known good installation.
If the integrity can't be verified, the helper will propose to upload a new database with all computed data as a new staple to compare to (this functionnality is mostly useful if you have a custom/modded Discord).
### Windows
DiscordHelper is configured to run every tests and save the result in a folder named "DiscordHelper" in the same directory as the script.
This file, named test_results_found.json, contains a snapshot of your current install. If you change it's name to test_results.json, DiscordHelper will use this snapshot instead of the bundled databases. (This feature is mostly useful if you have a custom/modded Discord).
DiscordHelper is configured to run every test and save the result in a folder named "DiscordHelper" in the same directory as the script.
This file, named test_results_found.json, contains a snapshot of your current installation. If you change its name to test_results.json, DiscordHelper will use this snapshot instead of the bundled databases. (This feature is mostly useful if you have a custom/modded Discord).
### What to do if the integrity can't be verified?
Open a new issue, upload the test_results_found.json file and any details surrounding the problem.
@ -17,7 +17,7 @@ Open a new issue, upload the test_results_found.json file and any details surrou
If this isn't a bug in DiscordHelper, you may want to reinstall Discord, and possibly your whole operating system.
# WARNING
Due to the evolutive nature of viruses, only a new, clean install of DiscordHelper will warranty a total detection of all threats, since a virus will always try to temper all methods of detecting it.
Due to the evolutive nature of viruses, only a new, clean installation of DiscordHelper will warranty a total detection of all threats, since a virus will always try to temper all methods of detecting it.
# DISCLAMER
While this program aims to provide a complete coverage over Discord Threats, there are many ways to temper with discord that cannot be covered in this program, mainly side-dll tempering and all forms of RAT and keyloggers. DiscordHelper cannot and will not try to analyse the rest of your operating system, we leave this intrusive behaviour to other anti-viruses.

View File

@ -1,16 +1,16 @@
#!/usr/bin/python3
""" Main program """
import argparse
from modules import main_runner, agnostic_paths, argument_parser
import sys
def main(argm):
def main(argm: argparse.Namespace):
"""
Main program
:param argm: List of arguments
:type argm: argparse.Namespace
"""
agnostic_path = agnostic_paths.AgnosticPaths(argm)
main_runner.run_check(argm, agnostic_path)

View File

@ -5,6 +5,9 @@ import os
import re
import sys
import random
import argparse
from typing import List
class AgnosticPaths:
@ -12,10 +15,9 @@ class AgnosticPaths:
An agnostic path object, containing all methods to access the files and folders in a standard discord install
"""
def __init__(self, args):
def __init__(self, args: argparse.Namespace):
"""
:param args: The arguments passed to the script
:type args: argparse.Namespace
"""
self.args = args
self.ptb = args.ptb
@ -32,13 +34,12 @@ class AgnosticPaths:
random.shuffle(self.all_files)
self.size = len(self.all_files)
def get_os(self):
def get_os(self) -> str:
"""
Get the os string in a short, spydey-detector way.
For now only windows and linux are supported, note that due to the nature of linux builds, strings will likely become
linux-arch-deb, linux-arch-snap etc...
:return: ("windows", "linux", "mac")
:rtype: str
"""
platform = sys.platform
if platform.startswith('win'):
@ -54,12 +55,11 @@ class AgnosticPaths:
raise OSError("This script can only check for Spideys on Windows, Linux and Mac.")
return self.os
def _get_path(self):
def _get_path(self) -> str:
"""
Return the base path of the install, note that the self.main_path is not returned,
Return the base path of the installation, note that the self.main_path is not returned,
and this method is meant to be used at init only
:return: Base path of the install (minus the version on Windows)
:rtype: str
:return: Base path of the installation (minus the version on Windows)
"""
if self.force_path is not None:
return self.force_path
@ -88,12 +88,11 @@ class AgnosticPaths:
return ""
raise OSError("Cannot detect discord PATH")
def get_version(self):
def get_version(self) -> str:
"""
Looks for the version file in the discord folder
and return the latest version of the discord build
:return: The version build
:rtype: str
"""
versions = []
if self.os == 'windows':
@ -112,14 +111,14 @@ class AgnosticPaths:
else:
raise OSError("Can't find for version on your OS.")
def _update_path(self):
def _update_path(self) -> None:
"""
Update the main path with the version, if needed (windows & mac only)
"""
if self.os == 'windows':
self.main_path = os.path.join(self.main_path, self.version)
def list(self, *args):
def list(self, *args: str) -> List[float]:
"""
Lists all files in the path /discord_path/args[0]/args[1].../args[n]
:param args: The path as a list of parameters list("folder1", "folder2", ..., "foldern")
@ -129,7 +128,7 @@ class AgnosticPaths:
"""
return os.listdir(self(*args))
def list_dir_files(self, *args):
def list_dir_files(self, *args: str) -> List[str]:
"""
Lists all files and directories in the given path.
:param args: The path
@ -145,58 +144,51 @@ class AgnosticPaths:
files.append(element)
return dirs, files
def __call__(self, *args):
def __call__(self, *args: str) -> str:
"""
Tries to open the path /discord_path/args[0]/args[1].../args[n]
:param args: The path of the file or directory as a list of parameters __call__("folder1", "folder2", ..., "foldern")
:type args: str
:return: The path is it exists
:rtype: str
:raises: FileNotFoundError if the path doesn't exists
:raises: FileNotFoundError if the path doesn't exist
"""
_path = os.path.join(self.main_path, *args)
if not os.path.exists(_path):
raise FileNotFoundError(f"Could not find {_path}")
return _path
def get_path(self):
def get_path(self) -> str:
"""
The main path of the discord install
:return: self.main_path
:rtype: str
"""
return self.main_path
def walk_all_files(self, *args):
def walk_all_files(self, *args: str) -> List[str]:
"""
Walks all files in the given path
:param args: The path
:return: A list of all files in the given path
:rtype: list[str]
"""
return [os.path.join(dirpath, filename)
for dirpath, dirnames, filenames in os.walk(self(*args))
for filename in filenames]
def get_short_path(self, path):
def get_short_path(self, path: str) -> str:
"""
Get the short path of the given path
:param path: The path
:return: The short path
:rtype: str
"""
return os.path.relpath(path, self.main_path)
def __repr__(self):
def __repr__(self) -> str:
"""
:return: A representation of the AgnosticPath
:rtype: str
"""
return f"AgnosticPaths(ptb={self.ptb}, os={self.os}, main_path={self.main_path}, version={self.version})"
def __str__(self):
def __str__(self) -> str:
"""
:return: The main path of the discord install
:rtype: str
"""
return self.main_path

View File

@ -1,7 +1,7 @@
import argparse
def parse(_args):
def parse(_args: list) -> argparse.Namespace:
parser = argparse.ArgumentParser(
prog="Spidey Detector",
description='Checks for corrupt discord install'

View File

@ -1,3 +1,4 @@
import argparse
import json
import os
import subprocess
@ -6,8 +7,10 @@ import importlib
import threading
import time
from collections import deque
from typing import List
from modules.internal_io import global_status, thread_parameters
from modules import agnostic_paths, internal_io
"""
All modules that can be tested
@ -70,15 +73,12 @@ LOGO = colored(r"""
class TestRunner:
def __init__(self, args, agnpath, start_time):
def __init__(self, args: argparse.Namespace, agnpath: agnostic_paths.AgnosticPaths, start_time: float):
"""
Main spidey runner
:param args: List of arguments
:type args: argparse.Namespace
:param agnpath: The path to the discord folder
:type agnpath: agnostic_path.AgnosticPath
:param start_time: The time the test started
:type start_time: float
"""
self.ptb = args.ptb
self.args = args
@ -108,17 +108,17 @@ class TestRunner:
self.open_base_data()
self.exec_all_tests()
def update_threat(self, threat_level):
def update_threat(self, threat_level: int):
"""
Updates the threat level
:param threat_level: The new threat level
:type threat_level: int
"""
self.threat_level = max(threat_level, self.threat_level)
def open_base_data(self):
def open_base_data(self) -> dict:
"""
Opens the base data file
:return: The base data (a json file)
"""
default_database = resource_path(self.agnostic_path.default_database)
@ -150,9 +150,10 @@ class TestRunner:
self.base_data = {}
return self.base_data
def check_database(self): # TODO: All of this can be refactored with a function
def check_database(self) -> bool: # TODO: All of this can be refactored with a function
"""
Check if the database is valid set self.bad_database to True if it is not
:return: True if the database is valid
"""
if not self.base_data:
print(colored(" > The database is empty", "red"))
@ -206,11 +207,10 @@ class TestRunner:
print(colored(f" > The database is missing the test {test_name}", "red"))
self.bad_database = True
def update_module_list(self):
def update_module_list(self) -> List[str]:
"""
Gets the list of modules to be loaded (in accordance to the config)
:return: List of modules
:rtype: list
"""
modules = {}
classes = {}
@ -229,7 +229,7 @@ class TestRunner:
self.loaded_test_modules.update(modules)
self.loaded_test_classes.update(classes)
def exec_all_tests(self):
def exec_all_tests(self) -> None:
"""
Executes all the tests, get their result as they finishes
"""
@ -268,7 +268,7 @@ class TestRunner:
tc.daemon = True
tc.start()
def controller_test(self):
def controller_test(self) -> None:
"""
Kills the tests if the user press enter
"""
@ -289,7 +289,7 @@ class TestRunner:
except Exception:
sys.exit()
def post_test_runner(self):
def post_test_runner(self) -> None:
"""
Runs the post test runner if all tests are finished
"""
@ -306,10 +306,9 @@ class TestRunner:
time.sleep(0.1)
return 0
def test_waiter(self):
def test_waiter(self) -> None:
"""
Waits for the end of the tests
:return:
"""
for t in self.list_of_tests: # Can only proceed if all tests are finished
t.join()
@ -320,11 +319,10 @@ class TestRunner:
global POST_RUN_ALLOWED
POST_RUN_ALLOWED = True
def get_exit_code(self):
def get_exit_code(self) -> int: # TODO: Use a NamedTuple
"""
Gets the exit code of the tests
:return: The exit code
:rtype: int
"""
status = self.get_status()
if status.tests_finished == status.tests_total:
@ -345,11 +343,10 @@ class TestRunner:
exit_code = -1 # The tests are not finished
return exit_code
def get_status(self):
def get_status(self) -> internal_io.global_status:
"""
Gets the status of the tests
:return: The status
:rtype: internal_io.global_status
"""
queue_lock.acquire(timeout=0.5)
nb_tests = len(self.list_of_tests)
@ -391,11 +388,10 @@ class TestRunner:
progress=progress
)
def get_test_data(self):
def get_test_data(self) -> dict:
"""
Gets the test data
:return: The test data
:rtype: dict
"""
data = {}
queue_lock.acquire()
@ -409,13 +405,11 @@ class TestRunner:
return data
def export_data(test_runner, data):
def export_data(test_runner: TestRunner, data: dict) -> dict:
"""
Exports the test data
Exports the test data and returns it
:param test_runner: The test runner
:type test_runner: TestRunner
:param data: The test data
:type data: dict
"""
main_data = {
"global":
@ -430,13 +424,11 @@ def export_data(test_runner, data):
return main_data
def print_status(status, timer_start):
def print_status(status: internal_io.global_status, timer_start: float) -> None:
"""
Prints the status
:param status: The status
:type status: internal_io.global_status
:param timer_start: The start time of the tests
:type timer_start: float
"""
if status.tests_failed != 0:
color = "red"
@ -461,7 +453,7 @@ def print_status(status, timer_start):
else:
mon, sec = divmod(ellapsed_time * 100 / status.progress, 60)
hr, mon = divmod(mon, 60)
sec = round(sec, 0) +1
sec = round(sec, 0) + 1
estimated_time = f"{hr:n}:{mon:02n}:{sec:02.0n}"
print(colored(
f" > Overall progress: {status.progress}%"
@ -470,12 +462,11 @@ def print_status(status, timer_start):
))
def run_check(args, agnpath):
def run_check(args: argparse.Namespace, agnpath: agnostic_paths.AgnosticPaths) -> None:
"""
Runs all operations selected in the config
:param args: List of arguments
:param agnpath: Annostic path to the discord folder
:return: None
"""
# Initialize the test runner
print(LOGO)
@ -509,7 +500,7 @@ def run_check(args, agnpath):
sys.exit(tr.get_exit_code())
def resource_path(relative_path):
def resource_path(relative_path: str) -> str:
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
@ -519,7 +510,7 @@ def resource_path(relative_path):
return os.path.join(base_path, relative_path)
def print_final_status(testrunner, start_time, args):
def print_final_status(testrunner: TestRunner, start_time: float, args: argparse.Namespace) -> None:
"""
Prints the final status
"""
@ -558,14 +549,15 @@ def print_final_status(testrunner, start_time, args):
print(colored(f"\nThe program executed {msg_error}, exiting in {args.timeout} seconds...", color))
def fill_it(size, string1, string2):
def fill_it(size: int, string1: str, string2: str) -> str:
"""
Fills a string with a character
Makes a string with the format "string1......string2"
with as many "." as needed to fill the size
"""
return string1 + max(size - len(string1)-len(string2), 0) * "." + string2
def at_max_elements(table, msize, fill):
def at_max_elements(table: list, msize: int, fill: str) -> list:
"""
Display at maximum msize elements, replace last with fill and return the table
"""
@ -578,9 +570,9 @@ def at_max_elements(table, msize, fill):
return table
def fit_it_under(message, size, start_line=""):
def fit_it_under(message: str, size: int, start_line: str = "") -> list:
"""
Fits a message under a size
Fits a message under a size (split lines into multiple lines if needed) and returns the list of lines
"""
final_message = []
for line in message.split('\n'):
@ -592,9 +584,9 @@ def fit_it_under(message, size, start_line=""):
return final_message
def gen_save_data(args, test_runner):
def gen_save_data(args: argparse.Namespace, test_runner: TestRunner) -> None:
"""
Generates the save data
Generates the save data and writes it to a file
"""
print(colored("\n > Generating data...", "blue"))
data = test_runner.get_test_data()

View File

@ -2,24 +2,22 @@
Fast adler32 checksum implementation.
"""
from modules import test_template
from modules import test_template, internal_io
from zlib import adler32
def apply_adler(path):
def apply_adler(path: str) -> hex:
"""
Apply the adler32 checksum to a file.
:param path: The path to the file.
:type path: str
:return: The adler32 checksum.
:rtype: int
"""
with open(path, "rb") as f:
return hex(adler32(f.read()))
class Adler32(test_template.TestWalkTemplateSimpleFunction):
def __init__(self, thread_parameters):
def __init__(self, thread_parameters: internal_io.thread_parameters):
"""
Simple test runner, compare adler32 to known good values.
"""

View File

@ -2,11 +2,11 @@
Test against the line count of the files in the discord folder.
"""
from modules import test_template
from modules import test_template, internal_io
class LineCount(test_template.TestWalkTemplateSimpleFunction):
def __init__(self, thread_parameters):
def __init__(self, thread_parameters: internal_io.thread_parameters):
"""
Simple test runner, compare line count to known good values.
"""

View File

@ -3,10 +3,10 @@ Sha256 hash function.
"""
from hashlib import sha256
from modules import test_template
from modules import test_template, internal_io
def sha256_hash(path):
def sha256_hash(path: str) -> hex:
"""
Returns the sha256 hash of the data.
"""
@ -18,7 +18,7 @@ class Sha256(test_template.TestWalkTemplateSimpleFunction):
"""
Sha256 hash function.
"""
def __init__(self, thread_parameters):
def __init__(self, thread_parameters: internal_io.thread_parameters):
"""
Sha256 hash function.
"""

View File

@ -1,10 +1,10 @@
import os
from modules import test_template
from modules import test_template, internal_io
class SizeCheck(test_template.TestWalkTemplateSimpleFunction):
def __init__(self, thread_parameters):
def __init__(self, thread_parameters: internal_io.thread_parameters):
"""
Simple test runner, compare file size to known good values.
"""

View File

@ -1,21 +1,20 @@
import os
from modules import test_template
from modules import test_template, internal_io
class SpideyTest(test_template.TestTemplate):
def __init__(self, thread_parameters):
def __init__(self, thread_parameters: internal_io.thread_parameters):
"""
Simple test runner, for testing the detection of Spidey viruses.
"""
super().__init__(thread_parameters)
def run_test(self):
def run_test(self) -> str:
"""
Counts the number of lines in both index.js files. If it's more than one, it's almost certain your discord
is corrupted.
:return: Whether any of the index.js is more than one line
:rtype: bool
:return: The status of the test as a string.
"""
self.set_status("running")
@ -52,11 +51,10 @@ class SpideyTest(test_template.TestTemplate):
self.progress = 100
return self.finish("success", "Your discord is not infected.")
def get_path(self):
def get_path(self) -> str:
"""
Gets the path of the two folders we need to check
:return: Two paths.
:rtype: str
"""
discord_modules = self.agnostic_path("modules", "discord_modules-1", "discord_modules")
discord_desktop_core = self.agnostic_path("modules", "discord_desktop_core-1", "discord_desktop_core")

View File

@ -2,8 +2,9 @@
A global template for all tests.
"""
import os
from typing import Callable, Union
from modules import internal_io
from modules import internal_io, agnostic_paths
class TestDataError(Exception):
@ -58,7 +59,7 @@ class TestTemplate:
self.dict_process_lock.release()
self.init_test_data()
def run(self):
def run(self) -> None:
"""
Runs the test.
"""
@ -68,7 +69,7 @@ class TestTemplate:
self.add_failure("problem", "DISCORD HELPER:"+str(e))
return self.finish("problem", str(e))
def run_test(self):
def run_test(self) -> None:
"""
The main runner function, must be implemented by the child class.
During the execution of the test, the status code and status MUST be updated.
@ -76,29 +77,26 @@ class TestTemplate:
self.set_status("running", "The test will begin shortly, please wait...")
self.set_status("sucess", "The test was a success but kinda not a success.")
def init_test_data(self):
def init_test_data(self) -> Union[str, None]:
if self.test_data is None and not self.args.continue_on_error:
self.set_status("problem", "No test data given.")
return self.finish()
def name(self):
def name(self) -> str:
"""
:return: Name of the test
:rtype: str
"""
return str(self.__class__.__name__)
def get_status_code(self):
def get_status_code(self) -> str:
"""
:return: Status code at the time of call.
:rtype: str
"""
return self.status_code
def get_status(self):
def get_status(self) -> internal_io.test_status:
"""
:return: Status at the time of call.
:rtype: internal_io.test_status
"""
return internal_io.test_status(
name=self.name(),
@ -110,23 +108,19 @@ class TestTemplate:
)
@staticmethod
def get_status_from_code(code):
def get_status_from_code(code: str) -> str:
"""
:param code: The status code to get the status from.
:type code: str
:return: Description of the status code
:rtype: str
"""
return internal_io.return_code_dict[code]
def set_status(self, statuscode: str, message: str = None):
def set_status(self, statuscode: str, message: str = None) -> str:
"""
Sets a new status code.
:param statuscode: Status code to set
:param message: Message to set
:type statuscode: str
:return: new status code
:rtype: str
"""
self.status_code = statuscode
if message is not None:
@ -135,9 +129,12 @@ class TestTemplate:
self.status = self.get_status_from_code(statuscode)
return self.status_code
def finish(self, statuscode: str = None, message: str = None):
def finish(self, statuscode: str = None, message: str = None) -> str:
"""
Finishes the test.
:param statuscode: Status code to set
:param message: Message to set
:type statuscode: str
"""
if message is not None:
self.status = message
@ -150,65 +147,54 @@ class TestTemplate:
self.queue_lock.release()
return self.get_status_code()
def add_failure(self, path, message):
def add_failure(self, path: str, message: str) -> None:
"""
Adds a failure to the failure dictionary.
:param path: Path to the file that failed
:type path: str
:param message: Message to add
:type message: str
"""
self.failure_dict[path] = message
def __del__(self):
def __del__(self) -> None:
"""
Destructor.
"""
if self.status_code == "running":
return self.finish("skipped")
def add_to_new_data(self, entry, testname, value):
def add_to_new_data(self, entry: str, testname: str, value: str) -> any:
"""
Adds a new entry to the database.
:param entry: The entry to add
:type entry: str
:param testname: The name of the test
:type testname: str
:param value: The value of the entry
:type value: str
:return: The value of the entry
"""
if entry not in self.new_data:
self.new_data[entry] = {}
self.new_data[entry][testname] = value
return value
def get_from_new_data(self, entry, testname):
def get_from_new_data(self, entry: str, testname: str) -> any:
"""
Gets the value of an entry from the database.
:param entry: The entry to get
:type entry: str
:param testname: The name of the test
:type testname: str
:return: The value of the entry
:rtype: str
"""
if entry in self.new_data:
if testname in self.new_data[entry]:
return self.new_data[entry][testname]
return None
def get_from_database(self, entry, testname):
def get_from_database(self, entry: str, testname: str) -> any:
"""
Gets the value of an entry from the database.
:param entry: The entry to get
:type entry: str
:param testname: The name of the test
:type testname: str
:return: The value of the entry
:rtype: str
"""
if self.test_data:
path = self.agnostic_path.get_short_path(entry)
if "tests" in self.test_data:
if entry in self.test_data["tests"]:
if testname in self.test_data["tests"][entry]:
@ -217,18 +203,17 @@ class TestTemplate:
class TestWalkTemplate(TestTemplate):
def __init__(self, thread_parameters):
def __init__(self, thread_parameters: internal_io.thread_parameters):
"""
Simple test template.
"""
super().__init__(thread_parameters)
self.to_skip = []
def run_test(self):
def run_test(self) -> str:
"""
The main runner function, must be implemented by the child class.
Here is an example of how to use the add_test_result function.
:return:
"""
self.set_status("running", "The test will begin shortly, please wait...")
@ -249,24 +234,25 @@ class TestWalkTemplate(TestTemplate):
return self.finish()
def walk(self):
def walk(self) -> list:
"""
Walks the given path and returns a list of all files and directories.
:return: List of all files
"""
return self.agnostic_path.all_files
def add_test_result(self, path: str, testname: str, result: any):
def add_test_result(self, path: str, testname: str, result: any) -> any:
"""
Adds a test result to the data dictionary.
:param path: Path to the file being tested
:param testname: Name of the test
:param result: Result of the test
:return: The result of the test
"""
path = self.agnostic_path.get_short_path(path)
return self.add_to_new_data(path, testname, result)
def get_test_data(self, path, testname):
def get_test_data(self, path: str, testname: str) -> any:
"""
Gets the test data from the data dictionary.
:param path: Path to the file being tested
@ -274,7 +260,7 @@ class TestWalkTemplate(TestTemplate):
"""
return self.get_from_new_data(self.agnostic_path.get_short_path(path), testname)
def get_expected_result(self, path, testname):
def get_expected_result(self, path: str, testname: str) -> Union[str, None]:
"""
Gets the expected result from the data dictionary.
:param path: Path to the file being tested
@ -284,21 +270,16 @@ class TestWalkTemplate(TestTemplate):
return self.get_from_database(self.agnostic_path.get_short_path(path), testname)
return None
def compare(self, path, entry_name, function, args, kwargs, cmp_function=None):
def compare(self, path: agnostic_paths.AgnosticPaths, entry_name: str, function: Callable,
args: list, kwargs: dict, cmp_function: Callable = None):
"""
Use the function on the given path, with given arguments and compare it with the entry in the test data.
:param path: Path to the file or directory
:type path: agnostic_path.AgnosticPath
:param entry_name: Name of the entry in the test data
:type entry_name: str
:param function: Function to use on the path
:type function: function
:param args: Arguments to use on the function
:type args: list
:param kwargs: Keyword arguments to use on the function
:type kwargs: dict
:param cmp_function: Function compare both results
:type cmp_function: function
"""
if self.agnostic_path.get_short_path(path) in self.to_skip:
@ -322,7 +303,7 @@ class TestWalkTemplate(TestTemplate):
class TestWalkTemplateNoLogs(TestWalkTemplate):
def __init__(self, thread_parameters):
def __init__(self, thread_parameters: internal_io.thread_parameters):
"""
Simple test template.
"""
@ -331,26 +312,22 @@ class TestWalkTemplateNoLogs(TestWalkTemplate):
class TestWalkTemplateSimpleFunction(TestWalkTemplateNoLogs):
def __init__(self, thread_parameters, function, unit_test):
def __init__(self, thread_parameters: internal_io.thread_parameters, function: Callable, unit_test: str):
"""
A test template that runs a simple function on every file, and compares the result with the expected data.
:param thread_parameters: Thread parameters
:type thread_parameters: dict
:param function: Function to use on every file
:type function: function
:param unit_test: A descriptor of what the test returns
:type unit_test: str
"""
super().__init__(thread_parameters)
self.function = function
self.test_name = self.name()
self.unit_test = unit_test
def run_test(self):
def run_test(self) -> bool:
"""
Walk all files and check their size.
:return: Whether any of the files are larger than the expected size.
:rtype: bool
"""
self.set_status("running")
size = self.agnostic_path.size