Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion apps/rufust/src/helper_client/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,17 @@ mod tests {
.into_iter()
.find(|device| device.minor == number)
.expect("the disk is attached");
assert_eq!(identity.transport, "loop", "refusing a non-virtual disk");
// A virtual disk, or the one removable USB drive named by serial
// (`scripts/windows/usb-tests.ps1`).
let named = std::env::var("RUFUST_TEST_USB_SERIAL").unwrap_or_default();
assert!(
identity.transport == "loop"
|| (identity.transport == "usb"
&& identity.removable
&& !identity.serial.is_empty()
&& identity.serial == named),
"refusing a disk that is neither virtual nor the named USB drive"
);
let block = platform::to_block_device(&identity, &platform::volumes());
Some(HelperRequest {
protocol_version: PROTOCOL_VERSION,
Expand Down
21 changes: 18 additions & 3 deletions crates/rufust-helper/src/windows/vhd_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,28 @@ fn target(variable: &str) -> Option<DeviceIdentity> {
.into_iter()
.find(|device| device.minor == number)
.expect("the disk is attached");
assert_eq!(
identity.transport, "loop",
"refusing disk {number}: it is not a file-backed virtual disk"
assert!(
disposable(&identity),
"refusing disk {number}: it is neither a file-backed virtual disk nor the \
removable USB drive whose serial is in RUFUST_TEST_USB_SERIAL"
);
Some(identity)
}

/// Virtual disks are always fair game. A physical disk qualifies only as a
/// removable USB drive whose exact serial the caller named, which is how
/// `scripts/windows/usb-tests.ps1` opts one disposable stick in.
fn disposable(identity: &DeviceIdentity) -> bool {
if identity.transport == "loop" {
return true;
}
let named = std::env::var("RUFUST_TEST_USB_SERIAL").unwrap_or_default();
identity.transport == "usb"
&& identity.removable
&& !identity.serial.is_empty()
&& identity.serial == named
}

fn request(identity: &DeviceIdentity, operation: HelperOperation) -> HelperRequest {
let block = platform::to_block_device(identity, &platform::volumes());
HelperRequest {
Expand Down
7 changes: 4 additions & 3 deletions docs/PROJECT_CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,10 @@ included in 0.1.3.

These are known follow-ups, not claims that the current release is broken:

- Windows: smoke-test on disposable physical USB media (flash drive and USB
SSD), boot-test Windows-built media, and Authenticode-sign the executable
and installer. See `WINDOWS.md`.
- Windows: the engine tests passed on a physical USB flash drive
(`scripts/windows/usb-tests.ps1`). Still open: a USB SSD and a drive over
32 GB, unplugging during a write, boot-testing Windows-built media, and
Authenticode-signing the executable and installer. See `WINDOWS.md`.
- Run a packaged, real-polkit smoke test on disposable physical USB media for
formatting, raw writing, Windows media, verification, cancellation, and
disconnect during write. Automated tests, loop-backed udisks2 tests, and
Expand Down
17 changes: 14 additions & 3 deletions docs/WINDOWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ UEFI:NTFS, GPT UEFI, FAT32) from a synthetic ISO, run large FAT32 on a sparse
40 GiB disk, and drive the window's pipe launcher through a format and a
cancellation. CI runs them on every push.

`scripts\windows\usb-tests.ps1 -DiskNumber N -Serial S` runs the same tests on
one disposable USB flash drive and erases it. The script and the tests refuse
any physical disk that is not a removable USB drive with exactly that serial
(`RUFUST_TEST_USB_SERIAL`). It passed on 2026-11-14 on a 16 GB Kingston
DataTraveler 101 G2 (USB 2.0 flash drive) under Windows 11: every file system
provider, raw, gzip, and VHDX image writes with read-back, Windows installer
media in all three layouts, and a format and a cancelled bad-block test
through the worker pipes. The drive is under 32 GB, so large FAT32 did not
run on it.

## Packaging

The release workflow builds two downloads:
Expand All @@ -154,9 +164,10 @@ Authenticode-signed yet, so SmartScreen may warn on first launch.

## Open gates

- A smoke test on disposable physical USB media (flash drive and USB SSD):
format, image write, Windows media, verification, cancellation, and
unplugging during a write. Virtual disks do not replace it.
- The rest of the physical-media smoke test: a USB SSD or hard disk, a drive
over 32 GB (large FAT32), a full bad-block pass, and unplugging during a
write. The flash-drive run above covers format, image write, Windows media,
verification, and cancellation.
- Boot tests of Windows-built media in QEMU/OVMF and on hardware.
- Authenticode signing of release executables and the installer.
- ext2/3/4 and ReFS creation, drive capture, and the other features blocked
Expand Down
80 changes: 80 additions & 0 deletions scripts/windows/usb-tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# End-to-end tests of the Windows disk engine on one disposable USB stick.
#
# EVERYTHING ON THE DRIVE IS DESTROYED. Run from an elevated PowerShell at the
# repository root, naming the drive by disk number and by serial:
#
# Get-Disk | Select-Object Number, FriendlyName, BusType, SerialNumber
# powershell -ExecutionPolicy Bypass -File scripts\windows\usb-tests.ps1 `
# -DiskNumber 2 -Serial 000AEBFFD790BA60C30C0600
#
# The script and the tests both refuse a disk that is not a removable USB
# drive with exactly that serial. It runs the `windows::vhd_tests` engine
# tests (every file system provider, raw/gzip/VHDX image writes with
# read-back, Windows installer media) and the desktop's worker-pipe tests
# (format and cancellation), then leaves the stick as one FAT32 volume.
# Drives over 32 GiB also run the large FAT32 test.

param(
[Parameter(Mandatory = $true)] [int] $DiskNumber,
[Parameter(Mandatory = $true)] [string] $Serial,
[string] $Log
)

$ErrorActionPreference = 'Stop'
if ($Log) { Start-Transcript -Path $Log -Force | Out-Null }

try {
$principal = New-Object Security.Principal.WindowsPrincipal(
[Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
throw 'Run this script from an elevated (administrator) PowerShell.'
}

$disk = Get-Disk -Number $DiskNumber
if ($disk.BusType -ne 'USB') { throw "Disk $DiskNumber is $($disk.BusType), not USB." }
if ($disk.SerialNumber.Trim() -ne $Serial) {
throw "Disk $DiskNumber has serial '$($disk.SerialNumber.Trim())', not '$Serial'."
}
if ($disk.IsBoot -or $disk.IsSystem) { throw "Disk $DiskNumber is a boot or system disk." }
Write-Host "Erasing and testing disk ${DiskNumber}: $($disk.FriendlyName), $([math]::Round($disk.Size / 1GB, 1)) GB"

$work = Join-Path ([IO.Path]::GetTempPath()) ("rufust-usb-" + [Guid]::NewGuid())
New-Item -ItemType Directory -Path $work | Out-Null
$source = Join-Path $work 'source.vhdx'
$script = Join-Path $work 'diskpart.txt'
Set-Content -Path $script -Encoding ascii -Value "create vdisk file=`"$source`" maximum=16 type=fixed"
$output = & diskpart.exe /s $script
if ($LASTEXITCODE -ne 0) { throw "diskpart failed:`n$($output -join "`n")" }

$env:RUFUST_TEST_USB_SERIAL = $Serial
$env:RUFUST_TEST_DISK = "$DiskNumber"
$env:RUFUST_TEST_VHD_SOURCE = $source
if ($disk.Size -gt 33GB) { $env:RUFUST_TEST_LARGE_DISK = "$DiskNumber" }

cargo build -p rufust-helper --locked
if ($LASTEXITCODE -ne 0) { throw 'build failed' }
cargo test -p rufust-helper --locked windows::vhd_tests -- --ignored --test-threads=1
if ($LASTEXITCODE -ne 0) { throw 'engine tests failed on the USB drive' }
cargo test -p rufust --locked -- --ignored --test-threads=1 helper_client::windows::tests
if ($LASTEXITCODE -ne 0) { throw 'worker pipe tests failed on the USB drive' }

# Leave the stick usable.
Clear-Disk -Number $DiskNumber -RemoveData -RemoveOEM -Confirm:$false
$style = (Get-Disk -Number $DiskNumber).PartitionStyle
if ($style -eq 'RAW') { Initialize-Disk -Number $DiskNumber -PartitionStyle MBR }
$size = [math]::Min((Get-Disk -Number $DiskNumber).LargestFreeExtent, 32GB - 1MB)
New-Partition -DiskNumber $DiskNumber -Size $size -AssignDriveLetter |
Format-Volume -FileSystem FAT32 -NewFileSystemLabel 'RUFUST' -Confirm:$false | Out-Null
Write-Host 'USB TESTS PASSED'
}
catch {
Write-Host "USB TESTS FAILED: $_"
throw
}
finally {
if ($work) { Remove-Item -Recurse -Force $work -ErrorAction SilentlyContinue }
foreach ($name in 'RUFUST_TEST_USB_SERIAL', 'RUFUST_TEST_DISK', 'RUFUST_TEST_VHD_SOURCE', 'RUFUST_TEST_LARGE_DISK') {
Remove-Item "Env:\$name" -ErrorAction SilentlyContinue
}
if ($Log) { Stop-Transcript | Out-Null }
}