Skip to content

DeepTeam is a framework to red team LLMs and AI agents.

updated tests for vulnerabilities

A-Vamshi024324e091a5
diff --git a/tests/test_core/test_vulnerabilities/test_bfla.py b/tests/test_core/test_vulnerabilities/test_bfla.py
index c889f46d..d17ebb0c 100644
--- a/tests/test_core/test_vulnerabilities/test_bfla.py
+++ b/tests/test_core/test_vulnerabilities/test_bfla.py
@@ -2,6 +2,7 @@ import pytest
from deepteam.vulnerabilities import BFLA
from deepteam.vulnerabilities.bfla import BFLAType
+from deepteam.test_case import RTTestCase
class TestBFLA:
@@ -45,3 +46,54 @@ class TestBFLA:
]
with pytest.raises(ValueError):
BFLA(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ bfla = BFLA(types=["authorization_bypass"])
+ test_cases = bfla.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "BFLA" for tc in test_cases)
+ assert all(tc.vulnerability_type == BFLAType.AUTHORIZATION_BYPASS for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ bfla = BFLA(types=["authorization_bypass"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = bfla.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert BFLAType.AUTHORIZATION_BYPASS in results
+ assert len(results[BFLAType.AUTHORIZATION_BYPASS]) == 1
+ test_case = results[BFLAType.AUTHORIZATION_BYPASS][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_BFLA_metric(self):
+ from deepteam.metrics import BFLAMetric
+
+ bfla = BFLA(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = bfla._get_metric(BFLAType.AUTHORIZATION_BYPASS)
+ assert isinstance(metric, BFLAMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ bfla = BFLA(types=["authorization_bypass"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await bfla.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert BFLAType.AUTHORIZATION_BYPASS in results
+ assert len(results[BFLAType.AUTHORIZATION_BYPASS]) == 1
+ test_case = results[BFLAType.AUTHORIZATION_BYPASS][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
\ No newline at end of file
diff --git a/tests/test_core/test_vulnerabilities/test_bias.py b/tests/test_core/test_vulnerabilities/test_bias.py
index fe792d01..80d382e6 100644
--- a/tests/test_core/test_vulnerabilities/test_bias.py
+++ b/tests/test_core/test_vulnerabilities/test_bias.py
@@ -2,6 +2,7 @@ import pytest
from deepteam.vulnerabilities import Bias
from deepteam.vulnerabilities.bias import BiasType
+from deepteam.test_case import RTTestCase
class TestBias:
@@ -41,3 +42,54 @@ class TestBias:
types = ["gender", "politics", "religion", "race", "invalid"]
with pytest.raises(ValueError):
Bias(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ bias = Bias(types=["gender"])
+ test_cases = bias.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Bias" for tc in test_cases)
+ assert all(tc.vulnerability_type == BiasType.GENDER for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ bias = Bias(types=["politics"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = bias.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert BiasType.POLITICS in results
+ assert len(results[BiasType.POLITICS]) == 1
+ test_case = results[BiasType.POLITICS][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_bias_metric(self):
+ from deepteam.metrics import BiasMetric
+
+ bias = Bias(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = bias._get_metric(BiasType.RACE)
+ assert isinstance(metric, BiasMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ bias = Bias(types=["religion"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await bias.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert BiasType.RELIGION in results
+ assert len(results[BiasType.RELIGION]) == 1
+ test_case = results[BiasType.RELIGION][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_bola.py b/tests/test_core/test_vulnerabilities/test_bola.py
index 79929322..013da96a 100644
--- a/tests/test_core/test_vulnerabilities/test_bola.py
+++ b/tests/test_core/test_vulnerabilities/test_bola.py
@@ -2,6 +2,7 @@ import pytest
from deepteam.vulnerabilities import BOLA
from deepteam.vulnerabilities.bola import BOLAType
+from deepteam.test_case import RTTestCase
class TestBOLA:
@@ -45,3 +46,54 @@ class TestBOLA:
]
with pytest.raises(ValueError):
BOLA(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ bola = BOLA(types=["cross_customer_access"])
+ test_cases = bola.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "BOLA" for tc in test_cases)
+ assert all(tc.vulnerability_type == BOLAType.CROSS_CUSTOMER_ACCESS for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ bola = BOLA(types=["cross_customer_access"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = bola.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert BOLAType.CROSS_CUSTOMER_ACCESS in results
+ assert len(results[BOLAType.CROSS_CUSTOMER_ACCESS]) == 1
+ test_case = results[BOLAType.CROSS_CUSTOMER_ACCESS][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_BOLA_metric(self):
+ from deepteam.metrics import BOLAMetric
+
+ bola = BOLA(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = bola._get_metric(BOLAType.CROSS_CUSTOMER_ACCESS)
+ assert isinstance(metric, BOLAMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ bola = BOLA(types=["cross_customer_access"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await bola.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert BOLAType.CROSS_CUSTOMER_ACCESS in results
+ assert len(results[BOLAType.CROSS_CUSTOMER_ACCESS]) == 1
+ test_case = results[BOLAType.CROSS_CUSTOMER_ACCESS][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_competition.py b/tests/test_core/test_vulnerabilities/test_competition.py
index 741b2529..2fe815e2 100644
--- a/tests/test_core/test_vulnerabilities/test_competition.py
+++ b/tests/test_core/test_vulnerabilities/test_competition.py
@@ -2,16 +2,17 @@ import pytest
from deepteam.vulnerabilities import Competition
from deepteam.vulnerabilities.competition import CompetitionType
+from deepteam.test_case import RTTestCase
class TestCompetition:
def test_competition_all_types(self):
types = [
- "competitor mention",
- "market manipulation",
+ "competitor_mention",
+ "market_manipulation",
"discreditation",
- "confidential strategies",
+ "confidential_strategies",
]
competition = Competition(types=types)
assert sorted(type.value for type in competition.types) == sorted(types)
@@ -23,12 +24,12 @@ class TestCompetition:
)
def test_competition_competitor_mention(self):
- types = ["competitor mention"]
+ types = ["competitor_mention"]
competition = Competition(types=types)
assert sorted(type.value for type in competition.types) == sorted(types)
def test_competition_market_manipulation(self):
- types = ["market manipulation"]
+ types = ["market_manipulation"]
competition = Competition(types=types)
assert sorted(type.value for type in competition.types) == sorted(types)
@@ -38,17 +39,68 @@ class TestCompetition:
assert sorted(type.value for type in competition.types) == sorted(types)
def test_competition_confidential_strategies(self):
- types = ["confidential strategies"]
+ types = ["confidential_strategies"]
competition = Competition(types=types)
assert sorted(type.value for type in competition.types) == sorted(types)
def test_competition_all_types_invalid(self):
types = [
- "competitor mention",
- "market manipulation",
+ "competitor_mention",
+ "market_manipulation",
"discreditation",
- "confidential strategies",
+ "confidential_strategies",
"invalid",
]
with pytest.raises(ValueError):
Competition(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ competition = Competition(types=["competitor mention"])
+ test_cases = competition.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Competition" for tc in test_cases)
+ assert all(tc.vulnerability_type == CompetitionType.COMPETITOR_MENTION for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ competition = Competition(types=["competitor_mention"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = competition.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert CompetitionType.COMPETITOR_MENTION in results
+ assert len(results[CompetitionType.COMPETITOR_MENTION]) == 1
+ test_case = results[CompetitionType.COMPETITOR_MENTION][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_Competition_metric(self):
+ from deepteam.metrics import CompetitorsMetric
+
+ competition = Competition(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = competition._get_metric(CompetitionType.COMPETITOR_MENTION)
+ assert isinstance(metric, CompetitorsMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ competition = Competition(types=["competitor_mention"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await competition.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert CompetitionType.COMPETITOR_MENTION in results
+ assert len(results[CompetitionType.COMPETITOR_MENTION]) == 1
+ test_case = results[CompetitionType.COMPETITOR_MENTION][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_debug_access.py b/tests/test_core/test_vulnerabilities/test_debug_access.py
index 5b0300a5..15b036b3 100644
--- a/tests/test_core/test_vulnerabilities/test_debug_access.py
+++ b/tests/test_core/test_vulnerabilities/test_debug_access.py
@@ -2,6 +2,7 @@ import pytest
from deepteam.vulnerabilities import DebugAccess
from deepteam.vulnerabilities.debug_access import DebugAccessType
+from deepteam.test_case import RTTestCase
class TestDebugAccess:
@@ -53,3 +54,54 @@ class TestDebugAccess:
]
with pytest.raises(ValueError):
DebugAccess(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ debug_access = DebugAccess(types=["debug_mode_bypass"])
+ test_cases = debug_access.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Debug Access" for tc in test_cases)
+ assert all(tc.vulnerability_type == DebugAccessType.DEBUG_MODE_BYPASS for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ debug_access = DebugAccess(types=["debug_mode_bypass"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = debug_access.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert DebugAccessType.DEBUG_MODE_BYPASS in results
+ assert len(results[DebugAccessType.DEBUG_MODE_BYPASS]) == 1
+ test_case = results[DebugAccessType.DEBUG_MODE_BYPASS][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_DebugAccess_metric(self):
+ from deepteam.metrics import DebugAccessMetric
+
+ debug_access = DebugAccess(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = debug_access._get_metric(DebugAccessType.DEBUG_MODE_BYPASS)
+ assert isinstance(metric, DebugAccessMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ debug_access = DebugAccess(types=["debug_mode_bypass"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await debug_access.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert DebugAccessType.DEBUG_MODE_BYPASS in results
+ assert len(results[DebugAccessType.DEBUG_MODE_BYPASS]) == 1
+ test_case = results[DebugAccessType.DEBUG_MODE_BYPASS][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
\ No newline at end of file
diff --git a/tests/test_core/test_vulnerabilities/test_excessive_agency.py b/tests/test_core/test_vulnerabilities/test_excessive_agency.py
index 1131af0f..1587125f 100644
--- a/tests/test_core/test_vulnerabilities/test_excessive_agency.py
+++ b/tests/test_core/test_vulnerabilities/test_excessive_agency.py
@@ -4,6 +4,7 @@ from deepteam.vulnerabilities import ExcessiveAgency
from deepteam.vulnerabilities.agentic.excessive_agency import (
ExcessiveAgencyType,
)
+from deepteam.test_case import RTTestCase
class TestExcessiveAgency:
@@ -46,3 +47,54 @@ class TestExcessiveAgency:
types = ["functionality", "permissions", "autonomy", "invalid"]
with pytest.raises(ValueError):
ExcessiveAgency(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ excessive_agency = ExcessiveAgency(types=["autonomy"])
+ test_cases = excessive_agency.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Excessive Agency" for tc in test_cases)
+ assert all(tc.vulnerability_type == ExcessiveAgencyType.AUTONOMY for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ excessive_agency = ExcessiveAgency(types=["autonomy"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = excessive_agency.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert ExcessiveAgencyType.AUTONOMY in results
+ assert len(results[ExcessiveAgencyType.AUTONOMY]) == 1
+ test_case = results[ExcessiveAgencyType.AUTONOMY][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_ExcessiveAgency_metric(self):
+ from deepteam.metrics import ExcessiveAgencyMetric
+
+ excessive_agency = ExcessiveAgency(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = excessive_agency._get_metric(ExcessiveAgencyType.AUTONOMY)
+ assert isinstance(metric, ExcessiveAgencyMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ excessive_agency = ExcessiveAgency(types=["autonomy"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await excessive_agency.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert ExcessiveAgencyType.AUTONOMY in results
+ assert len(results[ExcessiveAgencyType.AUTONOMY]) == 1
+ test_case = results[ExcessiveAgencyType.AUTONOMY][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_goal_theft.py b/tests/test_core/test_vulnerabilities/test_goal_theft.py
index 0b4d09b4..6ef130ed 100644
--- a/tests/test_core/test_vulnerabilities/test_goal_theft.py
+++ b/tests/test_core/test_vulnerabilities/test_goal_theft.py
@@ -2,6 +2,7 @@ import pytest
from deepteam.vulnerabilities import GoalTheft
from deepteam.vulnerabilities.agentic.goal_theft import GoalTheftType
+from deepteam.test_case import RTTestCase
class TestGoalTheft:
@@ -45,3 +46,54 @@ class TestGoalTheft:
]
with pytest.raises(ValueError):
GoalTheft(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ goal_theft = GoalTheft(types=["cooperative_dialogue"])
+ test_cases = goal_theft.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Goal Theft" for tc in test_cases)
+ assert all(tc.vulnerability_type == GoalTheftType.COOPERATIVE_DIALOGUE for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ goal_theft = GoalTheft(types=["cooperative_dialogue"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = goal_theft.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert GoalTheftType.COOPERATIVE_DIALOGUE in results
+ assert len(results[GoalTheftType.COOPERATIVE_DIALOGUE]) == 1
+ test_case = results[GoalTheftType.COOPERATIVE_DIALOGUE][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_GoalTheft_metric(self):
+ from deepteam.metrics.agentic import ExtractionSuccessMetric
+
+ goal_theft = GoalTheft(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = goal_theft._get_metric(GoalTheftType.COOPERATIVE_DIALOGUE)
+ assert isinstance(metric, ExtractionSuccessMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ goal_theft = GoalTheft(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await goal_theft.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert GoalTheftType.COOPERATIVE_DIALOGUE in results
+ assert len(results[GoalTheftType.COOPERATIVE_DIALOGUE]) == 1
+ test_case = results[GoalTheftType.COOPERATIVE_DIALOGUE][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_graphic_content.py b/tests/test_core/test_vulnerabilities/test_graphic_content.py
index 16250ed1..615f82ad 100644
--- a/tests/test_core/test_vulnerabilities/test_graphic_content.py
+++ b/tests/test_core/test_vulnerabilities/test_graphic_content.py
@@ -2,12 +2,13 @@ import pytest
from deepteam.vulnerabilities import GraphicContent
from deepteam.vulnerabilities.graphic_content import GraphicContentType
+from deepteam.test_case import RTTestCase
class TestGraphicContent:
def test_graphic_content_all_types(self):
- types = ["sexual content", "graphic content", "pornographic content"]
+ types = ["sexual_content", "graphic_content", "pornographic_content"]
graphic_content = GraphicContent(types=types)
assert sorted(type.value for type in graphic_content.types) == sorted(
types
@@ -20,21 +21,21 @@ class TestGraphicContent:
)
def test_graphic_content_sexual_content(self):
- types = ["sexual content"]
+ types = ["sexual_content"]
graphic_content = GraphicContent(types=types)
assert sorted(type.value for type in graphic_content.types) == sorted(
types
)
def test_graphic_content_graphic_content(self):
- types = ["graphic content"]
+ types = ["graphic_content"]
graphic_content = GraphicContent(types=types)
assert sorted(type.value for type in graphic_content.types) == sorted(
types
)
def test_graphic_content_pornographic_content(self):
- types = ["pornographic content"]
+ types = ["pornographic_content"]
graphic_content = GraphicContent(types=types)
assert sorted(type.value for type in graphic_content.types) == sorted(
types
@@ -42,10 +43,62 @@ class TestGraphicContent:
def test_graphic_content_all_types_invalid(self):
types = [
- "sexual content",
- "graphic content",
- "pornographic content",
+ "sexual_content",
+ "graphic_content",
+ "pornographic_content",
"invalid",
]
with pytest.raises(ValueError):
GraphicContent(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ graphic_content = GraphicContent(types=["graphic_content"])
+ test_cases = graphic_content.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Graphic Content" for tc in test_cases)
+ assert all(tc.vulnerability_type == GraphicContentType.GRAPHIC_CONTENT for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ graphic_content = GraphicContent(types=["graphic_content"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = graphic_content.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert GraphicContentType.GRAPHIC_CONTENT in results
+ assert len(results[GraphicContentType.GRAPHIC_CONTENT]) == 1
+ test_case = results[GraphicContentType.GRAPHIC_CONTENT][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_GraphicContent_metric(self):
+ from deepteam.metrics import GraphicMetric
+
+ graphic_content = GraphicContent(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = graphic_content._get_metric(GraphicContentType.GRAPHIC_CONTENT)
+ assert isinstance(metric, GraphicMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ graphic_content = GraphicContent(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await graphic_content.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert GraphicContentType.GRAPHIC_CONTENT in results
+ assert len(results[GraphicContentType.GRAPHIC_CONTENT]) == 1
+ test_case = results[GraphicContentType.GRAPHIC_CONTENT][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
diff --git a/tests/test_core/test_vulnerabilities/test_illegal_activity.py b/tests/test_core/test_vulnerabilities/test_illegal_activity.py
index 1ce14eb1..34961fea 100644
--- a/tests/test_core/test_vulnerabilities/test_illegal_activity.py
+++ b/tests/test_core/test_vulnerabilities/test_illegal_activity.py
@@ -2,19 +2,19 @@ import pytest
from deepteam.vulnerabilities import IllegalActivity
from deepteam.vulnerabilities.illegal_activity import IllegalActivityType
-
+from deepteam.test_case import RTTestCase
class TestIllegalActivity:
def test_illegal_activity_all_types(self):
types = [
"weapons",
- "illegal drugs",
- "violent crimes",
- "non violent crimes",
- "sex crimes",
+ "illegal_drugs",
+ "violent_crimes",
+ "non_violent_crimes",
+ "sex_crimes",
"cybercrime",
- "child exploitation",
+ "child_exploitation",
]
illegal_activity = IllegalActivity(types=types)
assert sorted(type.value for type in illegal_activity.types) == sorted(
@@ -35,28 +35,28 @@ class TestIllegalActivity:
)
def test_illegal_activity_illegal_drugs(self):
- types = ["illegal drugs"]
+ types = ["illegal_drugs"]
illegal_activity = IllegalActivity(types=types)
assert sorted(type.value for type in illegal_activity.types) == sorted(
types
)
def test_illegal_activity_violent_crimes(self):
- types = ["violent crimes"]
+ types = ["violent_crimes"]
illegal_activity = IllegalActivity(types=types)
assert sorted(type.value for type in illegal_activity.types) == sorted(
types
)
def test_illegal_activity_non_violent_crimes(self):
- types = ["non violent crimes"]
+ types = ["non_violent_crimes"]
illegal_activity = IllegalActivity(types=types)
assert sorted(type.value for type in illegal_activity.types) == sorted(
types
)
def test_illegal_activity_sex_crimes(self):
- types = ["sex crimes"]
+ types = ["sex_crimes"]
illegal_activity = IllegalActivity(types=types)
assert sorted(type.value for type in illegal_activity.types) == sorted(
types
@@ -70,7 +70,7 @@ class TestIllegalActivity:
)
def test_illegal_activity_child_exploitation(self):
- types = ["child exploitation"]
+ types = ["child_exploitation"]
illegal_activity = IllegalActivity(types=types)
assert sorted(type.value for type in illegal_activity.types) == sorted(
types
@@ -79,13 +79,64 @@ class TestIllegalActivity:
def test_illegal_activity_all_types_invalid(self):
types = [
"weapons",
- "illegal drugs",
- "violent crimes",
- "non violent crimes",
- "sex crimes",
+ "illegal_drugs",
+ "violent_crimes",
+ "non_violent_crimes",
+ "sex_crimes",
"cybercrime",
- "child exploitation",
+ "child_exploitation",
"invalid",
]
with pytest.raises(ValueError):
IllegalActivity(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ illegal = IllegalActivity(types=["weapons"])
+ test_cases = illegal.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Illegal Activity" for tc in test_cases)
+ assert all(tc.vulnerability_type == IllegalActivityType.WEAPONS for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ illegal = IllegalActivity(types=["weapons"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = illegal.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert IllegalActivityType.WEAPONS in results
+ assert len(results[IllegalActivityType.WEAPONS]) == 1
+ test_case = results[IllegalActivityType.WEAPONS][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_IllegalActivity_metric(self):
+ from deepteam.metrics import IllegalMetric
+
+ illegal = IllegalActivity(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = illegal._get_metric(IllegalActivityType.WEAPONS)
+ assert isinstance(metric, IllegalMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ illegal = IllegalActivity(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await illegal.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert IllegalActivityType.WEAPONS in results
+ assert len(results[IllegalActivityType.WEAPONS]) == 1
+ test_case = results[IllegalActivityType.WEAPONS][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_intellectual_property.py b/tests/test_core/test_vulnerabilities/test_intellectual_property.py
index 2c259817..a0511f4b 100644
--- a/tests/test_core/test_vulnerabilities/test_intellectual_property.py
+++ b/tests/test_core/test_vulnerabilities/test_intellectual_property.py
@@ -4,6 +4,7 @@ from deepteam.vulnerabilities import IntellectualProperty
from deepteam.vulnerabilities.intellectual_property import (
IntellectualPropertyType,
)
+from deepteam.test_case import RTTestCase
class TestIntellectualProperty:
@@ -11,9 +12,9 @@ class TestIntellectualProperty:
def test_intellectual_property_all_types(self):
types = [
"imitation",
- "copyright violations",
- "trademark infringement",
- "patent disclosure",
+ "copyright_violations",
+ "trademark_infringement",
+ "patent_disclosure",
]
intellectual_property = IntellectualProperty(types=types)
assert sorted(
@@ -34,21 +35,21 @@ class TestIntellectualProperty:
) == sorted(types)
def test_intellectual_property_copyright_violations(self):
- types = ["copyright violations"]
+ types = ["copyright_violations"]
intellectual_property = IntellectualProperty(types=types)
assert sorted(
type.value for type in intellectual_property.types
) == sorted(types)
def test_intellectual_property_trademark_infringement(self):
- types = ["trademark infringement"]
+ types = ["trademark_infringement"]
intellectual_property = IntellectualProperty(types=types)
assert sorted(
type.value for type in intellectual_property.types
) == sorted(types)
def test_intellectual_property_patent_disclosure(self):
- types = ["patent disclosure"]
+ types = ["patent_disclosure"]
intellectual_property = IntellectualProperty(types=types)
assert sorted(
type.value for type in intellectual_property.types
@@ -57,10 +58,61 @@ class TestIntellectualProperty:
def test_intellectual_property_all_types_invalid(self):
types = [
"imitation",
- "copyright violations",
- "trademark infringement",
- "patent disclosure",
+ "copyright_violations",
+ "trademark_infringement",
+ "patent_disclosure",
"invalid",
]
with pytest.raises(ValueError):
IntellectualProperty(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ intellectual = IntellectualProperty(types=["imitation"])
+ test_cases = intellectual.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Intellectual Property" for tc in test_cases)
+ assert all(tc.vulnerability_type == IntellectualPropertyType.IMITATION for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ intellectual = IntellectualProperty(types=["imitation"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = intellectual.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert IntellectualPropertyType.IMITATION in results
+ assert len(results[IntellectualPropertyType.IMITATION]) == 1
+ test_case = results[IntellectualPropertyType.IMITATION][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_IntellectualProperty_metric(self):
+ from deepteam.metrics import IntellectualPropertyMetric
+
+ intellectual = IntellectualProperty(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = intellectual._get_metric(IntellectualPropertyType.IMITATION)
+ assert isinstance(metric, IntellectualPropertyMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ intellectual = IntellectualProperty(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await intellectual.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert IntellectualPropertyType.IMITATION in results
+ assert len(results[IntellectualPropertyType.IMITATION]) == 1
+ test_case = results[IntellectualPropertyType.IMITATION][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
\ No newline at end of file
diff --git a/tests/test_core/test_vulnerabilities/test_misinformation.py b/tests/test_core/test_vulnerabilities/test_misinformation.py
index ca68350b..3dcbfea7 100644
--- a/tests/test_core/test_vulnerabilities/test_misinformation.py
+++ b/tests/test_core/test_vulnerabilities/test_misinformation.py
@@ -2,15 +2,16 @@ import pytest
from deepteam.vulnerabilities import Misinformation
from deepteam.vulnerabilities.misinformation import MisinformationType
+from deepteam.test_case import RTTestCase
class TestMisinformation:
def test_misinformation_all_types(self):
types = [
- "factual errors",
- "unsupported claims",
- "expertize misrepresentation",
+ "factual_errors",
+ "unsupported_claims",
+ "expertize_misrepresentation",
]
misinformation = Misinformation(
types=types,
@@ -26,7 +27,7 @@ class TestMisinformation:
)
def test_misinformation_factual_errors(self):
- types = ["factual errors"]
+ types = ["factual_errors"]
misinformation = Misinformation(
types=types,
)
@@ -35,7 +36,7 @@ class TestMisinformation:
)
def test_misinformation_unsupported_claims(self):
- types = ["unsupported claims"]
+ types = ["unsupported_claims"]
misinformation = Misinformation(
types=types,
)
@@ -44,7 +45,7 @@ class TestMisinformation:
)
def test_misinformation_expertize_misrepresentation(self):
- types = ["expertize misrepresentation"]
+ types = ["expertize_misrepresentation"]
misinformation = Misinformation(
types=types,
)
@@ -54,12 +55,63 @@ class TestMisinformation:
def test_misinformation_all_types_invalid(self):
types = [
- "factual errors",
- "unsupported claims",
- "expertize misrepresentation",
+ "factual_errors",
+ "unsupported_claims",
+ "expertize_misrepresentation",
"invalid",
]
with pytest.raises(ValueError):
Misinformation(
types=types,
)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ misinformation = Misinformation(types=["factual_errors"])
+ test_cases = misinformation.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Misinformation" for tc in test_cases)
+ assert all(tc.vulnerability_type == MisinformationType.FACTUAL_ERRORS for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ misinformation = Misinformation(types=["factual_errors"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = misinformation.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert MisinformationType.FACTUAL_ERRORS in results
+ assert len(results[MisinformationType.FACTUAL_ERRORS]) == 1
+ test_case = results[MisinformationType.FACTUAL_ERRORS][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_Misinformation_metric(self):
+ from deepteam.metrics.agentic import MisinterpretationMetric
+
+ misinformation = Misinformation(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = misinformation._get_metric(MisinformationType.FACTUAL_ERRORS)
+ assert isinstance(metric, MisinterpretationMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ misinformation = Misinformation(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await misinformation.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert MisinformationType.FACTUAL_ERRORS in results
+ assert len(results[MisinformationType.FACTUAL_ERRORS]) == 1
+ test_case = results[MisinformationType.FACTUAL_ERRORS][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_personal_safety.py b/tests/test_core/test_vulnerabilities/test_personal_safety.py
index 6cec5652..1105d351 100644
--- a/tests/test_core/test_vulnerabilities/test_personal_safety.py
+++ b/tests/test_core/test_vulnerabilities/test_personal_safety.py
@@ -2,6 +2,7 @@ import pytest
from deepteam.vulnerabilities import PersonalSafety
from deepteam.vulnerabilities.personal_safety import PersonalSafetyType
+from deepteam.test_case import RTTestCase
class TestPersonalSafety:
@@ -9,9 +10,9 @@ class TestPersonalSafety:
def test_personal_safety_all_types(self):
types = [
"bullying",
- "self-harm",
- "unsafe practices",
- "dangerous challenges",
+ "self_harm",
+ "unsafe_practices",
+ "dangerous_challenges",
"stalking",
]
personal_safety = PersonalSafety(types=types)
@@ -33,21 +34,21 @@ class TestPersonalSafety:
)
def test_personal_safety_self_harm(self):
- types = ["self-harm"]
+ types = ["self_harm"]
personal_safety = PersonalSafety(types=types)
assert sorted(type.value for type in personal_safety.types) == sorted(
types
)
def test_personal_safety_unsafe_practices(self):
- types = ["unsafe practices"]
+ types = ["unsafe_practices"]
personal_safety = PersonalSafety(types=types)
assert sorted(type.value for type in personal_safety.types) == sorted(
types
)
def test_personal_safety_dangerous_challenges(self):
- types = ["dangerous challenges"]
+ types = ["dangerous_challenges"]
personal_safety = PersonalSafety(types=types)
assert sorted(type.value for type in personal_safety.types) == sorted(
types
@@ -63,11 +64,62 @@ class TestPersonalSafety:
def test_personal_safety_all_types_invalid(self):
types = [
"bullying",
- "self-harm",
- "unsafe practices",
- "dangerous challenges",
+ "self_harm",
+ "unsafe_practices",
+ "dangerous_challenges",
"stalking",
"invalid",
]
with pytest.raises(ValueError):
PersonalSafety(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ safety = PersonalSafety(types=["bullying"])
+ test_cases = safety.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Personal Safety" for tc in test_cases)
+ assert all(tc.vulnerability_type == PersonalSafetyType.BULLYING for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ safety = PersonalSafety(types=["bullying"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = safety.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert PersonalSafetyType.BULLYING in results
+ assert len(results[PersonalSafetyType.BULLYING]) == 1
+ test_case = results[PersonalSafetyType.BULLYING][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_PersonalSafety_metric(self):
+ from deepteam.metrics import SafetyMetric
+
+ safety = PersonalSafety(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = safety._get_metric(PersonalSafetyType.BULLYING)
+ assert isinstance(metric, SafetyMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ safety = PersonalSafety(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await safety.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert PersonalSafetyType.BULLYING in results
+ assert len(results[PersonalSafetyType.BULLYING]) == 1
+ test_case = results[PersonalSafetyType.BULLYING][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_pii_leakage.py b/tests/test_core/test_vulnerabilities/test_pii_leakage.py
index dc1b6c49..78dae15b 100644
--- a/tests/test_core/test_vulnerabilities/test_pii_leakage.py
+++ b/tests/test_core/test_vulnerabilities/test_pii_leakage.py
@@ -2,16 +2,17 @@ import pytest
from deepteam.vulnerabilities import PIILeakage
from deepteam.vulnerabilities.pii_leakage import PIILeakageType
+from deepteam.test_case import RTTestCase
class TestPIILeakage:
def test_pii_leakage_all_types(self):
types = [
- "api and database access",
- "direct disclosure",
- "session leak",
- "social manipulation",
+ "api_and_database_access",
+ "direct_disclosure",
+ "session_leak",
+ "social_manipulation",
]
pii_leakage = PIILeakage(types=types)
assert sorted(type.value for type in pii_leakage.types) == sorted(types)
@@ -23,32 +24,83 @@ class TestPIILeakage:
)
def test_pii_leakage_database_access(self):
- types = ["api and database access"]
+ types = ["api_and_database_access"]
pii_leakage = PIILeakage(types=types)
assert sorted(type.value for type in pii_leakage.types) == sorted(types)
def test_pii_leakage_direct_disclosure(self):
- types = ["direct disclosure"]
+ types = ["direct_disclosure"]
pii_leakage = PIILeakage(types=types)
assert sorted(type.value for type in pii_leakage.types) == sorted(types)
def test_pii_leakage_session_leak(self):
- types = ["session leak"]
+ types = ["session_leak"]
pii_leakage = PIILeakage(types=types)
assert sorted(type.value for type in pii_leakage.types) == sorted(types)
def test_pii_leakage_social_manipulation(self):
- types = ["social manipulation"]
+ types = ["social_manipulation"]
pii_leakage = PIILeakage(types=types)
assert sorted(type.value for type in pii_leakage.types) == sorted(types)
def test_pii_leakage_all_types_invalid(self):
types = [
- "api and database access",
- "direct disclosure",
- "session leak",
- "social manipulation",
+ "api_and_database_access",
+ "direct_disclosure",
+ "session_leak",
+ "social_manipulation",
"invalid",
]
with pytest.raises(ValueError):
PIILeakage(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ pii_lekage = PIILeakage(types=["session_leak"])
+ test_cases = pii_lekage.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "PII Lekage" for tc in test_cases)
+ assert all(tc.vulnerability_type == PIILeakageType.SESSION_LEAK for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ pii_lekage = PIILeakage(types=["session_leak"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = pii_lekage.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert PIILeakageType.SESSION_LEAK in results
+ assert len(results[PIILeakageType.SESSION_LEAK]) == 1
+ test_case = results[PIILeakageType.SESSION_LEAK][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_PIILeakage_metric(self):
+ from deepteam.metrics import PIIMetric
+
+ pii_lekage = PIILeakage(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = pii_lekage._get_metric(PIILeakageType.SESSION_LEAK)
+ assert isinstance(metric, PIIMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ pii_lekage = PIILeakage(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await pii_lekage.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert PIILeakageType.SESSION_LEAK in results
+ assert len(results[PIILeakageType.SESSION_LEAK]) == 1
+ test_case = results[PIILeakageType.SESSION_LEAK][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_prompt_leakage.py b/tests/test_core/test_vulnerabilities/test_prompt_leakage.py
index 0ee7ab5d..7e127038 100644
--- a/tests/test_core/test_vulnerabilities/test_prompt_leakage.py
+++ b/tests/test_core/test_vulnerabilities/test_prompt_leakage.py
@@ -2,16 +2,17 @@ import pytest
from deepteam.vulnerabilities import PromptLeakage
from deepteam.vulnerabilities.prompt_leakage import PromptLeakageType
+from deepteam.test_case import RTTestCase
class TestPromptLeakage:
def test_prompt_leakage_all_types(self):
types = [
- "secrets and credentials",
+ "secrets_and_credentials",
"instructions",
- "guard exposure",
- "permissions and roles",
+ "guard_exposure",
+ "permissions_and_roles",
]
prompt_leakage = PromptLeakage(types=types)
assert sorted(type.value for type in prompt_leakage.types) == sorted(
@@ -25,7 +26,7 @@ class TestPromptLeakage:
)
def test_prompt_leakage_secrets_and_credentials(self):
- types = ["secrets and credentials"]
+ types = ["secrets_and_credentials"]
prompt_leakage = PromptLeakage(types=types)
assert sorted(type.value for type in prompt_leakage.types) == sorted(
types
@@ -39,14 +40,14 @@ class TestPromptLeakage:
)
def test_prompt_leakage_guard_exposure(self):
- types = ["guard exposure"]
+ types = ["guard_exposure"]
prompt_leakage = PromptLeakage(types=types)
assert sorted(type.value for type in prompt_leakage.types) == sorted(
types
)
def test_prompt_leakage_permissions_and_roles(self):
- types = ["permissions and roles"]
+ types = ["permissions_and_roles"]
prompt_leakage = PromptLeakage(types=types)
assert sorted(type.value for type in prompt_leakage.types) == sorted(
types
@@ -54,11 +55,63 @@ class TestPromptLeakage:
def test_prompt_leakage_all_types_invalid(self):
types = [
- "secrets and credentials",
+ "secrets_and_credentials",
"instructions",
- "guard exposure",
- "permissions and roles",
+ "guard_exposure",
+ "permissions_and _oles",
"invalid",
]
with pytest.raises(ValueError):
PromptLeakage(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ prompt_lekage = PromptLeakage(types=["secrets_and_credentials"])
+ test_cases = prompt_lekage.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Prompt Lekage" for tc in test_cases)
+ assert all(tc.vulnerability_type == PromptLeakageType.SECRETS_AND_CREDENTIALS for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ prompt_lekage = PromptLeakage(types=["secrets_and_credentials"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = prompt_lekage.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert PromptLeakageType.SECRETS_AND_CREDENTIALS in results
+ assert len(results[PromptLeakageType.SECRETS_AND_CREDENTIALS]) == 1
+ test_case = results[PromptLeakageType.SECRETS_AND_CREDENTIALS][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_PromptLeakage_metric(self):
+ from deepteam.metrics import PromptExtractionMetric
+
+ prompt_lekage = PromptLeakage(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = prompt_lekage._get_metric(PromptLeakageType.SECRETS_AND_CREDENTIALS)
+ assert isinstance(metric, PromptExtractionMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ prompt_lekage = PromptLeakage(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await prompt_lekage.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert PromptLeakageType.SECRETS_AND_CREDENTIALS in results
+ assert len(results[PromptLeakageType.SECRETS_AND_CREDENTIALS]) == 1
+ test_case = results[PromptLeakageType.SECRETS_AND_CREDENTIALS][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
diff --git a/tests/test_core/test_vulnerabilities/test_rbac.py b/tests/test_core/test_vulnerabilities/test_rbac.py
index 7e51a87e..153bd5f4 100644
--- a/tests/test_core/test_vulnerabilities/test_rbac.py
+++ b/tests/test_core/test_vulnerabilities/test_rbac.py
@@ -2,15 +2,16 @@ import pytest
from deepteam.vulnerabilities import RBAC
from deepteam.vulnerabilities.rbac import RBACType
+from deepteam.test_case import RTTestCase
class TestRBAC:
def test_rbac_all_types(self):
types = [
- "role bypass",
- "privilege escalation",
- "unauthorized role assumption",
+ "role_bypass",
+ "privilege_escalation",
+ "unauthorized_role_assumption",
]
rbac = RBAC(types=types)
assert sorted(type.value for type in rbac.types) == sorted(types)
@@ -22,26 +23,77 @@ class TestRBAC:
)
def test_rbac_role_bypass(self):
- types = ["role bypass"]
+ types = ["role_bypass"]
rbac = RBAC(types=types)
assert sorted(type.value for type in rbac.types) == sorted(types)
def test_rbac_privilege_escalation(self):
- types = ["privilege escalation"]
+ types = ["privilege_escalation"]
rbac = RBAC(types=types)
assert sorted(type.value for type in rbac.types) == sorted(types)
def test_rbac_unauthorized_role_assumption(self):
- types = ["unauthorized role assumption"]
+ types = ["unauthorized_role_assumption"]
rbac = RBAC(types=types)
assert sorted(type.value for type in rbac.types) == sorted(types)
def test_rbac_all_types_invalid(self):
types = [
- "role bypass",
- "privilege escalation",
- "unauthorized role assumption",
+ "role_bypass",
+ "privilege_escalation",
+ "unauthorized_role_assumption",
"invalid",
]
with pytest.raises(ValueError):
RBAC(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ rbac = RBAC(types=["role_bypass"])
+ test_cases = rbac.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "RBAC" for tc in test_cases)
+ assert all(tc.vulnerability_type == RBACType.ROLE_BYPASS for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ rbac = RBAC(types=["role_bypass"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = rbac.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert RBACType.ROLE_BYPASS in results
+ assert len(results[RBACType.ROLE_BYPASS]) == 1
+ test_case = results[RBACType.ROLE_BYPASS][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_RBAC_metric(self):
+ from deepteam.metrics import RBACMetric
+
+ rbac = RBAC(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = rbac._get_metric(RBACType.ROLE_BYPASS)
+ assert isinstance(metric, RBACMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ rbac = RBAC(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await rbac.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert RBACType.ROLE_BYPASS in results
+ assert len(results[RBACType.ROLE_BYPASS]) == 1
+ test_case = results[RBACType.ROLE_BYPASS][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_recursive_hijacking.py b/tests/test_core/test_vulnerabilities/test_recursive_hijacking.py
index a29017be..ade9b6d0 100644
--- a/tests/test_core/test_vulnerabilities/test_recursive_hijacking.py
+++ b/tests/test_core/test_vulnerabilities/test_recursive_hijacking.py
@@ -4,6 +4,7 @@ from deepteam.vulnerabilities import RecursiveHijacking
from deepteam.vulnerabilities.agentic.recursive_hijacking import (
RecursiveHijackingType,
)
+from deepteam.test_case import RTTestCase
class TestRecursiveHijacking:
@@ -55,3 +56,54 @@ class TestRecursiveHijacking:
]
with pytest.raises(ValueError):
RecursiveHijacking(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ recursive_hijack = RecursiveHijacking(types=["goal_propagation_attacks"])
+ test_cases = recursive_hijack.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Recursive Hijacking" for tc in test_cases)
+ assert all(tc.vulnerability_type == RecursiveHijackingType.GOAL_PROPAGATION_ATTACKS for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ recursive_hijack = RecursiveHijacking(types=["goal_propagation_attacks"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = recursive_hijack.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert RecursiveHijackingType.GOAL_PROPAGATION_ATTACKS in results
+ assert len(results[RecursiveHijackingType.GOAL_PROPAGATION_ATTACKS]) == 1
+ test_case = results[RecursiveHijackingType.GOAL_PROPAGATION_ATTACKS][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_RecursiveHijacking_metric(self):
+ from deepteam.metrics.agentic import SubversionSuccessMetric
+
+ recursive_hijack = RecursiveHijacking(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = recursive_hijack._get_metric(RecursiveHijackingType.GOAL_PROPAGATION_ATTACKS)
+ assert isinstance(metric, SubversionSuccessMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ recursive_hijack = RecursiveHijacking(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await recursive_hijack.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert RecursiveHijackingType.GOAL_PROPAGATION_ATTACKS in results
+ assert len(results[RecursiveHijackingType.GOAL_PROPAGATION_ATTACKS]) == 1
+ test_case = results[RecursiveHijackingType.GOAL_PROPAGATION_ATTACKS][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_robustness.py b/tests/test_core/test_vulnerabilities/test_robustness.py
index 70bf827d..58e0137b 100644
--- a/tests/test_core/test_vulnerabilities/test_robustness.py
+++ b/tests/test_core/test_vulnerabilities/test_robustness.py
@@ -2,12 +2,13 @@ import pytest
from deepteam.vulnerabilities import Robustness
from deepteam.vulnerabilities.agentic.robustness import RobustnessType
+from deepteam.test_case import RTTestCase
class TestRobustness:
def test_robustness_all_types(self):
- types = ["input overreliance", "hijacking"]
+ types = ["input_overreliance", "hijacking"]
robustness = Robustness(types=types)
assert sorted(type.value for type in robustness.types) == sorted(types)
@@ -18,7 +19,7 @@ class TestRobustness:
)
def test_robustness_input_overreliance(self):
- types = ["input overreliance"]
+ types = ["input_overreliance"]
robustness = Robustness(types=types)
assert sorted(type.value for type in robustness.types) == sorted(types)
@@ -28,6 +29,66 @@ class TestRobustness:
assert sorted(type.value for type in robustness.types) == sorted(types)
def test_robustness_all_types_invalid(self):
- types = ["input overreliance", "hijacking", "invalid"]
+ types = ["input_overreliance", "hijacking", "invalid"]
with pytest.raises(ValueError):
Robustness(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ robustness = Robustness(types=["hijacking"])
+ test_cases = robustness.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Robustness" for tc in test_cases)
+ assert all(tc.vulnerability_type == RobustnessType.HIJACKING for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ robustness = Robustness(types=["hijacking"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = robustness.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert RobustnessType.HIJACKING in results
+ assert len(results[RobustnessType.HIJACKING]) == 1
+ test_case = results[RobustnessType.HIJACKING][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_Robustness_overreliance_metric(self):
+ from deepteam.metrics import OverrelianceMetric
+
+ robustness = Robustness(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = robustness._get_metric(RobustnessType.INPUT_OVERRELIANCE)
+ assert isinstance(metric, OverrelianceMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ def test_get_metric_returns_Robustness_hijacking_metric(self):
+ from deepteam.metrics import HijackingMetric
+
+ robustness = Robustness(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = robustness._get_metric(RobustnessType.HIJACKING)
+ assert isinstance(metric, HijackingMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ robustness = Robustness(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await robustness.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert RobustnessType.HIJACKING in results
+ assert len(results[RobustnessType.HIJACKING]) == 1
+ test_case = results[RobustnessType.HIJACKING][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_shell_injection.py b/tests/test_core/test_vulnerabilities/test_shell_injection.py
index 1797cbed..402dc18a 100644
--- a/tests/test_core/test_vulnerabilities/test_shell_injection.py
+++ b/tests/test_core/test_vulnerabilities/test_shell_injection.py
@@ -2,6 +2,7 @@ import pytest
from deepteam.vulnerabilities import ShellInjection
from deepteam.vulnerabilities.shell_injection import ShellInjectionType
+from deepteam.test_case import RTTestCase
class TestShellInjection:
@@ -53,3 +54,54 @@ class TestShellInjection:
]
with pytest.raises(ValueError):
ShellInjection(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ shell_injection = ShellInjection(types=["command_injection"])
+ test_cases = shell_injection.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Shell Injection" for tc in test_cases)
+ assert all(tc.vulnerability_type == ShellInjectionType.COMMAND_INJECTION for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ shell_injection = ShellInjection(types=["command_injection"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = shell_injection.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert ShellInjectionType.COMMAND_INJECTION in results
+ assert len(results[ShellInjectionType.COMMAND_INJECTION]) == 1
+ test_case = results[ShellInjectionType.COMMAND_INJECTION][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_ShellInjection_metric(self):
+ from deepteam.metrics import ShellInjectionMetric
+
+ shell_injection = ShellInjection(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = shell_injection._get_metric(ShellInjectionType.COMMAND_INJECTION)
+ assert isinstance(metric, ShellInjectionMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ shell_injection = ShellInjection(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await shell_injection.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert ShellInjectionType.COMMAND_INJECTION in results
+ assert len(results[ShellInjectionType.COMMAND_INJECTION]) == 1
+ test_case = results[ShellInjectionType.COMMAND_INJECTION][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_sql_injection.py b/tests/test_core/test_vulnerabilities/test_sql_injection.py
index 37512c06..5e00c17a 100644
--- a/tests/test_core/test_vulnerabilities/test_sql_injection.py
+++ b/tests/test_core/test_vulnerabilities/test_sql_injection.py
@@ -2,6 +2,7 @@ import pytest
from deepteam.vulnerabilities import SQLInjection
from deepteam.vulnerabilities.sql_injection import SQLInjectionType
+from deepteam.test_case import RTTestCase
class TestSQLInjection:
@@ -53,3 +54,54 @@ class TestSQLInjection:
]
with pytest.raises(ValueError):
SQLInjection(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ sql_injection = SQLInjection(types=["blind_sql_injection"])
+ test_cases = sql_injection.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "SQL Injection" for tc in test_cases)
+ assert all(tc.vulnerability_type == SQLInjectionType.BLIND_SQL_INJECTION for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ sql_injection = SQLInjection(types=["blind_sql_injection"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = sql_injection.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert SQLInjectionType.BLIND_SQL_INJECTION in results
+ assert len(results[SQLInjectionType.BLIND_SQL_INJECTION]) == 1
+ test_case = results[SQLInjectionType.BLIND_SQL_INJECTION][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_SQLInjection_metric(self):
+ from deepteam.metrics import SQLInjectionMetric
+
+ sql_injection = SQLInjection(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = sql_injection._get_metric(SQLInjectionType.BLIND_SQL_INJECTION)
+ assert isinstance(metric, SQLInjectionMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ sql_injection = SQLInjection(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await sql_injection.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert SQLInjectionType.BLIND_SQL_INJECTION in results
+ assert len(results[SQLInjectionType.BLIND_SQL_INJECTION]) == 1
+ test_case = results[SQLInjectionType.BLIND_SQL_INJECTION][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_ssrf.py b/tests/test_core/test_vulnerabilities/test_ssrf.py
index d655fb8c..8b02af06 100644
--- a/tests/test_core/test_vulnerabilities/test_ssrf.py
+++ b/tests/test_core/test_vulnerabilities/test_ssrf.py
@@ -2,6 +2,7 @@ import pytest
from deepteam.vulnerabilities import SSRF
from deepteam.vulnerabilities.ssrf import SSRFType
+from deepteam.test_case import RTTestCase
class TestSSRF:
@@ -45,3 +46,54 @@ class TestSSRF:
]
with pytest.raises(ValueError):
SSRF(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ ssrf = SSRF(types=["cloud_metadata_access"])
+ test_cases = ssrf.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "SSRF" for tc in test_cases)
+ assert all(tc.vulnerability_type == SSRFType.CLOUD_METADATA_ACCESS for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ ssrf = SSRF(types=["cloud_metadata_access"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = ssrf.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert SSRFType.CLOUD_METADATA_ACCESS in results
+ assert len(results[SSRFType.CLOUD_METADATA_ACCESS]) == 1
+ test_case = results[SSRFType.CLOUD_METADATA_ACCESS][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_SSRF_metric(self):
+ from deepteam.metrics import SSRFMetric
+
+ ssrf = SSRF(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = ssrf._get_metric(SSRFType.CLOUD_METADATA_ACCESS)
+ assert isinstance(metric, SSRFMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ ssrf = SSRF(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await ssrf.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert SSRFType.CLOUD_METADATA_ACCESS in results
+ assert len(results[SSRFType.CLOUD_METADATA_ACCESS]) == 1
+ test_case = results[SSRFType.CLOUD_METADATA_ACCESS][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
diff --git a/tests/test_core/test_vulnerabilities/test_toxicity.py b/tests/test_core/test_vulnerabilities/test_toxicity.py
index 5fa9d482..7b256071 100644
--- a/tests/test_core/test_vulnerabilities/test_toxicity.py
+++ b/tests/test_core/test_vulnerabilities/test_toxicity.py
@@ -2,6 +2,7 @@ import pytest
from deepteam.vulnerabilities import Toxicity
from deepteam.vulnerabilities.toxicity import ToxicityType
+from deepteam.test_case import RTTestCase
class TestToxicity:
@@ -41,3 +42,54 @@ class TestToxicity:
types = ["profanity", "insults", "threats", "mockery", "invalid"]
with pytest.raises(ValueError):
Toxicity(types=types)
+
+ def test_simulate_attacks_returns_expected_cases(self):
+ toxicity = Toxicity(types=["insults"])
+ test_cases = toxicity.simulate_attacks(attacks_per_vulnerability_type=2)
+
+ assert len(test_cases) == 2
+ assert all(isinstance(tc, RTTestCase) for tc in test_cases)
+ assert all(tc.vulnerability == "Toxicity" for tc in test_cases)
+ assert all(tc.vulnerability_type == ToxicityType.INSULTS for tc in test_cases)
+
+ def test_assess_returns_results(self):
+ toxicity = Toxicity(types=["insults"], async_mode=False)
+
+ def dummy_model_callback(prompt):
+ # Provide a simple pass-through or minimal callback if required by your real env
+ return prompt
+
+ results = toxicity.assess(model_callback=dummy_model_callback, attacks_per_vulnerability_type=1)
+ assert ToxicityType.INSULTS in results
+ assert len(results[ToxicityType.INSULTS]) == 1
+ test_case = results[ToxicityType.INSULTS][0]
+ # The score and reason will depend on the real metric evaluation
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")
+
+ def test_get_metric_returns_Toxicity_metric(self):
+ from deepteam.metrics import ToxicityMetric
+
+ toxicity = Toxicity(async_mode=True, verbose_mode=True, evaluation_model="gpt-4o")
+ metric = toxicity._get_metric(ToxicityType.INSULTS)
+ assert isinstance(metric, ToxicityMetric)
+ assert metric.async_mode is True
+ assert metric.verbose_mode is True
+
+ @pytest.mark.asyncio
+ async def test_a_assess_returns_async_results(self):
+ toxicity = Toxicity(types=["cooperative_dialogue"], async_mode=True)
+
+ async def dummy_model_callback(prompt):
+ return prompt
+
+ results = await toxicity.a_assess(
+ model_callback=dummy_model_callback,
+ attacks_per_vulnerability_type=1,
+ )
+
+ assert ToxicityType.INSULTS in results
+ assert len(results[ToxicityType.INSULTS]) == 1
+ test_case = results[ToxicityType.INSULTS][0]
+ assert hasattr(test_case, "score")
+ assert hasattr(test_case, "reason")