DeepTeam is a framework to red team LLMs and AI agents.
Added tests for frameworks
A-Vamshi6304fe38a9ba
diff --git a/tests/test_core/test_frameworks/test_aegis.py b/tests/test_core/test_frameworks/test_aegis.pynew file mode 100644index 00000000..74860258--- /dev/null+++ b/tests/test_core/test_frameworks/test_aegis.py@@ -0,0 +1,56 @@+import pytest+from deepteam.frameworks import Aegis+from deepteam import red_team+++class TestAegis:++ def test_aegis_init(self):+ """Test that Aegis framework can be instantiated."""+ framework = Aegis()+ assert framework is not None++ def test_aegis_name(self):+ """Test that Aegis framework has correct name."""+ framework = Aegis()+ assert framework.name == "Aegis"++ def test_aegis_description(self):+ """Test that Aegis framework has correct description."""+ framework = Aegis()+ assert framework.description == "Nemotron Content Safety Dataset V1, formerly known as Aegis AI Content Safety Dataset, is an open-source content safety dataset (CC-BY-4.0), which adheres to Nvidia's content safety taxonomy, covering 13 critical risk categories"++ def test_aegis_red_team(self):+ """Test that Aegis framework can be used with red_team function."""++ def mock_model_callback(prompt: str) -> str:+ return (+ "I'm a helpful AI assistant. I cannot help with that request."+ )++ risk_assessment = red_team(+ model_callback=mock_model_callback,+ framework=Aegis(num_attacks=5),+ async_mode=False,+ ignore_errors=True,+ )++ assert risk_assessment is not None++ @pytest.mark.asyncio+ async def test_aegis_async_red_team(self):+ """Test that Aegis framework can be used with red_team function in async mode."""++ async def mock_async_model_callback(prompt: str) -> str:+ return (+ "I'm a helpful AI assistant. I cannot help with that request."+ )++ risk_assessment = red_team(+ model_callback=mock_async_model_callback,+ framework=Aegis(num_attacks=5),+ async_mode=True,+ ignore_errors=True,+ )++ assert risk_assessment is not None\ No newline at end of filediff --git a/tests/test_core/test_frameworks/test_beavertails.py b/tests/test_core/test_frameworks/test_beavertails.pynew file mode 100644index 00000000..9e4895fd--- /dev/null+++ b/tests/test_core/test_frameworks/test_beavertails.py@@ -0,0 +1,56 @@+import pytest+from deepteam.frameworks import BeaverTails+from deepteam import red_team+++class TestBeaverTails:++ def test_beavertails_init(self):+ """Test that BeaverTails framework can be instantiated."""+ framework = BeaverTails()+ assert framework is not None++ def test_beavertails_name(self):+ """Test that BeaverTails framework has correct name."""+ framework = BeaverTails()+ assert framework.name == "BeaverTails"++ def test_beavertails_description(self):+ """Test that BeaverTails framework has correct description."""+ framework = BeaverTails()+ assert framework.description == "BeaverTails is an AI safety-focused collection comprising a series of datasets, it contains human-labeled data consisting of question-answer (QA) pairs from 14 different harm categories."++ def test_beavertails_red_team(self):+ """Test that BeaverTails framework can be used with red_team function."""++ def mock_model_callback(prompt: str) -> str:+ return (+ "I'm a helpful AI assistant. I cannot help with that request."+ )++ risk_assessment = red_team(+ model_callback=mock_model_callback,+ framework=BeaverTails(num_attacks=5),+ async_mode=False,+ ignore_errors=True,+ )++ assert risk_assessment is not None++ @pytest.mark.asyncio+ async def test_beavertails_async_red_team(self):+ """Test that BeaverTails framework can be used with red_team function in async mode."""++ async def mock_async_model_callback(prompt: str) -> str:+ return (+ "I'm a helpful AI assistant. I cannot help with that request."+ )++ risk_assessment = red_team(+ model_callback=mock_async_model_callback,+ framework=BeaverTails(num_attacks=5),+ async_mode=True,+ ignore_errors=True,+ )++ assert risk_assessment is not None\ No newline at end of filediff --git a/tests/test_core/test_frameworks/test_mitre.py b/tests/test_core/test_frameworks/test_mitre.pynew file mode 100644index 00000000..23f33092--- /dev/null+++ b/tests/test_core/test_frameworks/test_mitre.py@@ -0,0 +1,176 @@+import pytest+from deepteam.frameworks import MITRE+from deepteam.vulnerabilities import BaseVulnerability+from deepteam.attacks import BaseAttack+from deepteam import red_team+++class TestMITRE:++ def test_mitre_init(self):+ """Test that MITRE ATLAS framework can be instantiated."""+ framework = MITRE()+ assert framework is not None++ def test_mitre_name(self):+ """Test that MITRE ATLAS framework has correct name."""+ framework = MITRE()+ assert framework.name == framework.get_name() == "MITRE ATLAS"++ def test_mitre_description(self):+ """Test that MITRE ATLAS framework has correct description."""+ framework = MITRE()+ assert framework.description == "MITRE ATLAS mapping for LLM/ML adversarial techniques (project-specific) to understand and defend against threats specific to AI and ML systems."++ def test_mitre_default_categories(self):+ """Test that all six MITRE categories are included by default."""+ framework = MITRE()+ assert set(framework.categories) == {+ "reconnaissance",+ "resource_development",+ "initial_access",+ "ml_attack_staging",+ "exfiltration",+ "impact",+ }++ def test_mitre_partial_categories(self):+ """Test that MITRE can be initialized with limited categories."""+ framework = MITRE(categories=["reconnaissance", "impact"])+ assert set(framework.categories) == {"reconnaissance", "impact"}++ def test_mitre_vulnerabilities_exist(self):+ """Test that MITRE framework defines vulnerabilities."""+ framework = MITRE()+ assert hasattr(framework, "vulnerabilities")+ assert len(framework.vulnerabilities) > 0++ def test_mitre_vulnerabilities_are_instances(self):+ """Test that all vulnerabilities are instances of BaseVulnerability."""+ framework = MITRE()+ for vuln in framework.vulnerabilities:+ assert isinstance(vuln, BaseVulnerability)++ def test_mitre_attacks_exist(self):+ """Test that MITRE framework defines attacks."""+ framework = MITRE()+ assert hasattr(framework, "attacks")+ assert len(framework.attacks) > 0++ def test_mitre_attacks_are_instances(self):+ """Test that all attacks are instances of BaseAttack."""+ framework = MITRE()+ for attack in framework.attacks:+ assert isinstance(attack, BaseAttack)++ def test_mitre_category_vulnerability_mapping(self):+ """Test that all categories map to vulnerabilities properly."""+ framework = MITRE()+ mapping = framework._mitre_vulnerabilities_by_category()+ assert set(mapping.keys()) == {+ "reconnaissance",+ "resource_development",+ "initial_access",+ "ml_attack_staging",+ "exfiltration",+ "impact",+ }+ for vlist in mapping.values():+ assert isinstance(vlist, list)+ assert all(isinstance(v, BaseVulnerability) for v in vlist)++ def test_mitre_category_attack_mapping(self):+ """Test that all categories map to attacks properly."""+ framework = MITRE()+ mapping = framework._mitre_attacks_by_category()+ assert set(mapping.keys()) == {+ "reconnaissance",+ "resource_development",+ "initial_access",+ "ml_attack_staging",+ "exfiltration",+ "impact",+ }+ for alist in mapping.values():+ assert isinstance(alist, list)+ assert all(isinstance(a, BaseAttack) for a in alist)++ def test_mitre_vulnerability_names_present(self):+ """Test that key MITRE vulnerabilities are present."""+ framework = MITRE()+ vuln_names = [v.__class__.__name__ for v in framework.vulnerabilities]+ expected_vulns = [+ "IllegalActivity",+ "PromptLeakage",+ "PIILeakage",+ "ExcessiveAgency",+ "IntellectualProperty",+ "Competition",+ "GraphicContent",+ "RBAC",+ "SSRF",+ "DebugAccess",+ "ShellInjection",+ "SQLInjection",+ "CustomVulnerability",+ "RecursiveHijacking",+ ]+ for name in expected_vulns:+ assert name in vuln_names, f"Expected vulnerability {name} not found"++ def test_mitre_attack_names_present(self):+ """Test that key MITRE attacks are present."""+ framework = MITRE()+ attack_names = [a.__class__.__name__ for a in framework.attacks]+ expected_attacks = [+ "Roleplay",+ "PromptInjection",+ "LinearJailbreaking",+ "TreeJailbreaking",+ "SequentialJailbreak",+ "CrescendoJailbreaking",+ "Leetspeak",+ "ROT13",+ "PromptProbing",+ ]+ for name in expected_attacks:+ assert name in attack_names, f"Expected attack {name} not found"++ def test_partial_category_reduces_scope(self):+ """Test that selecting fewer categories reduces vulnerabilities and attacks."""+ full = MITRE()+ partial = MITRE(categories=["impact"])+ assert len(partial.vulnerabilities) < len(full.vulnerabilities)+ assert len(partial.attacks) < len(full.attacks)++ def test_mitre_attack_weights_valid(self):+ """Test that all attacks have valid weights."""+ framework = MITRE()+ for attack in framework.attacks:+ assert hasattr(attack, "weight")+ assert isinstance(attack.weight, int)+ assert 1 <= attack.weight <= 3++ def test_mitre_framework_with_red_team(self):+ import random++ """Test MITRE ATLAS integration with red_team pipeline."""+ def mock_model_callback(prompt: str, turns=None) -> str:+ return "This request violates internal policy."++ categories = [+ "reconnaissance",+ "resource_development",+ "initial_access",+ "ml_attack_staging",+ "exfiltration",+ "impact",+ ]+ random_category = random.choice(categories)+ risk_assessment = red_team(+ model_callback=mock_model_callback,+ framework=MITRE(categories=[random_category]),+ async_mode=False,+ ignore_errors=True,+ )+ assert risk_assessment is not Nonediff --git a/tests/test_core/test_frameworks/test_nist.py b/tests/test_core/test_frameworks/test_nist.pynew file mode 100644index 00000000..2537c499--- /dev/null+++ b/tests/test_core/test_frameworks/test_nist.py@@ -0,0 +1,184 @@+import pytest+from deepteam.frameworks import NIST+from deepteam.vulnerabilities import BaseVulnerability+from deepteam.attacks import BaseAttack+from deepteam import red_team++class TestNIST:++ def test_nist_init(self):+ """Test that NIST framework can be instantiated."""+ framework = NIST()+ assert framework is not None++ def test_nist_name(self):+ """Test that NIST framework has correct name."""+ framework = NIST()+ assert framework.name == framework.get_name() == "NIST AI RMF"++ def test_nist_description(self):+ """Test that NIST framework has correct description."""+ framework = NIST()+ assert framework.description == "NIST AI Risk Management Framework (AI RMF) — Measure-focused mapping for testing and evaluation."++ def test_nist_default_categories(self):+ """Test that all four measure categories are included by default."""+ framework = NIST()+ assert set(framework.categories) == {+ "measure_1",+ "measure_2",+ "measure_3",+ "measure_4",+ }++ def test_nist_partial_categories(self):+ """Test that framework can be created with limited categories."""+ framework = NIST(categories=["measure_1", "measure_2"])+ assert set(framework.categories) == {"measure_1", "measure_2"}++ def test_nist_vulnerabilities_exist(self):+ """Test that vulnerabilities are defined and populated."""+ framework = NIST()+ assert hasattr(framework, "vulnerabilities")+ assert framework.vulnerabilities is not None+ assert len(framework.vulnerabilities) > 0++ def test_nist_vulnerabilities_are_instances(self):+ """Test that all vulnerabilities are instances of BaseVulnerability."""+ framework = NIST()+ for vuln in framework.vulnerabilities:+ assert isinstance(vuln, BaseVulnerability)++ def test_nist_attacks_exist(self):+ """Test that attacks are defined and populated."""+ framework = NIST()+ assert hasattr(framework, "attacks")+ assert framework.attacks is not None+ assert len(framework.attacks) > 0++ def test_nist_attacks_are_instances(self):+ """Test that all attacks are instances of BaseAttack."""+ framework = NIST()+ for attack in framework.attacks:+ assert isinstance(attack, BaseAttack)++ def test_nist_vulnerability_types_present(self):+ """Test that key vulnerabilities are present."""+ framework = NIST()+ vuln_names = [v.__class__.__name__ for v in framework.vulnerabilities]+ expected_vulns = [+ "IntellectualProperty",+ "RBAC",+ "Bias",+ "Fairness",+ "Ethics",+ "Toxicity",+ "Misinformation",+ "PIILeakage",+ "PromptLeakage",+ "IllegalActivity",+ "Robustness",+ "ExcessiveAgency",+ "ShellInjection",+ "SQLInjection",+ "SSRF",+ "GraphicContent",+ "PersonalSafety",+ "ChildProtection",+ "BOLA",+ "BFLA",+ "Competition",+ ]+ for name in expected_vulns:+ assert name in vuln_names, f"Missing vulnerability {name}"++ def test_nist_attack_types_present(self):+ """Test that key attacks are included."""+ framework = NIST()+ attack_names = [a.__class__.__name__ for a in framework.attacks]+ expected_attacks = [+ "PromptInjection",+ "PromptProbing",+ "Base64",+ "ROT13",+ "Leetspeak",+ "Multilingual",+ "GrayBox",+ "Roleplay",+ "CrescendoJailbreaking",+ "LinearJailbreaking",+ "TreeJailbreaking",+ "SequentialJailbreak",+ "BadLikertJudge",+ ]+ for attack in expected_attacks:+ assert attack in attack_names, f"Expected attack {attack} not found"++ def test_nist_attack_weights_defined(self):+ """Test that all attacks have a valid weight."""+ framework = NIST()+ for attack in framework.attacks:+ assert hasattr(attack, "weight")+ assert isinstance(attack.weight, int)+ assert attack.weight >= 1++ def test_nist_category_vulnerability_mapping(self):+ """Test that all categories map to vulnerabilities properly."""+ framework = NIST()+ mapping = framework._nist_vulnerabilities_by_measure()+ assert set(mapping.keys()) == {+ "measure_1",+ "measure_2",+ "measure_3",+ "measure_4",+ }+ for vlist in mapping.values():+ assert isinstance(vlist, list)+ assert all(isinstance(v, BaseVulnerability) for v in vlist)++ def test_nist_category_attack_mapping(self):+ """Test that all categories map to attacks properly."""+ framework = NIST()+ mapping = framework._nist_attacks_by_measure()+ assert set(mapping.keys()) == {+ "measure_1",+ "measure_2",+ "measure_3",+ "measure_4",+ }+ for alist in mapping.values():+ assert isinstance(alist, list)+ assert all(isinstance(a, BaseAttack) for a in alist)++ def test_partial_category_reduces_vulnerabilities(self):+ """Test that selecting fewer categories reduces vulnerabilities."""+ all_vulns = len(NIST().vulnerabilities)+ partial_vulns = len(NIST(categories=["measure_1", "measure_2"]).vulnerabilities)+ assert partial_vulns < all_vulns++ def test_partial_category_reduces_attacks(self):+ """Test that selecting fewer categories reduces attacks."""+ all_attacks = len(NIST().attacks)+ partial_attacks = len(NIST(categories=["measure_1", "measure_2"]).attacks)+ assert partial_attacks < all_attacks++ def test_nist_framework_with_red_team(self):+ import random+ """Test that NIST framework integrates correctly with red_team function."""++ # Simple mock model for testing+ def mock_model_callback(prompt: str, turns=None) -> str:+ return "I'm a safe AI model. I cannot comply with unsafe instructions."++ categories = ["measure_1", "measure_2", "measure_3", "measure_4"]+ random_category = random.choice(categories) # Randomizing to not test on too many attacks or vulnerabilities++ risk_assessment = red_team(+ model_callback=mock_model_callback,+ framework=NIST(categories=[random_category]),+ async_mode=False,+ ignore_errors=True,+ )++ assert risk_assessment is not None+diff --git a/tests/test_core/test_frameworks/test_owasp_top_10.py b/tests/test_core/test_frameworks/test_owasp_top_10.pyindex 5598d411..168c4091 100644--- a/tests/test_core/test_frameworks/test_owasp_top_10.py+++ b/tests/test_core/test_frameworks/test_owasp_top_10.py@@ -4,7 +4,6 @@ from deepteam.vulnerabilities import BaseVulnerabilityfrom deepteam.attacks import BaseAttackfrom deepteam import red_team-class TestOWASPTop10:def test_owasp_top_10_init(self):