Skip to content

Commit bf86f77

Browse files
Test not-file metadata prefix control-char sanitization
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 1f15535 commit bf86f77

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

tests/test_extension_create_utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,28 @@ def test_normalize_extension_create_input_uses_metadata_not_file_prefix(
187187
assert exc_info.value.original_error is None
188188

189189

190+
def test_normalize_extension_create_input_sanitizes_control_chars_in_metadata_not_file_prefix(
191+
tmp_path, monkeypatch: pytest.MonkeyPatch
192+
):
193+
params = CreateExtensionParams(name="dir-extension", file_path=tmp_path)
194+
monkeypatch.setattr(
195+
extension_create_utils,
196+
"EXTENSION_OPERATION_METADATA",
197+
SimpleNamespace(
198+
missing_file_message_prefix="Custom extension missing prefix",
199+
not_file_message_prefix="Custom\tnot-file prefix",
200+
),
201+
)
202+
203+
with pytest.raises(
204+
HyperbrowserError,
205+
match="Custom\\?not-file prefix:",
206+
) as exc_info:
207+
normalize_extension_create_input(params)
208+
209+
assert exc_info.value.original_error is None
210+
211+
190212
def test_normalize_extension_create_input_uses_default_not_file_prefix_when_metadata_invalid(
191213
tmp_path, monkeypatch: pytest.MonkeyPatch
192214
):

tests/test_session_upload_utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,33 @@ def test_normalize_upload_file_input_uses_default_not_file_prefix_when_metadata_
176176
assert exc_info.value.original_error is None
177177

178178

179+
def test_normalize_upload_file_input_sanitizes_control_chars_in_metadata_not_file_prefix(
180+
tmp_path: Path,
181+
monkeypatch: pytest.MonkeyPatch,
182+
):
183+
monkeypatch.setattr(
184+
session_upload_utils,
185+
"SESSION_OPERATION_METADATA",
186+
type(
187+
"_Metadata",
188+
(),
189+
{
190+
"upload_missing_file_message_prefix": "Custom missing prefix",
191+
"upload_not_file_message_prefix": "Custom\tnot-file prefix",
192+
"upload_open_file_error_prefix": "Custom open prefix",
193+
},
194+
)(),
195+
)
196+
197+
with pytest.raises(
198+
HyperbrowserError,
199+
match="Custom\\?not-file prefix:",
200+
) as exc_info:
201+
normalize_upload_file_input(tmp_path)
202+
203+
assert exc_info.value.original_error is None
204+
205+
179206
def test_normalize_upload_file_input_returns_open_file_like_object():
180207
file_obj = io.BytesIO(b"content")
181208

0 commit comments

Comments
 (0)