Skip to content

Commit 0b89f37

Browse files
committed
test: cover archive symlink and auth redaction shapes
1 parent 32334be commit 0b89f37

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

test/test_ff_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,18 @@ def test_unified_authenticator_authentication_error_redacts_auth_in_message():
370370
assert exc.auth == bad_auth
371371

372372

373+
@pytest.mark.parametrize("auth, secrets", [
374+
(("key-value", "secret-value"), ("key-value", "secret-value")),
375+
(["key-value", "secret-value"], ("key-value", "secret-value")),
376+
("opaque-credential", ("opaque-credential",)),
377+
])
378+
def test_unified_authenticator_authentication_error_redacts_other_auth_shapes(auth, secrets):
379+
exc = ff_utils.UnifiedAuthenticator.AuthenticationError("Invalid authentication.", auth, "test-env")
380+
381+
assert all(secret not in str(exc) for secret in secrets)
382+
assert exc.auth == auth
383+
384+
373385
# Integration tests
374386

375387
@pytest.mark.integratedx

test/test_zip_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ def _make_tar_with_member(tar_path: str, member_name: str, content: bytes = b"da
2323
tf.addfile(info, io.BytesIO(content))
2424

2525

26+
def _make_tar_with_symlink(tar_path: str, member_name: str, link_target: str) -> None:
27+
with tarfile.open(tar_path, "w") as tf:
28+
info = tarfile.TarInfo(name=member_name)
29+
info.type = tarfile.SYMTYPE
30+
info.linkname = link_target
31+
tf.addfile(info)
32+
33+
2634
def test_unpack_zip_file_to_temporary_directory_rejects_path_traversal():
2735
# Zip Slip: a malicious archive entry named with ../ segments must not be extracted
2836
# outside of the target directory, even though zipfile.extractall would otherwise allow it.
@@ -69,6 +77,15 @@ def test_unpack_tar_file_to_temporary_directory_rejects_path_traversal():
6977
assert not os.path.exists("/tmp/dcicutils_tar_slip_poc.txt")
7078

7179

80+
def test_unpack_tar_file_to_temporary_directory_rejects_escaping_symlink():
81+
with temporary_directory() as work_dir:
82+
tar_path = os.path.join(work_dir, "evil_symlink.tar")
83+
_make_tar_with_symlink(tar_path, "escape", "../../../tmp")
84+
with pytest.raises(tarfile.FilterError):
85+
with unpack_tar_file_to_temporary_directory(tar_path):
86+
pass
87+
88+
7289
def test_unpack_tar_file_to_temporary_directory_extracts_benign_archive():
7390
with temporary_directory() as work_dir:
7491
tar_path = os.path.join(work_dir, "benign.tar")

0 commit comments

Comments
 (0)