From d0ae9871d961b48c14931d4844a8890de9c9201e Mon Sep 17 00:00:00 2001 From: s3inlc Date: Tue, 2 Dec 2025 13:37:41 +0100 Subject: [PATCH 1/3] restructure the tests slightly to improve overview --- ci/apiv2/DEBUGGING.md | 40 ++++ ci/apiv2/HACKING.md | 145 ------------- ci/apiv2/PERMISSIONS_REWORK.md | 194 ------------------ ci/apiv2/poc_openapi_perm_test.sh | 8 - ci/apiv2/test_openapi_permissions.sh | 8 + .../create_accessgroup_001.json | 0 .../create_accessgroup_002.json | 0 .../create_agentbinary_001.json | 0 .../{ => testfiles}/create_cracker_001.json | 0 .../{ => testfiles}/create_cracker_002.json | 0 .../create_crackertype_001.json | 0 .../create_crackertype_002.json | 0 ci/apiv2/{ => testfiles}/create_file_001.json | 0 .../{ => testfiles}/create_hashlist_001.json | 0 .../{ => testfiles}/create_hashlist_002.json | 0 .../{ => testfiles}/create_hashlist_003.json | 0 .../{ => testfiles}/create_hashtype_001.json | 0 .../create_healthcheck_001.json | 0 .../create_notification_001.json | 0 .../create_preprocessor_001.json | 0 .../{ => testfiles}/create_pretask_001.json | 0 ci/apiv2/testfiles/create_pretask_002.json | 15 ++ .../{ => testfiles}/create_pretask_003.json | 0 .../{ => testfiles}/create_supertask_001.json | 0 ci/apiv2/{ => testfiles}/create_task_001.json | 0 ci/apiv2/{ => testfiles}/create_task_002.json | 0 ci/apiv2/{ => testfiles}/create_task_003.json | 0 ci/apiv2/utils.py | 2 +- 28 files changed, 64 insertions(+), 348 deletions(-) create mode 100644 ci/apiv2/DEBUGGING.md delete mode 100644 ci/apiv2/HACKING.md delete mode 100644 ci/apiv2/PERMISSIONS_REWORK.md delete mode 100644 ci/apiv2/poc_openapi_perm_test.sh create mode 100644 ci/apiv2/test_openapi_permissions.sh rename ci/apiv2/{ => testfiles}/create_accessgroup_001.json (100%) rename ci/apiv2/{ => testfiles}/create_accessgroup_002.json (100%) rename ci/apiv2/{ => testfiles}/create_agentbinary_001.json (100%) rename ci/apiv2/{ => testfiles}/create_cracker_001.json (100%) rename ci/apiv2/{ => testfiles}/create_cracker_002.json (100%) rename ci/apiv2/{ => testfiles}/create_crackertype_001.json (100%) rename ci/apiv2/{ => testfiles}/create_crackertype_002.json (100%) rename ci/apiv2/{ => testfiles}/create_file_001.json (100%) rename ci/apiv2/{ => testfiles}/create_hashlist_001.json (100%) rename ci/apiv2/{ => testfiles}/create_hashlist_002.json (100%) rename ci/apiv2/{ => testfiles}/create_hashlist_003.json (100%) rename ci/apiv2/{ => testfiles}/create_hashtype_001.json (100%) rename ci/apiv2/{ => testfiles}/create_healthcheck_001.json (100%) rename ci/apiv2/{ => testfiles}/create_notification_001.json (100%) rename ci/apiv2/{ => testfiles}/create_preprocessor_001.json (100%) rename ci/apiv2/{ => testfiles}/create_pretask_001.json (100%) create mode 100644 ci/apiv2/testfiles/create_pretask_002.json rename ci/apiv2/{ => testfiles}/create_pretask_003.json (100%) rename ci/apiv2/{ => testfiles}/create_supertask_001.json (100%) rename ci/apiv2/{ => testfiles}/create_task_001.json (100%) rename ci/apiv2/{ => testfiles}/create_task_002.json (100%) rename ci/apiv2/{ => testfiles}/create_task_003.json (100%) diff --git a/ci/apiv2/DEBUGGING.md b/ci/apiv2/DEBUGGING.md new file mode 100644 index 000000000..2c83a5725 --- /dev/null +++ b/ci/apiv2/DEBUGGING.md @@ -0,0 +1,40 @@ +#### Examples + +Common sequences of commands used in development setups + +Initialize token: +``` +TOKEN=$(curl -X POST --user admin:hashtopolis http://localhost:8080/api/v2/auth/token | jq -r .token) +``` + +Fetch object: +``` +curl --compressed --header "Authorization: Bearer $TOKEN" -g 'http://localhost:8080/api/v2/ui/hashtypes?page[size]=5' +``` + +Access database (MySQL): +``` +mysql -u $HASHTOPOLIS_DB_USER -p$HASHTOPOLIS_DB_PASS -h $HASHTOPOLIS_DB_HOST -D $HASHTOPOLIS_DB_DATABASE +``` + +Access database (PostgreSQL): +``` +psql -U${HASHTOPOLIS_DB_USER} -h${HASHTOPOLIS_DB_HOST} +``` + +Enable query logging: +``` +docker exec $(docker ps -aqf "ancestor=mysql:8.0") mysql -u root -phashtopolis -e "SET global log_output = 'FILE'; SET global general_log_file='/tmp/mysql_all.log'; SET global general_log = 1;" +docker exec $(docker ps -aqf "ancestor=mysql:8.0") tail -f /tmp/mysql_all.log +``` + +Shortcut for testing within development setup: +``` +cd ~/src/hashtopolis/server/ci/apiv2 +pytest --exitfirst --last-failed +``` + +Run a specific test from the terminal +``` +cd /var/www/html/ci/apiv2 && python3 -m pytest test_task.py::TaskTest::test_toggle_archive_task_supertask_type -v -s +``` diff --git a/ci/apiv2/HACKING.md b/ci/apiv2/HACKING.md deleted file mode 100644 index 2a2418fe9..000000000 --- a/ci/apiv2/HACKING.md +++ /dev/null @@ -1,145 +0,0 @@ -#### Examples -Common sequences of commands used in development setups - -Initilise token: -``` -TOKEN=$(curl -X POST --user admin:hashtopolis http://localhost:8080/api/v2/auth/token | jq -r .token) -``` - - -Fetch object: -``` -curl --compressed --header "Authorization: Bearer $TOKEN" -g 'http://localhost:8080/api/v2/ui/hashtypes?page[size]=5' -``` - -Access database: -``` -mysql -u $HASHTOPOLIS_DB_USER -p$HASHTOPOLIS_DB_PASS -h $HASHTOPOLIS_DB_HOST -D $HASHTOPOLIS_DB_DATABASE -``` - -Enable query logging: -``` -docker exec $(docker ps -aqf "ancestor=mysql:8.0") mysql -u root -phashtopolis -e "SET global log_output = 'FILE'; SET global general_log_file='/tmp/mysql_all.log'; SET global general_log = 1;" -docker exec $(docker ps -aqf "ancestor=mysql:8.0") tail -f /tmp/mysql_all.log -``` - -Shortcut for testing within development setup: -``` -cd ~/src/hashtopolis/server/ci/apiv2 -pytest --exitfirst --last-failed -``` -Run a specific test from the terminal -``` -cd /var/www/html/ci/apiv2 && python3 -m pytest test_task.py::TaskTest::test_toggle_archive_task_supertask_type -v -s -``` -### paper flipchart scribbles - -#### v2 beta - -# Items with '#' are (partially) implemented - -* /api/v2/ - * ./agent : for now aligning to the PHP-api - * ./auth : local OAuth provider - * ./ui : all queries for angular, cli etc. -# * ./agents [GET, POST] -# * ./{id} [GET, PATCH, DELETE] -# * ./{id}/healthchecks [GET, POST] -# * ./{id}/healthchecks/{id} [GET, (PATCH?,) DELETE] -# * ./{id}/healthcheckagents [GET, POST] -# * ./{id}/healthcheckagents/{id} [GET, (PATCH?,) DELETE] -# * ./agentstats [GET] -# * ./agentstats/${id} [DELETE] -# * ./agentbinaries [GET, POST] -# * ./agentbinaries/{id} [GET, PATCH, DELETE] -# * ./chunks [GET] -# * ./{id} [GET] - * ./{id}/abort [POST] - * ./{id}/reset [POST] -# * ./configs [GET, PATCH] - * ./recount-cracked [POST] - * ./rescan-files [POST] - * ./configsections [GET] -# * ./crackers [GET, POST] -# * ./{id} [GET, PATCH, DELETE] - * ./{id}/versions [GET, POST] - * ./{id}/versions/{id} [GET, DELETE, PATCH] - * ./fields [-] - * ./notification-types [GET] - * ./notification-triggers [GET] -# * ./files [GET, POST] -# * ./{id} [GET, PATCH, DELETE] -# * ./hashes [GET (output-format set in GET)] -# * ./{id} [GET (output-format set in GET)] -# * ./hashlists [GET, POST] -# * ./{id} [GET, PATCH, DELETE] - * ./{id}/add-cracked [POST] - * ./{id}/export-cracked [POST] -# * ./hashtypes [GET, POST] -# * ./{id} [GET, PATCH, DELETE] - * ./logs [GET] - * ./{id} [GET] -# * ./logentries [GET] -# * ./{id} [GET] -# * ./notifications [GET, POST] -# * ./{id} [GET, PATCH, ?DELETE?] - * ./notification-settings [GET, POST] - * ./{id} [GET, PATCH, DELETE] - * ./permissiongroups [GET, POST] - * ./{id} [GET, PATCH, DELETE] -# * ./preprocessors [GET, POST] -# * ./{id} [GET, PATCH, DELETE] - * ./pretaskgroup [GET, POST] - * ./{id} [GET, PATCH, DELETE] - * ./import/hcmask [POST] -# * ./pretasks [GET, POST] -# * ./{id} [GET, PATCH, DELETE] -# * ./superhashlists [GET, POST] -# * ./{id} [GET, PATCH, DELETE] - * ./taskgroups [GET] - * ./{tgid} [GET, PATCH, DELETE] - * ./{tgid}/set-toppriority [POST] -# * ./tasks [GET, POST] -# * ./{tid} [GET, PATCH, DELETE] - * ./{tid}/unassign-agents [POST] - * ./{tid}/assign-agents [POST] - * ./{tid}/reset [POST] - * ./{tid}/set-toppriority [POST] - * ./tests [-] - * ./connection [GET] - * ./access [GET] -# * ./tokens [GET, POST] -# * ./{tid} [GET, PATCH, DELETE] -# * ./users/ [GET, POST] -# * ./{id} [GET, PATCH, DELETE] -# * ./vouchers [GET, POST] -# * ./{id} [GET, PATCH, DELETE] - - -# * ./crackertypes [GET, POST] -# * ./{id} [GET, PATCH, DELETE] - - -# Type devs mapping static values (StatType), om generator (bvb DAgentStatsType) casten naar field types. - -#### abbreviations used - -* id - * an ID within the respective scope - -* tid - * taskId (used to differentiate from tgid) - -* tgid - * taskGroupId (used to differentiate from tid) - - -#### additional notes - -permissiongroups should be reflecting the following scopes: - * user (global) - * user (project) - * team (project) - * token - - diff --git a/ci/apiv2/PERMISSIONS_REWORK.md b/ci/apiv2/PERMISSIONS_REWORK.md deleted file mode 100644 index 1d96cd60c..000000000 --- a/ci/apiv2/PERMISSIONS_REWORK.md +++ /dev/null @@ -1,194 +0,0 @@ -Intro -===== -- Current Group API and User API are not consistant can compatible with each-other. -- Permissions seems very fine-grain e.g. set for certain action, request to make more generic. - - - -Suggestion -========== -4 Base groups - - VIEW: View/Search/Qeuery list of objects. View object details. - - CREATE: Create new object. - - MANAGE: Alter existing object. - - DELETE: Delete existing object. - -all set per API endpoint - - -Behaviour in dual-setup (old and new UI) ----------------------------------------- - - Option A: - - Changing (old) permissions will set new permissions if-and-only-if all required old permissions are set. - - Changing (new) permissions will set old permissions of this mapping. - - Option B: - - Yet-an-other-permission schema which only applies to the new UI. - - -Current permission scheme to new permission scheme mapping -========================================================== -Current permission scheme and in brackets the proposed new permissions layout - - -- Access Management (GUI - group) - - Can view Hashlists [VIEW_HASHLIST] - - Can manage hashlists [MANAGE_HASHLIST] - - Can create hashlists [CREATE_HASHLIST] - - Can create superhashlists [CREATE_SUPERHASHLIST] - - User can view cracked/uncracked hashes [VIEW_HASHES] - - Can view agents [VIEW_AGENTS] - - Can manage agents [MANAGE_AGENTS] - - Can create agents [CREATE_AGENTS] - - Can view tasks [VIEW_TASKS] - - Can run preconfigured tasks [CREATE_TASK] - - Can create/delete tasks [CREATE_TASK,DELETE_TASK] - - Can change tasks (set priority, rename, etc.) [CHANGE_TASK] - - Can view preconfigured tasks [VIEW_PERCONFIGURED_TASK] - - Can create/delete preconfigured tasks [CREATE_PRECONFIGURED_TASK] - - Can manage preconfigured tasks [MANAGE_PRECONFIGURED_TASK] - - Can view preconfigured supertasks [VIEW_PRECONFIGURED_SUPERTASK] - - Can create/delete supertasks [MANGE_SUPERTASK] - - Can manage preconfigured supertasks. [MANAGE_PRECONFIGURED_SUPERTASK] - - Can view files [VIEW_FILES] - - Can manage files [MANAGE_FILES, DELETE_FILES] - - Can add files [MANAGE_FILES] - - Can configure cracker binaries [MANGE_CRACKER_BINARIES] - - Can access server configuration [MANAGE_CONFIG] - - Can manage users [MANAGE_USERS] - - Can manage access groups. [MANAGE_GROUPS, MANAGE_PERMISSIONS] - - -- User API (API Management) - - Test - - Connection testing [VIEW_TEST] - - Verifying the API key and test if user has access to the API [VIEW_TEST] - - Agent - - Creating new vouchers [CREATE_VOUCHER] - - Get a list of available agent binaries [VIEW_AGENT_BINARIES] - - List existing vouchers [VIEW_VOUCHER] - - Delete an existing voucher [DELETE_VOUCHER] - - List all agents [VIEW_AGENTS] - - Get details about an agent [VIEW_AGENTS] - - Set an agent active/inactive [MANAGE_AGENTS] - - Change the owner of an agent [MANAGE_AGENTS] - - Set the name of an agent [MANAGE_AGENTS] - - Set if an agent is CPU only or not [MANAGE_AGENTS] - - Set extra flags for an agent [MANAGE_AGENTS] - - Set how errors from an agent should be handled [MANAGE_AGENTS] - - Set if an agent is trusted or not [MANAGE_AGENTS] - - Delete agents [DELETE_AGENTS] - - Task - - List all tasks [VIEW_TASKS] - - Get details of a task [VIEW_TASKS] - - List subtasks of a running supertask [VIEW_TASKS] - - Get details of a chunk [VIEW_CHUNKS] - - Retrieve all cracked hashes by a task [VIEW_HASHES] - - Create a new task [CREATE_TASKS] - - Run an existing preconfigured task with a hashlist [CREATE_TASKS] - - Run a configured supertask with a hashlist [CREATE_TASKS] - - Set the priority of a task [MANAGE_TASKS] - - Set task priority to the previous highest plus one hundred [MANAGE_TASKS] - - Set the priority of a supertask [MANAGE_TASKS] - - Set supertask priority to the previous highest plus one hundred [MANAGE_TASKS] - - Rename a task [MANAGE_TASKS] - - Set the color of a task [MANAGE_TASKS] - - Set if a task is CPU only or not [MANAGE_TASKS] - - Set if a task is small or not [MANAGE_TASKS] - - Set max agents for tasks [MANAGE_TASKS] - - Unassign an agent from a task [MANAGE_AGENTS] - - Assign agents to a task MANAGE_AGENTS] - - Delete a task [DELETE_TASKS] - - Purge a task [MANAGE_TASKS] - - Set the name of a supertask [MANAGE_SUPERTASKS] - - Delete a supertask [MANAGE_SUPERTASKS] - - Archive tasks [MANAGE_TASKS] - - Archive supertasks [MANAGE_SUPERTASKS] - - Pretask - - List all preconfigured tasks [VIEW_PRETASKS] - - Get details about a preconfigured task [VIEW_PRETASKS] - - Create preconfigured tasks [CREATE_PRETASKS] - - Set preconfigured tasks priorities [MANAGE_PRETASKS] - - Set max agents for a preconfigured task [MANAGE_PRETASKS] - - Rename preconfigured tasks [MANAGE_PRETASKS] - - Set the color of a preconfigured task [MANAGE_PRETASKS] - - Change the chunk size for a preconfigured task [MANAGE_PRETASKS] - - Set if a preconfigured task is CPU only or not [MANAGE_PRETASKS] - - Set if a preconfigured task is small or not [MANAGE_PRETASKS] - - Delete preconfigured tasks [DELETE_PRETASKS] - - Supertask - - List all supertasks [VIEW_SUPERTASKS] - - Get details of a supertask [VIEW_SUPERTASKS] - - Create a supertask [CREATE_SUPERTASKS] - - Import a supertask from masks [CREATE_SUPERTASKS] - - Rename a configured supertask [MANAGE_SUPERTASKS] - - Delete a supertask [DELETE_SUPERTASKS] - - Create supertask out base command with files [CREATE_SUPERTASKS] - - Hashlist - - List all hashlists [VIEW_HASHLISTS] - - Get details of a hashlist [VIEW_HASHLISTS] - - Create a new hashlist [CREATE_HASHLISTS] - - Rename hashlists [MANAGE_HASHLISTS] - - Set if a hashlist is secret or not [MANAGE_HASHLISTS] - - Query to archive/un-archie hashlist [MANAGE_HASHLISTS] - - Import cracked hashes [MANAGE_HASHLISTS] - - Export cracked hashes [VIEW_HASHES] - - Generate wordlist from founds [VIEW_HASHES] - - Export a left list of uncracked hashes - - Delete hashlists [DELETE_HASHLISTS] - - Query for specific hashes [VIEW_HASHES] - - Query cracked hashes of a hashlist [VIEW_HASHES] - - Superhashlist - - List all superhashlists [VIEW_SUPERHASHLISTS] - - Get details about a superhashlist [VIEW_SUPERHASHLISTS] - - Create superhashlists [CREATE_SUPERHASHLISTS] - - Delete superhashlists [DELETE_SUPERHASHLISTS] - - File - - List all files [VIEW_FILES] - - Get details of a file [VIEW_FILES] - - Add new files [CREATE_FILES] - - Rename files [MANAGE_FILES] - - Set if a file is secret or not [MANAGE_FILES] - - Delete files [DELETE_FILES] - - Change type of files [MANAGE_FILES] - - Cracker - - List all crackers [VIEW_CRACKERS] - - Get details of a cracker [VIEW_CRACKERS] - - Delete a specific version of a cracker [MANAGE_CRACKERS] - - Deleting crackers [DELETE_CRACKERS] - - Create new crackers [CREATE_CRACKERS] - - Add new cracker versions [MANAGE_CRACKERS] - - Update cracker versions [MANAGE_CRACKERS] - - Config - - List available sections in config [VIEW_CONFIGS] - - List config options of a given section [VIEW_CONFIGS] - - Get current value of a config [VIEW_CONFIGS] - - Change values of configs [MANAGE_CONFIGS] - - User - - List all users [VIEW_USERS] - - Get details of a user [VIEW_USERS] - - Create new users [CREATE_USERS] - - Disable a user account [MANAGE_USERS] - - Enable a user account [MANAGE_USERS] - - Set a user's password [MANAGE_USERS] - - Change the permission group for a user [MANAGE_USERS] - - Group - - List all groups [VIEW_GROUPS] - - Get details of a group [VIEW_GROUPS] - - Create new groups [CREATE_GROUPS] - - Abort all chunks dispatched to agents of this group [MANAGE_AGENTS] - - Delete groups [DELETE_GROUPS] - - Add agents to groups [MANAGE_AGENTS] - - Add users to groups [MANAGE_USERS] - - Remove agents from groups [MANAGE_AGENTS] - - Remove users from groups [MANAGE_USERS] - - Access - - List permission groups [VIEW_PERMISSIONS] - - Get details of a permission group [VIEW_PERMISSIONS] - - Create a new permission group [CREATE_PERMISSIONS] - - Delete permission groups [DELETE_PERMISSIONS] - - Update permissions of a group [MANAGE_PERMISSIONS] - - Account - - Get account information [MANAGE_USERS] - - Change email [MANAGE_USERS] - - Update session length [MANAGE_USERS] - - Change password [MANAGE_USERS] \ No newline at end of file diff --git a/ci/apiv2/poc_openapi_perm_test.sh b/ci/apiv2/poc_openapi_perm_test.sh deleted file mode 100644 index 05f9bb512..000000000 --- a/ci/apiv2/poc_openapi_perm_test.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# PoC to use openapi.json for automated unit testing. This will test of 'GET' permission is available on all API listing endpoints' -# -for ENDPOINT in $(curl -s 'http://localhost:8080/api/v2/openapi.json' | jq -r '.paths | keys[]' | grep -v '}'); do - echo -n "$ENDPOINT..."; - curl --header "Content-Type: application/json" -X GET --header "Authorization: Bearer $TOKEN" "http://localhost:8080$ENDPOINT" -s -d '{}' | grep -q '403' && echo "FAIL" || echo "OK" -done diff --git a/ci/apiv2/test_openapi_permissions.sh b/ci/apiv2/test_openapi_permissions.sh new file mode 100644 index 000000000..837f462a5 --- /dev/null +++ b/ci/apiv2/test_openapi_permissions.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# PoC to use openapi.json for automated unit testing. This will test of 'GET' permission is available on all API listing endpoints' +# +for ENDPOINT in $(curl -s 'http://localhost:8080/api/v2/openapi.json' | jq -r '.paths | keys[]' | grep -v '}'); do + echo -n "$ENDPOINT..."; + curl --header "Content-Type: application/json" -X GET --header "Authorization: Bearer $TOKEN" "http://localhost:8080$ENDPOINT" -s -d '{}' | grep -q '403' && echo "FAIL" || echo "OK" +done diff --git a/ci/apiv2/create_accessgroup_001.json b/ci/apiv2/testfiles/create_accessgroup_001.json similarity index 100% rename from ci/apiv2/create_accessgroup_001.json rename to ci/apiv2/testfiles/create_accessgroup_001.json diff --git a/ci/apiv2/create_accessgroup_002.json b/ci/apiv2/testfiles/create_accessgroup_002.json similarity index 100% rename from ci/apiv2/create_accessgroup_002.json rename to ci/apiv2/testfiles/create_accessgroup_002.json diff --git a/ci/apiv2/create_agentbinary_001.json b/ci/apiv2/testfiles/create_agentbinary_001.json similarity index 100% rename from ci/apiv2/create_agentbinary_001.json rename to ci/apiv2/testfiles/create_agentbinary_001.json diff --git a/ci/apiv2/create_cracker_001.json b/ci/apiv2/testfiles/create_cracker_001.json similarity index 100% rename from ci/apiv2/create_cracker_001.json rename to ci/apiv2/testfiles/create_cracker_001.json diff --git a/ci/apiv2/create_cracker_002.json b/ci/apiv2/testfiles/create_cracker_002.json similarity index 100% rename from ci/apiv2/create_cracker_002.json rename to ci/apiv2/testfiles/create_cracker_002.json diff --git a/ci/apiv2/create_crackertype_001.json b/ci/apiv2/testfiles/create_crackertype_001.json similarity index 100% rename from ci/apiv2/create_crackertype_001.json rename to ci/apiv2/testfiles/create_crackertype_001.json diff --git a/ci/apiv2/create_crackertype_002.json b/ci/apiv2/testfiles/create_crackertype_002.json similarity index 100% rename from ci/apiv2/create_crackertype_002.json rename to ci/apiv2/testfiles/create_crackertype_002.json diff --git a/ci/apiv2/create_file_001.json b/ci/apiv2/testfiles/create_file_001.json similarity index 100% rename from ci/apiv2/create_file_001.json rename to ci/apiv2/testfiles/create_file_001.json diff --git a/ci/apiv2/create_hashlist_001.json b/ci/apiv2/testfiles/create_hashlist_001.json similarity index 100% rename from ci/apiv2/create_hashlist_001.json rename to ci/apiv2/testfiles/create_hashlist_001.json diff --git a/ci/apiv2/create_hashlist_002.json b/ci/apiv2/testfiles/create_hashlist_002.json similarity index 100% rename from ci/apiv2/create_hashlist_002.json rename to ci/apiv2/testfiles/create_hashlist_002.json diff --git a/ci/apiv2/create_hashlist_003.json b/ci/apiv2/testfiles/create_hashlist_003.json similarity index 100% rename from ci/apiv2/create_hashlist_003.json rename to ci/apiv2/testfiles/create_hashlist_003.json diff --git a/ci/apiv2/create_hashtype_001.json b/ci/apiv2/testfiles/create_hashtype_001.json similarity index 100% rename from ci/apiv2/create_hashtype_001.json rename to ci/apiv2/testfiles/create_hashtype_001.json diff --git a/ci/apiv2/create_healthcheck_001.json b/ci/apiv2/testfiles/create_healthcheck_001.json similarity index 100% rename from ci/apiv2/create_healthcheck_001.json rename to ci/apiv2/testfiles/create_healthcheck_001.json diff --git a/ci/apiv2/create_notification_001.json b/ci/apiv2/testfiles/create_notification_001.json similarity index 100% rename from ci/apiv2/create_notification_001.json rename to ci/apiv2/testfiles/create_notification_001.json diff --git a/ci/apiv2/create_preprocessor_001.json b/ci/apiv2/testfiles/create_preprocessor_001.json similarity index 100% rename from ci/apiv2/create_preprocessor_001.json rename to ci/apiv2/testfiles/create_preprocessor_001.json diff --git a/ci/apiv2/create_pretask_001.json b/ci/apiv2/testfiles/create_pretask_001.json similarity index 100% rename from ci/apiv2/create_pretask_001.json rename to ci/apiv2/testfiles/create_pretask_001.json diff --git a/ci/apiv2/testfiles/create_pretask_002.json b/ci/apiv2/testfiles/create_pretask_002.json new file mode 100644 index 000000000..f497939bd --- /dev/null +++ b/ci/apiv2/testfiles/create_pretask_002.json @@ -0,0 +1,15 @@ +{ + "taskName": "Example - create_pretasks_001", + "attackCmd": "-a3 ?l?l?l?l?l", + "chunkTime": 600, + "statusTimer": 700, + "color": "7C6EFF", + "isSmall": true, + "isCpuTask": true, + "useNewBench": true, + "priority": 10, + "maxAgents": 10, + "isMaskImport": false, + "crackerBinaryTypeId": 1, + "files": [] +} diff --git a/ci/apiv2/create_pretask_003.json b/ci/apiv2/testfiles/create_pretask_003.json similarity index 100% rename from ci/apiv2/create_pretask_003.json rename to ci/apiv2/testfiles/create_pretask_003.json diff --git a/ci/apiv2/create_supertask_001.json b/ci/apiv2/testfiles/create_supertask_001.json similarity index 100% rename from ci/apiv2/create_supertask_001.json rename to ci/apiv2/testfiles/create_supertask_001.json diff --git a/ci/apiv2/create_task_001.json b/ci/apiv2/testfiles/create_task_001.json similarity index 100% rename from ci/apiv2/create_task_001.json rename to ci/apiv2/testfiles/create_task_001.json diff --git a/ci/apiv2/create_task_002.json b/ci/apiv2/testfiles/create_task_002.json similarity index 100% rename from ci/apiv2/create_task_002.json rename to ci/apiv2/testfiles/create_task_002.json diff --git a/ci/apiv2/create_task_003.json b/ci/apiv2/testfiles/create_task_003.json similarity index 100% rename from ci/apiv2/create_task_003.json rename to ci/apiv2/testfiles/create_task_003.json diff --git a/ci/apiv2/utils.py b/ci/apiv2/utils.py index 9467ddd3e..48da1431a 100644 --- a/ci/apiv2/utils.py +++ b/ci/apiv2/utils.py @@ -37,7 +37,7 @@ def _do_create_obj_from_file(model_class, file_prefix, extra_payload={}, **kwargs): file_id = kwargs.get('file_id') or '001' - p = Path(__file__).parent.joinpath(f'{file_prefix}_{file_id}.json') + p = Path(__file__).parent.joinpath(f'testfiles/{file_prefix}_{file_id}.json') payload = json.loads(p.read_text('UTF-8')) final_payload = {**payload, **extra_payload} obj = model_class(**final_payload) From 83d012090f650b1e2a119fadbae12c6109d414e3 Mon Sep 17 00:00:00 2001 From: s3inlc Date: Tue, 2 Dec 2025 14:06:00 +0100 Subject: [PATCH 2/3] structured all json files into further subdirs to have them tied to their models to keep overview with more new test files added, for example added further tests for pretask --- ci/apiv2/test_pretask.py | 38 +++++++++++++++++-- ci/apiv2/test_supertask.py | 2 +- .../create_accessgroup_001.json | 0 .../create_accessgroup_002.json | 0 .../create_agentbinary_001.json | 0 .../{ => cracker}/create_cracker_001.json | 0 .../{ => cracker}/create_cracker_002.json | 0 .../create_crackertype_001.json | 0 .../create_crackertype_002.json | 0 .../testfiles/{ => file}/create_file_001.json | 0 .../{ => hashlist}/create_hashlist_001.json | 0 .../{ => hashlist}/create_hashlist_002.json | 0 .../{ => hashlist}/create_hashlist_003.json | 0 .../{ => hashtype}/create_hashtype_001.json | 0 .../create_healthcheck_001.json | 0 .../create_notification_001.json | 0 .../create_preprocessor_001.json | 0 .../{ => pretask}/create_pretask_001.json | 0 .../create_pretask_002.json} | 0 .../create_pretask_chunk_negative.json | 15 ++++++++ .../pretask/create_pretask_chunk_zero.json | 15 ++++++++ .../create_pretask_inv_attackcmd.json} | 0 .../pretask/create_pretask_inv_name.json | 15 ++++++++ .../{ => supertask}/create_supertask_001.json | 0 .../testfiles/{ => task}/create_task_001.json | 0 .../testfiles/{ => task}/create_task_002.json | 0 .../testfiles/{ => task}/create_task_003.json | 0 ci/apiv2/utils.py | 2 +- 28 files changed, 81 insertions(+), 6 deletions(-) rename ci/apiv2/testfiles/{ => accessgroup}/create_accessgroup_001.json (100%) rename ci/apiv2/testfiles/{ => accessgroup}/create_accessgroup_002.json (100%) rename ci/apiv2/testfiles/{ => agentbinary}/create_agentbinary_001.json (100%) rename ci/apiv2/testfiles/{ => cracker}/create_cracker_001.json (100%) rename ci/apiv2/testfiles/{ => cracker}/create_cracker_002.json (100%) rename ci/apiv2/testfiles/{ => crackertype}/create_crackertype_001.json (100%) rename ci/apiv2/testfiles/{ => crackertype}/create_crackertype_002.json (100%) rename ci/apiv2/testfiles/{ => file}/create_file_001.json (100%) rename ci/apiv2/testfiles/{ => hashlist}/create_hashlist_001.json (100%) rename ci/apiv2/testfiles/{ => hashlist}/create_hashlist_002.json (100%) rename ci/apiv2/testfiles/{ => hashlist}/create_hashlist_003.json (100%) rename ci/apiv2/testfiles/{ => hashtype}/create_hashtype_001.json (100%) rename ci/apiv2/testfiles/{ => healthcheck}/create_healthcheck_001.json (100%) rename ci/apiv2/testfiles/{ => notification}/create_notification_001.json (100%) rename ci/apiv2/testfiles/{ => preprocessor}/create_preprocessor_001.json (100%) rename ci/apiv2/testfiles/{ => pretask}/create_pretask_001.json (100%) rename ci/apiv2/testfiles/{create_pretask_003.json => pretask/create_pretask_002.json} (100%) create mode 100644 ci/apiv2/testfiles/pretask/create_pretask_chunk_negative.json create mode 100644 ci/apiv2/testfiles/pretask/create_pretask_chunk_zero.json rename ci/apiv2/testfiles/{create_pretask_002.json => pretask/create_pretask_inv_attackcmd.json} (100%) create mode 100644 ci/apiv2/testfiles/pretask/create_pretask_inv_name.json rename ci/apiv2/testfiles/{ => supertask}/create_supertask_001.json (100%) rename ci/apiv2/testfiles/{ => task}/create_task_001.json (100%) rename ci/apiv2/testfiles/{ => task}/create_task_002.json (100%) rename ci/apiv2/testfiles/{ => task}/create_task_003.json (100%) diff --git a/ci/apiv2/test_pretask.py b/ci/apiv2/test_pretask.py index 5bbf2aab3..16b49a251 100644 --- a/ci/apiv2/test_pretask.py +++ b/ci/apiv2/test_pretask.py @@ -1,5 +1,5 @@ -from hashtopolis import Pretask -from utils import BaseTest +from hashtopolis import Pretask, HashtopolisError +from utils import BaseTest,do_create_pretask class PretaskTest(BaseTest): @@ -16,6 +16,14 @@ def test_patch(self): model_obj = self.create_test_object() self._test_patch(model_obj, 'taskName') + def test_patch_missing_alias(self): + model_obj = self.create_test_object() + model_obj.attackCmd = "-a 3 ?l?l?l" + with self.assertRaises(HashtopolisError) as e: + model_obj.save() + self.assertEqual(e.exception.status_code, 500) + self.assertEqual(e.exception.title, f"The attack command does not contain the hashlist alias!") + def test_delete(self): model_obj = self.create_test_object(delete=False) self._test_delete(model_obj) @@ -25,6 +33,28 @@ def test_expandables(self): expandables = ['pretaskFiles'] self._test_expandables(model_obj, expandables) - def test_create_pretask_alt(self): - model_obj = self.create_test_object(file_id='003') + def test_create_alt(self): + model_obj = self.create_test_object(file_id='002') + self._test_create(model_obj) + + def test_create_missing_alias(self): + with self.assertRaises(HashtopolisError) as e: + model_obj = self.create_test_object(file_id='inv_attackcmd') + self.assertEqual(e.exception.status_code, 400) + self.assertEqual(e.exception.title, "The attack command does not contain the hashlist alias!") + + def test_create_empty_name(self): + with self.assertRaises(HashtopolisError) as e: + model_obj = self.create_test_object(file_id='inv_name') + self.assertEqual(e.exception.status_code, 400) + self.assertEqual(e.exception.title, "Name cannot be empty!") + + def test_create_chunktime_zero(self): + model_obj = self.create_test_object(file_id='chunk_zero') + self._test_create(model_obj) + self.assertGreater(model_obj.chunkTime, 0) + + def test_create_chunktime_negative(self): + model_obj = self.create_test_object(file_id='chunk_negative') self._test_create(model_obj) + self.assertGreater(model_obj.chunkTime, 0) diff --git a/ci/apiv2/test_supertask.py b/ci/apiv2/test_supertask.py index ac8874bea..395f58710 100644 --- a/ci/apiv2/test_supertask.py +++ b/ci/apiv2/test_supertask.py @@ -31,7 +31,7 @@ def test_new_pretasks(self): # Quirk for expanding object to allow update to take place work_obj = Supertask.objects.prefetch_related('pretasks').get(pk=model_obj.id) - new_pretasks = [self.create_pretask(file_id="003") for i in range(2)] + new_pretasks = [self.create_pretask(file_id="002") for i in range(2)] selected_pretasks = [work_obj.pretasks_set[0], new_pretasks[1]] work_obj.pretasks_set = selected_pretasks work_obj.save() diff --git a/ci/apiv2/testfiles/create_accessgroup_001.json b/ci/apiv2/testfiles/accessgroup/create_accessgroup_001.json similarity index 100% rename from ci/apiv2/testfiles/create_accessgroup_001.json rename to ci/apiv2/testfiles/accessgroup/create_accessgroup_001.json diff --git a/ci/apiv2/testfiles/create_accessgroup_002.json b/ci/apiv2/testfiles/accessgroup/create_accessgroup_002.json similarity index 100% rename from ci/apiv2/testfiles/create_accessgroup_002.json rename to ci/apiv2/testfiles/accessgroup/create_accessgroup_002.json diff --git a/ci/apiv2/testfiles/create_agentbinary_001.json b/ci/apiv2/testfiles/agentbinary/create_agentbinary_001.json similarity index 100% rename from ci/apiv2/testfiles/create_agentbinary_001.json rename to ci/apiv2/testfiles/agentbinary/create_agentbinary_001.json diff --git a/ci/apiv2/testfiles/create_cracker_001.json b/ci/apiv2/testfiles/cracker/create_cracker_001.json similarity index 100% rename from ci/apiv2/testfiles/create_cracker_001.json rename to ci/apiv2/testfiles/cracker/create_cracker_001.json diff --git a/ci/apiv2/testfiles/create_cracker_002.json b/ci/apiv2/testfiles/cracker/create_cracker_002.json similarity index 100% rename from ci/apiv2/testfiles/create_cracker_002.json rename to ci/apiv2/testfiles/cracker/create_cracker_002.json diff --git a/ci/apiv2/testfiles/create_crackertype_001.json b/ci/apiv2/testfiles/crackertype/create_crackertype_001.json similarity index 100% rename from ci/apiv2/testfiles/create_crackertype_001.json rename to ci/apiv2/testfiles/crackertype/create_crackertype_001.json diff --git a/ci/apiv2/testfiles/create_crackertype_002.json b/ci/apiv2/testfiles/crackertype/create_crackertype_002.json similarity index 100% rename from ci/apiv2/testfiles/create_crackertype_002.json rename to ci/apiv2/testfiles/crackertype/create_crackertype_002.json diff --git a/ci/apiv2/testfiles/create_file_001.json b/ci/apiv2/testfiles/file/create_file_001.json similarity index 100% rename from ci/apiv2/testfiles/create_file_001.json rename to ci/apiv2/testfiles/file/create_file_001.json diff --git a/ci/apiv2/testfiles/create_hashlist_001.json b/ci/apiv2/testfiles/hashlist/create_hashlist_001.json similarity index 100% rename from ci/apiv2/testfiles/create_hashlist_001.json rename to ci/apiv2/testfiles/hashlist/create_hashlist_001.json diff --git a/ci/apiv2/testfiles/create_hashlist_002.json b/ci/apiv2/testfiles/hashlist/create_hashlist_002.json similarity index 100% rename from ci/apiv2/testfiles/create_hashlist_002.json rename to ci/apiv2/testfiles/hashlist/create_hashlist_002.json diff --git a/ci/apiv2/testfiles/create_hashlist_003.json b/ci/apiv2/testfiles/hashlist/create_hashlist_003.json similarity index 100% rename from ci/apiv2/testfiles/create_hashlist_003.json rename to ci/apiv2/testfiles/hashlist/create_hashlist_003.json diff --git a/ci/apiv2/testfiles/create_hashtype_001.json b/ci/apiv2/testfiles/hashtype/create_hashtype_001.json similarity index 100% rename from ci/apiv2/testfiles/create_hashtype_001.json rename to ci/apiv2/testfiles/hashtype/create_hashtype_001.json diff --git a/ci/apiv2/testfiles/create_healthcheck_001.json b/ci/apiv2/testfiles/healthcheck/create_healthcheck_001.json similarity index 100% rename from ci/apiv2/testfiles/create_healthcheck_001.json rename to ci/apiv2/testfiles/healthcheck/create_healthcheck_001.json diff --git a/ci/apiv2/testfiles/create_notification_001.json b/ci/apiv2/testfiles/notification/create_notification_001.json similarity index 100% rename from ci/apiv2/testfiles/create_notification_001.json rename to ci/apiv2/testfiles/notification/create_notification_001.json diff --git a/ci/apiv2/testfiles/create_preprocessor_001.json b/ci/apiv2/testfiles/preprocessor/create_preprocessor_001.json similarity index 100% rename from ci/apiv2/testfiles/create_preprocessor_001.json rename to ci/apiv2/testfiles/preprocessor/create_preprocessor_001.json diff --git a/ci/apiv2/testfiles/create_pretask_001.json b/ci/apiv2/testfiles/pretask/create_pretask_001.json similarity index 100% rename from ci/apiv2/testfiles/create_pretask_001.json rename to ci/apiv2/testfiles/pretask/create_pretask_001.json diff --git a/ci/apiv2/testfiles/create_pretask_003.json b/ci/apiv2/testfiles/pretask/create_pretask_002.json similarity index 100% rename from ci/apiv2/testfiles/create_pretask_003.json rename to ci/apiv2/testfiles/pretask/create_pretask_002.json diff --git a/ci/apiv2/testfiles/pretask/create_pretask_chunk_negative.json b/ci/apiv2/testfiles/pretask/create_pretask_chunk_negative.json new file mode 100644 index 000000000..d57a1f07e --- /dev/null +++ b/ci/apiv2/testfiles/pretask/create_pretask_chunk_negative.json @@ -0,0 +1,15 @@ +{ + "taskName": "Example - create_pretasks_001", + "attackCmd": "#HL# -a3 ?l?l?l?l?l", + "chunkTime": -100, + "statusTimer": 700, + "color": "7C6EFF", + "isSmall": true, + "isCpuTask": true, + "useNewBench": true, + "priority": 10, + "maxAgents": 10, + "isMaskImport": false, + "crackerBinaryTypeId": 1, + "files": [] +} diff --git a/ci/apiv2/testfiles/pretask/create_pretask_chunk_zero.json b/ci/apiv2/testfiles/pretask/create_pretask_chunk_zero.json new file mode 100644 index 000000000..3eee8d2b9 --- /dev/null +++ b/ci/apiv2/testfiles/pretask/create_pretask_chunk_zero.json @@ -0,0 +1,15 @@ +{ + "taskName": "Example - create_pretasks_001", + "attackCmd": "#HL# -a3 ?l?l?l?l?l", + "chunkTime": 0, + "statusTimer": 700, + "color": "7C6EFF", + "isSmall": true, + "isCpuTask": true, + "useNewBench": true, + "priority": 10, + "maxAgents": 10, + "isMaskImport": false, + "crackerBinaryTypeId": 1, + "files": [] +} diff --git a/ci/apiv2/testfiles/create_pretask_002.json b/ci/apiv2/testfiles/pretask/create_pretask_inv_attackcmd.json similarity index 100% rename from ci/apiv2/testfiles/create_pretask_002.json rename to ci/apiv2/testfiles/pretask/create_pretask_inv_attackcmd.json diff --git a/ci/apiv2/testfiles/pretask/create_pretask_inv_name.json b/ci/apiv2/testfiles/pretask/create_pretask_inv_name.json new file mode 100644 index 000000000..147685cc3 --- /dev/null +++ b/ci/apiv2/testfiles/pretask/create_pretask_inv_name.json @@ -0,0 +1,15 @@ +{ + "taskName": "", + "attackCmd": "#HL# -a3 ?l?l?l?l?l", + "chunkTime": 600, + "statusTimer": 700, + "color": "7C6EFF", + "isSmall": true, + "isCpuTask": true, + "useNewBench": true, + "priority": 10, + "maxAgents": 10, + "isMaskImport": false, + "crackerBinaryTypeId": 1, + "files": [] +} diff --git a/ci/apiv2/testfiles/create_supertask_001.json b/ci/apiv2/testfiles/supertask/create_supertask_001.json similarity index 100% rename from ci/apiv2/testfiles/create_supertask_001.json rename to ci/apiv2/testfiles/supertask/create_supertask_001.json diff --git a/ci/apiv2/testfiles/create_task_001.json b/ci/apiv2/testfiles/task/create_task_001.json similarity index 100% rename from ci/apiv2/testfiles/create_task_001.json rename to ci/apiv2/testfiles/task/create_task_001.json diff --git a/ci/apiv2/testfiles/create_task_002.json b/ci/apiv2/testfiles/task/create_task_002.json similarity index 100% rename from ci/apiv2/testfiles/create_task_002.json rename to ci/apiv2/testfiles/task/create_task_002.json diff --git a/ci/apiv2/testfiles/create_task_003.json b/ci/apiv2/testfiles/task/create_task_003.json similarity index 100% rename from ci/apiv2/testfiles/create_task_003.json rename to ci/apiv2/testfiles/task/create_task_003.json diff --git a/ci/apiv2/utils.py b/ci/apiv2/utils.py index 48da1431a..90179a3aa 100644 --- a/ci/apiv2/utils.py +++ b/ci/apiv2/utils.py @@ -37,7 +37,7 @@ def _do_create_obj_from_file(model_class, file_prefix, extra_payload={}, **kwargs): file_id = kwargs.get('file_id') or '001' - p = Path(__file__).parent.joinpath(f'testfiles/{file_prefix}_{file_id}.json') + p = Path(__file__).parent.joinpath(f'testfiles/{model_class.__name__.lower()}/{file_prefix}_{file_id}.json') payload = json.loads(p.read_text('UTF-8')) final_payload = {**payload, **extra_payload} obj = model_class(**final_payload) From 81b6ec47a177b50ade9498d124fc9af553b22ac9 Mon Sep 17 00:00:00 2001 From: s3inlc Date: Tue, 2 Dec 2025 15:02:26 +0100 Subject: [PATCH 3/3] completed similar coverage as legacy tests for Pretask model, fixed missing checks in new api --- ci/apiv2/test_pretask.py | 78 ++++++++++++++++++++++++- src/inc/apiv2/model/pretasks.routes.php | 4 +- src/inc/utils/PretaskUtils.class.php | 3 + 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/ci/apiv2/test_pretask.py b/ci/apiv2/test_pretask.py index 16b49a251..2d0c2590c 100644 --- a/ci/apiv2/test_pretask.py +++ b/ci/apiv2/test_pretask.py @@ -12,10 +12,46 @@ def test_create(self): model_obj = self.create_test_object() self._test_create(model_obj) - def test_patch(self): + def test_patch_name(self): model_obj = self.create_test_object() self._test_patch(model_obj, 'taskName') + def test_patch_color(self): + model_obj = self.create_test_object() + self._test_patch(model_obj, 'color', "deadbf") + + def test_patch_priority(self): + model_obj = self.create_test_object() + self._test_patch(model_obj, 'priority', 500) + + def test_patch_priority_zero(self): + model_obj = self.create_test_object() + self._test_patch(model_obj, 'priority', 0) + + def test_patch_priority_negative(self): + model_obj = self.create_test_object() + self._test_patch(model_obj, 'priority', -500) + + def test_patch_maxAgents(self): + model_obj = self.create_test_object() + self._test_patch(model_obj, 'maxAgents', 10) + + def test_patch_maxAgents_zero(self): + model_obj = self.create_test_object() + self._test_patch(model_obj, 'maxAgents', 0) + + def test_patch_isSmall(self): + model_obj = self.create_test_object() + self._test_patch(model_obj, 'isSmall', 1) + model_obj = self.create_test_object() + self._test_patch(model_obj, 'isSmall', True) + + def test_patch_isCpuTask(self): + model_obj = self.create_test_object() + self._test_patch(model_obj, 'isCpuTask', 1) + model_obj = self.create_test_object() + self._test_patch(model_obj, 'isCpuTask', True) + def test_patch_missing_alias(self): model_obj = self.create_test_object() model_obj.attackCmd = "-a 3 ?l?l?l" @@ -24,6 +60,46 @@ def test_patch_missing_alias(self): self.assertEqual(e.exception.status_code, 500) self.assertEqual(e.exception.title, f"The attack command does not contain the hashlist alias!") + def test_patch_empty_name(self): + model_obj = self.create_test_object() + model_obj.taskName = "" + with self.assertRaises(HashtopolisError) as e: + model_obj.save() + self.assertEqual(e.exception.status_code, 500) + self.assertEqual(e.exception.title, "Name cannot be empty!") + + def test_patch_maxAgents_negative(self): + model_obj = self.create_test_object() + model_obj.maxAgents = -5 + with self.assertRaises(HashtopolisError) as e: + model_obj.save() + self.assertEqual(e.exception.status_code, 500) + self.assertEqual(e.exception.title, "Max agents cannot be negative!") + + def test_patch_invalid_color(self): + model_obj = self.create_test_object() + model_obj.color = "hello1" + with self.assertRaises(HashtopolisError) as e: + model_obj.save() + self.assertEqual(e.exception.status_code, 500) + self.assertEqual(e.exception.title, "Invalid color!") + + def test_patch_invalid_isSmall(self): + model_obj = self.create_test_object() + model_obj.isSmall = 4 + with self.assertRaises(HashtopolisError) as e: + model_obj.save() + self.assertEqual(e.exception.status_code, 400) + self.assertEqual(e.exception.title, "Key 'isSmall' is not of type boolean") + + def test_patch_invalid_isCpuTask(self): + model_obj = self.create_test_object() + model_obj.isCpuTask = "test" + with self.assertRaises(HashtopolisError) as e: + model_obj.save() + self.assertEqual(e.exception.status_code, 400) + self.assertEqual(e.exception.title, "Key 'isCpuTask' is not of type boolean") + def test_delete(self): model_obj = self.create_test_object(delete=False) self._test_delete(model_obj) diff --git a/src/inc/apiv2/model/pretasks.routes.php b/src/inc/apiv2/model/pretasks.routes.php index 85e4dff67..81a5f8b2e 100644 --- a/src/inc/apiv2/model/pretasks.routes.php +++ b/src/inc/apiv2/model/pretasks.routes.php @@ -68,6 +68,8 @@ protected function getUpdateHandlers($id, $current_user): array { return [ Pretask::ATTACK_CMD => fn($value) => PretaskUtils::changeAttack($id, $value), Pretask::COLOR => fn($value) => PretaskUtils::setColor($id, $value), + Pretask::TASK_NAME => fn($value) => PretaskUtils::renamePretask($id, $value), + Pretask::MAX_AGENTS => fn($value) => PretaskUtils::setMaxAgents($id, $value), ]; } @@ -79,4 +81,4 @@ protected function deleteObject(object $object): void { } } -PreTaskAPI::register($app); \ No newline at end of file +PreTaskAPI::register($app); diff --git a/src/inc/utils/PretaskUtils.class.php b/src/inc/utils/PretaskUtils.class.php index 005f5964b..526606a97 100644 --- a/src/inc/utils/PretaskUtils.class.php +++ b/src/inc/utils/PretaskUtils.class.php @@ -125,6 +125,9 @@ public static function setMaxAgents($pretaskId, $maxAgents) { throw new HTException("Max agents needs to be a number!"); } $maxAgents = intval($maxAgents); + if ($maxAgents < 0) { + throw new HTException("Max agents cannot be negative!"); + } Factory::getPretaskFactory()->set($pretask, Pretask::MAX_AGENTS, $maxAgents); }