Skip to content

Commit 1b1d7e3

Browse files
lovesegfaultxokdvium
authored andcommitted
test(nixos): add nix-prefetch-url test for S3 URLs with query parameters
Adds a comprehensive test to verify that `nix-prefetch-url` correctly handles S3 URLs with query parameters (e.g., custom endpoints and regions). Previously, nix-prefetch-url would fail with "invalid store path" errors when given S3 URLs with query parameters like `?endpoint=http://server:9000&region=eu-west-1`, because it incorrectly extracted the filename from the query parameters instead of the path.
1 parent e3b3f05 commit 1b1d7e3

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/nixos/s3-binary-cache-store.nix

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,69 @@ in
534534
535535
print(" ✓ No compression applied by default")
536536
537+
@setup_s3()
538+
def test_nix_prefetch_url(bucket):
539+
"""Test that nix-prefetch-url retrieves actual file content from S3, not empty files (issue #8862)"""
540+
print("\n=== Testing nix-prefetch-url S3 Content Retrieval (issue #8862) ===")
541+
542+
# Create a test file with known content
543+
test_content = "This is test content to verify S3 downloads work correctly!\n"
544+
test_file_size = len(test_content)
545+
546+
server.succeed(f"echo -n '{test_content}' > /tmp/test-file.txt")
547+
548+
# Upload to S3
549+
server.succeed(f"mc cp /tmp/test-file.txt minio/{bucket}/test-file.txt")
550+
551+
# Calculate expected hash
552+
expected_hash = server.succeed(
553+
"nix hash file --type sha256 --base32 /tmp/test-file.txt"
554+
).strip()
555+
556+
print(f" ✓ Uploaded test file to S3 ({test_file_size} bytes)")
557+
558+
# Use nix-prefetch-url to download from S3
559+
s3_url = make_s3_url(bucket, path="/test-file.txt")
560+
561+
prefetch_output = client.succeed(
562+
f"{ENV_WITH_CREDS} nix-prefetch-url --print-path '{s3_url}'"
563+
)
564+
565+
# Extract hash and store path
566+
# With --print-path, output is: <hash>\n<store-path>
567+
lines = prefetch_output.strip().split('\n')
568+
prefetch_hash = lines[0] # First line is the hash
569+
store_path = lines[1] # Second line is the store path
570+
571+
# Verify hash matches
572+
if prefetch_hash != expected_hash:
573+
raise Exception(
574+
f"Hash mismatch: expected {expected_hash}, got {prefetch_hash}"
575+
)
576+
577+
print(" ✓ nix-prefetch-url completed with correct hash")
578+
579+
# Verify the downloaded file is NOT empty (the bug in #8862)
580+
file_size = int(client.succeed(f"stat -c %s {store_path}").strip())
581+
582+
if file_size == 0:
583+
raise Exception("Downloaded file is EMPTY - issue #8862 regression detected!")
584+
585+
if file_size != test_file_size:
586+
raise Exception(
587+
f"File size mismatch: expected {test_file_size}, got {file_size}"
588+
)
589+
590+
print(f" ✓ File has correct size ({file_size} bytes, not empty)")
591+
592+
# Verify actual content matches by comparing hashes instead of printing entire file
593+
downloaded_hash = client.succeed(f"nix hash file --type sha256 --base32 {store_path}").strip()
594+
595+
if downloaded_hash != expected_hash:
596+
raise Exception(f"Content hash mismatch: expected {expected_hash}, got {downloaded_hash}")
597+
598+
print(" ✓ File content verified correct (hash matches)")
599+
537600
# ============================================================================
538601
# Main Test Execution
539602
# ============================================================================
@@ -562,6 +625,7 @@ in
562625
test_compression_narinfo_gzip()
563626
test_compression_mixed()
564627
test_compression_disabled()
628+
test_nix_prefetch_url()
565629
566630
print("\n" + "="*80)
567631
print("✓ All S3 Binary Cache Store Tests Passed!")

0 commit comments

Comments
 (0)