Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(transfer): handle LOGICAL root home directory mapping (#557)
Stefan Budeanu203997e24a00
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a275abd6..6b423b21 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,6 +5,8 @@ All notable changes to MiniStack will be documented here.Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).Versioning follows [Semantic Versioning](https://semver.org/).+- **Transfer Family `LOGICAL` root home directory mappings** — `HomeDirectoryMappings` with `Entry="/"` now match SFTP paths like `/users.csv` and resolve them under the configured target bucket instead of falling through because the resolver checked for a `"//"` prefix.+---## [1.3.26] — 2026-05-04diff --git a/ministack/services/transfer.py b/ministack/services/transfer.pyindex 50c72e7b..d441b346 100644--- a/ministack/services/transfer.py+++ b/ministack/services/transfer.py@@ -675,7 +675,8 @@ def _sftp_resolve_s3_target(user: dict, virtual_path: str):for mapping in sorted_maps:entry = _sftp_normalize_virtual_path(mapping.get("Entry", "/"))target = mapping.get("Target", "")- if virtual_path == entry or virtual_path.startswith(entry + "/"):+ prefix = entry if entry == "/" else entry + "/"+ if virtual_path == entry or virtual_path.startswith(prefix):rest = virtual_path[len(entry):].lstrip("/")full = target.rstrip("/") + ("/" + rest if rest else "")return _sftp_split_bucket_key(full)diff --git a/tests/test_transfer.py b/tests/test_transfer.pyindex dfb2a27a..c67ef887 100644--- a/tests/test_transfer.py+++ b/tests/test_transfer.py@@ -591,6 +591,35 @@ def test_sftp_mkdir_listdir_rmdir(transfer, s3):transfer.delete_server(ServerId=ctx["server_id"])+def test_sftp_logical_root_entry_mapping(transfer, s3):+ """LOGICAL home dir with Entry='/' maps all paths to the target bucket.+ Regression test for a bug where entry + '/' produced '//' and never+ matched any path."""+ suffix = uuid.uuid4().hex[:8]+ bucket = f"sftp-root-{suffix}"+ s3.create_bucket(Bucket=bucket)+ ctx = _provision(+ transfer,+ s3,+ bucket=bucket,+ logical_mappings=[{"Entry": "/", "Target": f"/{bucket}"}],+ )++ async def _run():+ async with await _connect(ctx["user_name"], ctx["priv_pem"]) as conn:+ async with conn.start_sftp_client() as sftp:+ async with sftp.open("/users.csv", "wb") as f:+ await f.write(b"id,name\n1,Alice\n")+ async with sftp.open("/users.csv", "rb") as f:+ assert await f.read() == b"id,name\n1,Alice\n"++ asyncio.run(_run())++ obj = s3.get_object(Bucket=bucket, Key="users.csv")+ assert obj["Body"].read() == b"id,name\n1,Alice\n"+ transfer.delete_server(ServerId=ctx["server_id"])++def test_sftp_logical_home_directory_mappings(transfer, s3):"""LOGICAL home dir maps virtual `/inbox` → bucket prefix; an uploadto /inbox/foo lands at the mapped S3 key."""