From bf19a0a9aea85faa9fbf4441c3ff2b616e55101a Mon Sep 17 00:00:00 2001 From: S-mishina <45090872+S-mishina@users.noreply.github.com> Date: Sun, 8 Dec 2024 17:34:33 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Code=20that=20destro?= =?UTF-8?q?ys=20the=20application=20with=20MEMORY=20(#76)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/project/main.py b/project/main.py index e92349d4..076da859 100644 --- a/project/main.py +++ b/project/main.py @@ -302,6 +302,11 @@ def max_cpu(duration,core): p.start() return jsonify({"message": f'{core}Core is used for {duration} seconds MAX'}), 202 +@app.route('//max-memory', methods=['GET']) +def max_memory(memory): + data = bytearray(1024 * 1024 * memory) + return jsonify({"message": f"{memory} MiB usage"}), 200 + @app.route('/', methods=HTTP_METHODS) def custom_rule(path): From e40c149be51f9f38e2e981827d70abf9c13fa0e2 Mon Sep 17 00:00:00 2001 From: S-mishina <45090872+S-mishina@users.noreply.github.com> Date: Sun, 8 Dec 2024 19:48:53 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Code=20to=20destroy?= =?UTF-8?q?=20storages=20(#77)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 🎸 Code to destroy storages * Fix code scanning alert no. 4: Uncontrolled data used in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Fix code scanning alert no. 5: Uncontrolled data used in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- project/main.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/project/main.py b/project/main.py index 076da859..fe4b1e70 100644 --- a/project/main.py +++ b/project/main.py @@ -300,13 +300,25 @@ def max_cpu(duration,core): core_count = int(request.args.get('cores', core)) p = Process(target=multi_core_cpu_load, args=(duration, core_count)) p.start() - return jsonify({"message": f'{core}Core is used for {duration} seconds MAX'}), 202 + return jsonify({"message": f'{core}Core is used for {duration} seconds MAX'}), 200 @app.route('//max-memory', methods=['GET']) def max_memory(memory): data = bytearray(1024 * 1024 * memory) return jsonify({"message": f"{memory} MiB usage"}), 200 +@app.route('//max-storage', methods=['GET']) +def max_storage(storage): + if storage <= 0: + return make_response(jsonify(err="Invalid storage value"), 400) + base_path = '/tmp' + file_name = f'{storage}MB' + file_path = os.path.normpath(os.path.join(base_path, file_name)) + if not file_path.startswith(base_path): + return make_response(jsonify(err="Invalid file path"), 400) + with open(file_path, 'wb') as f: + f.write(bytearray(1024 * 1024 * storage)) + return jsonify({"message": f"{storage} MiB storage usage"}), 200 @app.route('/', methods=HTTP_METHODS) def custom_rule(path):