From d9c183fbd86e2553a125e8501729f9d71b6e0681 Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Mon, 22 Apr 2024 11:47:49 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BF=AE=E6=94=B9=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_backdoor_detection.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/test_backdoor_detection.py b/tests/test_backdoor_detection.py index f61b561..0c2935a 100644 --- a/tests/test_backdoor_detection.py +++ b/tests/test_backdoor_detection.py @@ -1,5 +1,9 @@ import unittest -from detection.backdoor_detection import find_dangerous_functions +import os +import sys + +sys.path.append(os.path.abspath("../detection")) +from backdoor_detection import find_dangerous_functions class TestBackdoorDetection(unittest.TestCase): @@ -9,7 +13,8 @@ class TestBackdoorDetection(unittest.TestCase): exec('print("Hello")') # high risk eval('2 + 2') # high risk """ - results = find_dangerous_functions(content) + file_extension = ".py" + results = find_dangerous_functions(content, file_extension) self.assertIn((2, "os.system('rm -rf /')"), results["high"]) self.assertIn((3, "exec('print(\"Hello\")')"), results["high"]) self.assertIn((4, "eval('2 + 2')"), results["high"]) @@ -20,7 +25,8 @@ class TestBackdoorDetection(unittest.TestCase): import os os.popen('ls') # medium risk """ - results = find_dangerous_functions(content) + file_extension = ".py" + results = find_dangerous_functions(content, file_extension) self.assertIn((2, "subprocess.run(['ls', '-l'])"), results["medium"]) self.assertIn((4, "os.popen('ls')"), results["medium"]) @@ -29,7 +35,8 @@ class TestBackdoorDetection(unittest.TestCase): b = a + 5 print('This should not be detected as risky.') """ - results = find_dangerous_functions(content) + file_extension = ".py" + results = find_dangerous_functions(content, file_extension) self.assertEqual(len(results["high"]), 0) self.assertEqual(len(results["medium"]), 0) self.assertEqual(len(results["low"]), 0) @@ -40,7 +47,8 @@ class TestBackdoorDetection(unittest.TestCase): eval('2 + 2') # This should be high risk subprocess.run(['echo', 'hello']) # This should be medium risk """ - results = find_dangerous_functions(content) + file_extension = ".py" + results = find_dangerous_functions(content, file_extension) self.assertIn( (3, "eval('2 + 2')"), results["high"],