test:添加GPT检测测试用例
Some checks are pending
Python application test / build (pull_request) Waiting to run

This commit is contained in:
2024-04-28 15:37:11 +08:00
parent be59c891e5
commit 135a07219d
3 changed files with 28 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import unittest
from detection.backdoor_detection import find_dangerous_functions
from detection.GPTdetection import *
class TestBackdoorDetection(unittest.TestCase):
@@ -55,6 +56,25 @@ class TestBackdoorDetection(unittest.TestCase):
results["medium"],
)
def test_gpt_risk_detection(self):
content = """import os
os.system('rm -rf /') # high risk
exec('print("Hello")') # high risk
eval('2 + 2') # high risk
"""
results = detectGPT(content)
self.assertEqual(len(results["high"]), 3)
def test_gpt_no_risk_detection(self):
content = """a = 10
b = a + 5
print('This should not be detected as risky.')
"""
results = detectGPT(content)
self.assertEqual(len(results["high"]), 0)
self.assertEqual(len(results["medium"]), 0)
self.assertEqual(len(results["low"]), 0)
if __name__ == "__main__":
unittest.main()