Skip to content

Commit 3f92836

Browse files
MAINT: Bump the minor-and-patch group with 8 updates (microsoft#2114)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4310bf9 commit 3f92836

3 files changed

Lines changed: 187 additions & 174 deletions

File tree

pyrit/prompt_target/http_target/http_target.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -189,23 +189,22 @@ async def _send_prompt_to_target_async(self, *, normalized_conversation: list[Me
189189
cleanup_client = True
190190

191191
try:
192-
match http_body:
193-
case dict():
194-
response = await client.request(
195-
method=http_method,
196-
url=url,
197-
headers=header_dict,
198-
data=http_body,
199-
follow_redirects=True,
200-
)
201-
case str():
202-
response = await client.request(
203-
method=http_method,
204-
url=url,
205-
headers=header_dict,
206-
content=http_body,
207-
follow_redirects=True,
208-
)
192+
if isinstance(http_body, dict):
193+
response = await client.request(
194+
method=http_method,
195+
url=url,
196+
headers=header_dict,
197+
data=http_body,
198+
follow_redirects=True,
199+
)
200+
else:
201+
response = await client.request(
202+
method=http_method,
203+
url=url,
204+
headers=header_dict,
205+
content=http_body,
206+
follow_redirects=True,
207+
)
209208

210209
response_content = response.content
211210

tests/unit/prompt_target/target/test_http_target.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,45 @@ async def test_send_prompt_async(mock_request, mock_http_target, mock_http_respo
9090
)
9191

9292

93+
@patch("httpx.AsyncClient.request", new_callable=AsyncMock)
94+
async def test_send_prompt_async_uses_data_for_dict_body(mock_request, mock_http_response, patch_central_database):
95+
target = HTTPTarget(http_request="POST / HTTP/1.1\nHost: example.com\n\n")
96+
message = MagicMock()
97+
message.message_pieces = [
98+
MagicMock(
99+
converted_value="test_prompt",
100+
converted_value_data_type="text",
101+
attack_identifier=None,
102+
conversation_id="",
103+
labels={},
104+
prompt_metadata={},
105+
)
106+
]
107+
mock_request.return_value = mock_http_response
108+
109+
with patch.object(
110+
target,
111+
"parse_raw_http_request",
112+
return_value=(
113+
{"host": "example.com"},
114+
{"prompt": "test_prompt"},
115+
"https://example.com/",
116+
"POST",
117+
"HTTP/1.1",
118+
),
119+
):
120+
response = await target.send_prompt_async(message=message)
121+
122+
assert len(response) == 1
123+
mock_request.assert_awaited_once_with(
124+
method="POST",
125+
url="https://example.com/",
126+
headers={"host": "example.com"},
127+
data={"prompt": "test_prompt"},
128+
follow_redirects=True,
129+
)
130+
131+
93132
def test_parse_raw_http_request_ignores_content_length(patch_central_database):
94133
request = "POST / HTTP/1.1\nHost: example.com\nContent-Type: application/json\nContent-Length: 100\n\n"
95134
target = HTTPTarget(http_request=request)

0 commit comments

Comments
 (0)