test: 修改单元测试
Some checks failed
Python application test / build (pull_request) Failing after 15s
Some checks failed
Python application test / build (pull_request) Failing after 15s
This commit is contained in:
parent
c5cfcb00f7
commit
d9c183fbd8
@ -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"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user