Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3364a7eb7b | ||
|
|
970d54b991 | ||
|
|
b8b56c0f32 | ||
|
|
7c915a9fd7 | ||
|
|
d0917c952f | ||
|
|
d4de2915a1 | ||
|
|
7f8d5711ea | ||
|
|
89b81d73b1 | ||
|
|
25c3358842 | ||
|
|
367af4de82 | ||
|
|
600f68b63d |
@@ -88,6 +88,9 @@ jobs:
|
|||||||
$errors | ForEach-Object { Write-Error $_ }
|
$errors | ForEach-Object { Write-Error $_ }
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
- name: Windows installer runtime test
|
||||||
|
shell: pwsh
|
||||||
|
run: scripts/test-install-windows.ps1
|
||||||
- name: cmd installer smoke check
|
- name: cmd installer smoke check
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
Generated
+1
-1
@@ -436,7 +436,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dosh"
|
name = "dosh"
|
||||||
version = "1.0.0-rc42"
|
version = "1.0.0-rc44"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64",
|
"base64",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "dosh"
|
name = "dosh"
|
||||||
version = "1.0.0-rc42"
|
version = "1.0.0-rc44"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
|
|||||||
+36
-132
@@ -11,14 +11,17 @@ param(
|
|||||||
[string]$BinaryBase = $env:DOSH_BINARY_BASE,
|
[string]$BinaryBase = $env:DOSH_BINARY_BASE,
|
||||||
[string]$BinaryName = $env:DOSH_BINARY_NAME,
|
[string]$BinaryName = $env:DOSH_BINARY_NAME,
|
||||||
[string]$BinaryVersion = $(if ($env:DOSH_BINARY_VERSION) { $env:DOSH_BINARY_VERSION } else { "latest" }),
|
[string]$BinaryVersion = $(if ($env:DOSH_BINARY_VERSION) { $env:DOSH_BINARY_VERSION } else { "latest" }),
|
||||||
|
[switch]$BinaryExact = $($env:DOSH_BINARY_EXACT -and $env:DOSH_BINARY_EXACT -ne "0"),
|
||||||
[string]$UpdateCache = $(if ($env:DOSH_UPDATE_CACHE) { $env:DOSH_UPDATE_CACHE } elseif ($env:LOCALAPPDATA) { Join-Path $env:LOCALAPPDATA "dosh\source" } else { Join-Path $HOME ".cache\dosh\source" }),
|
[string]$UpdateCache = $(if ($env:DOSH_UPDATE_CACHE) { $env:DOSH_UPDATE_CACHE } elseif ($env:LOCALAPPDATA) { Join-Path $env:LOCALAPPDATA "dosh\source" } else { Join-Path $HOME ".cache\dosh\source" }),
|
||||||
[switch]$BinaryRequired = $($env:DOSH_BINARY_REQUIRED -and $env:DOSH_BINARY_REQUIRED -ne "0"),
|
[switch]$BinaryRequired = $($env:DOSH_BINARY_REQUIRED -and $env:DOSH_BINARY_REQUIRED -ne "0"),
|
||||||
|
[switch]$FromCurrent,
|
||||||
[switch]$ForceConfig
|
[switch]$ForceConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
$ProgressPreference = "SilentlyContinue"
|
$ProgressPreference = "SilentlyContinue"
|
||||||
$Quiet = $env:DOSH_UPDATE_QUIET -and $env:DOSH_UPDATE_QUIET -ne "0"
|
$Quiet = $env:DOSH_UPDATE_QUIET -and $env:DOSH_UPDATE_QUIET -ne "0"
|
||||||
|
$script:ResolvedSourceRef = $null
|
||||||
|
|
||||||
function Write-Info($Message) {
|
function Write-Info($Message) {
|
||||||
if (-not $Quiet) {
|
if (-not $Quiet) {
|
||||||
@@ -121,96 +124,18 @@ function Release-DownloadUrl {
|
|||||||
if (-not $web) {
|
if (-not $web) {
|
||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
if ($BinaryVersion -eq "latest") {
|
$releaseRef = Source-ReleaseRef
|
||||||
return "$web/releases/latest/download/$name"
|
if (-not $releaseRef) {
|
||||||
}
|
|
||||||
"$web/releases/download/$BinaryVersion/$name"
|
|
||||||
}
|
|
||||||
|
|
||||||
function Release-LatestTagDownloadUrl {
|
|
||||||
if ($BinaryUrl -or $BinaryBase -or $BinaryVersion -ne "latest") {
|
|
||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
$web = Repo-WebBase $Repo
|
"$web/releases/download/$releaseRef/$name"
|
||||||
if (-not $web) {
|
|
||||||
return $null
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$response = Invoke-WebRequest -UseBasicParsing -Uri "$web/releases/latest" -MaximumRedirection 5
|
|
||||||
$effective = $null
|
|
||||||
if ($response.BaseResponse.ResponseUri) {
|
|
||||||
$effective = $response.BaseResponse.ResponseUri.AbsoluteUri
|
|
||||||
} elseif ($response.BaseResponse.RequestMessage -and $response.BaseResponse.RequestMessage.RequestUri) {
|
|
||||||
$effective = $response.BaseResponse.RequestMessage.RequestUri.AbsoluteUri
|
|
||||||
}
|
|
||||||
$prefix = "$web/releases/tag/"
|
|
||||||
if ($effective -and $effective.StartsWith($prefix)) {
|
|
||||||
$tag = $effective.Substring($prefix.Length)
|
|
||||||
if ($tag) {
|
|
||||||
return "$web/releases/download/$tag/$(Release-ArtifactName)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
return $null
|
|
||||||
}
|
|
||||||
return $null
|
|
||||||
}
|
|
||||||
|
|
||||||
function Version-Core($Value) {
|
|
||||||
$base = $Value.TrimStart("v").Split("+")[0]
|
|
||||||
$base.Split("-")[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
function Version-Prerelease($Value) {
|
|
||||||
$base = $Value.TrimStart("v").Split("+")[0]
|
|
||||||
$dash = $base.IndexOf("-")
|
|
||||||
if ($dash -lt 0) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
$base.Substring($dash + 1).ToLowerInvariant()
|
|
||||||
}
|
|
||||||
|
|
||||||
function Version-Parts($Value) {
|
|
||||||
[regex]::Matches((Version-Core $Value), "\d+") | ForEach-Object { [int64]$_.Value }
|
|
||||||
}
|
|
||||||
|
|
||||||
function Compare-Prerelease($Left, $Right) {
|
|
||||||
if (-not $Left -and -not $Right) {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
if (-not $Left) {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
if (-not $Right) {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
if ($Left -eq $Right) {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
if ($Left -match "(?i)^rc(\d+)$" -and $Right -match "(?i)^rc(\d+)$") {
|
|
||||||
$leftRc = [int64]([regex]::Match($Left, "(?i)^rc(\d+)$").Groups[1].Value)
|
|
||||||
$rightRc = [int64]([regex]::Match($Right, "(?i)^rc(\d+)$").Groups[1].Value)
|
|
||||||
return $leftRc.CompareTo($rightRc)
|
|
||||||
}
|
|
||||||
return [string]::CompareOrdinal($Left, $Right)
|
|
||||||
}
|
|
||||||
|
|
||||||
function Compare-DoshVersion($Left, $Right) {
|
|
||||||
$leftParts = @(Version-Parts $Left)
|
|
||||||
$rightParts = @(Version-Parts $Right)
|
|
||||||
$width = [Math]::Max($leftParts.Count, $rightParts.Count)
|
|
||||||
for ($i = 0; $i -lt $width; $i++) {
|
|
||||||
$l = if ($i -lt $leftParts.Count) { $leftParts[$i] } else { 0 }
|
|
||||||
$r = if ($i -lt $rightParts.Count) { $rightParts[$i] } else { 0 }
|
|
||||||
if ($l -lt $r) { return -1 }
|
|
||||||
if ($l -gt $r) { return 1 }
|
|
||||||
}
|
|
||||||
return Compare-Prerelease (Version-Prerelease $Left) (Version-Prerelease $Right)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Current-SourceVersion {
|
function Current-SourceVersion {
|
||||||
if (Test-Path "Cargo.toml") {
|
if ($FromCurrent) {
|
||||||
|
if (-not (Test-Path "Cargo.toml")) {
|
||||||
|
return $null
|
||||||
|
}
|
||||||
$raw = Get-Content "Cargo.toml" -Raw
|
$raw = Get-Content "Cargo.toml" -Raw
|
||||||
} else {
|
} else {
|
||||||
$web = Repo-WebBase $Repo
|
$web = Repo-WebBase $Repo
|
||||||
@@ -230,47 +155,23 @@ function Current-SourceVersion {
|
|||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
|
|
||||||
function Latest-ReleaseTag {
|
function Source-ReleaseRef {
|
||||||
$web = Repo-WebBase $Repo
|
if ($BinaryUrl -or $BinaryBase) {
|
||||||
if (-not $web) {
|
|
||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
try {
|
if ($BinaryVersion -ne "latest" -and $BinaryExact) {
|
||||||
$response = Invoke-WebRequest -UseBasicParsing -Uri "$web/releases/latest" -MaximumRedirection 5
|
return $BinaryVersion
|
||||||
$effective = $null
|
|
||||||
if ($response.BaseResponse.ResponseUri) {
|
|
||||||
$effective = $response.BaseResponse.ResponseUri.AbsoluteUri
|
|
||||||
} elseif ($response.BaseResponse.RequestMessage -and $response.BaseResponse.RequestMessage.RequestUri) {
|
|
||||||
$effective = $response.BaseResponse.RequestMessage.RequestUri.AbsoluteUri
|
|
||||||
}
|
|
||||||
$prefix = "$web/releases/tag/"
|
|
||||||
if ($effective -and $effective.StartsWith($prefix)) {
|
|
||||||
return $effective.Substring($prefix.Length)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch {
|
$current = Current-SourceVersion
|
||||||
return $null
|
if ($current) {
|
||||||
|
return "v$($current.TrimStart('v'))"
|
||||||
|
}
|
||||||
|
if ($BinaryVersion -ne "latest") {
|
||||||
|
return $BinaryVersion
|
||||||
}
|
}
|
||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
|
|
||||||
function Latest-ReleaseIsStale {
|
|
||||||
if ($BinaryUrl -or $BinaryBase -or $BinaryVersion -ne "latest") {
|
|
||||||
return $false
|
|
||||||
}
|
|
||||||
$latest = Latest-ReleaseTag
|
|
||||||
$current = Current-SourceVersion
|
|
||||||
if (-not $latest -or -not $current) {
|
|
||||||
return $false
|
|
||||||
}
|
|
||||||
$latestVersion = $latest.TrimStart("v")
|
|
||||||
if ((Compare-DoshVersion $latestVersion $current) -lt 0) {
|
|
||||||
Write-Warning "latest release $latestVersion is older than source $current; skipping stale prebuilt"
|
|
||||||
return $true
|
|
||||||
}
|
|
||||||
return $false
|
|
||||||
}
|
|
||||||
|
|
||||||
function Verify-ArchiveChecksum($Url, $Archive) {
|
function Verify-ArchiveChecksum($Url, $Archive) {
|
||||||
$checksumPath = "$Archive.sha256"
|
$checksumPath = "$Archive.sha256"
|
||||||
try {
|
try {
|
||||||
@@ -475,16 +376,11 @@ if ($env:DOSH_INSTALL_BINDIR_FILE) {
|
|||||||
Apply-PendingBinaryReplacements $bindir
|
Apply-PendingBinaryReplacements $bindir
|
||||||
|
|
||||||
function Install-Prebuilt {
|
function Install-Prebuilt {
|
||||||
if (Latest-ReleaseIsStale) {
|
$url = Release-DownloadUrl
|
||||||
return $false
|
|
||||||
}
|
|
||||||
$url = Release-LatestTagDownloadUrl
|
|
||||||
if (-not $url) {
|
|
||||||
$url = Release-DownloadUrl
|
|
||||||
}
|
|
||||||
if (-not $url) {
|
if (-not $url) {
|
||||||
return $false
|
return $false
|
||||||
}
|
}
|
||||||
|
$script:ResolvedSourceRef = Source-ReleaseRef
|
||||||
$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("dosh-bin-" + [guid]::NewGuid())
|
$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("dosh-bin-" + [guid]::NewGuid())
|
||||||
$zip = Join-Path $tmp (Release-ArtifactName)
|
$zip = Join-Path $tmp (Release-ArtifactName)
|
||||||
$extract = Join-Path $tmp "extract"
|
$extract = Join-Path $tmp "extract"
|
||||||
@@ -520,7 +416,10 @@ function Install-Prebuilt {
|
|||||||
|
|
||||||
function Install-FromSource {
|
function Install-FromSource {
|
||||||
Ensure-Cargo
|
Ensure-Cargo
|
||||||
if (Test-Path "Cargo.toml") {
|
if ($FromCurrent) {
|
||||||
|
if (-not (Test-Path "Cargo.toml")) {
|
||||||
|
throw "-FromCurrent requires a Dosh checkout with Cargo.toml"
|
||||||
|
}
|
||||||
$src = (Get-Location).Path
|
$src = (Get-Location).Path
|
||||||
} else {
|
} else {
|
||||||
if (-not $Repo) {
|
if (-not $Repo) {
|
||||||
@@ -530,21 +429,26 @@ function Install-FromSource {
|
|||||||
$sourceCache = Assert-SafeUpdateCache $UpdateCache
|
$sourceCache = Assert-SafeUpdateCache $UpdateCache
|
||||||
$parent = Split-Path -Parent $sourceCache
|
$parent = Split-Path -Parent $sourceCache
|
||||||
New-Item -ItemType Directory -Force -Path $parent | Out-Null
|
New-Item -ItemType Directory -Force -Path $parent | Out-Null
|
||||||
|
$sourceRef = if ($script:ResolvedSourceRef) { $script:ResolvedSourceRef } else { "main" }
|
||||||
if (Test-Path (Join-Path $sourceCache ".git")) {
|
if (Test-Path (Join-Path $sourceCache ".git")) {
|
||||||
git -C $sourceCache remote set-url origin $Repo
|
git -C $sourceCache remote set-url origin $Repo
|
||||||
$fetchArgs = @("-C", $sourceCache, "fetch", "--depth", "1", "origin", "main")
|
$fetchArgs = @("-C", $sourceCache, "fetch", "--depth", "1", "origin", $sourceRef)
|
||||||
if ($Quiet) {
|
if ($Quiet) {
|
||||||
$fetchArgs = @("-C", $sourceCache, "fetch", "-q", "--depth", "1", "origin", "main")
|
$fetchArgs = @("-C", $sourceCache, "fetch", "-q", "--depth", "1", "origin", $sourceRef)
|
||||||
}
|
}
|
||||||
git @fetchArgs
|
git @fetchArgs
|
||||||
git -C $sourceCache checkout -q -B main FETCH_HEAD
|
if ($sourceRef -eq "main") {
|
||||||
|
git -C $sourceCache checkout -q -B main FETCH_HEAD
|
||||||
|
} else {
|
||||||
|
git -C $sourceCache checkout -q --detach FETCH_HEAD
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Test-Path $sourceCache) {
|
if (Test-Path $sourceCache) {
|
||||||
Remove-Item -Recurse -Force $sourceCache
|
Remove-Item -Recurse -Force $sourceCache
|
||||||
}
|
}
|
||||||
$cloneArgs = @("clone", "--depth", "1", "--branch", "main", $Repo, $sourceCache)
|
$cloneArgs = @("clone", "--depth", "1", "--branch", $sourceRef, $Repo, $sourceCache)
|
||||||
if ($Quiet) {
|
if ($Quiet) {
|
||||||
$cloneArgs = @("clone", "-q", "--depth", "1", "--branch", "main", $Repo, $sourceCache)
|
$cloneArgs = @("clone", "-q", "--depth", "1", "--branch", $sourceRef, $Repo, $sourceCache)
|
||||||
}
|
}
|
||||||
git @cloneArgs | Out-Null
|
git @cloneArgs | Out-Null
|
||||||
}
|
}
|
||||||
|
|||||||
+38
-122
@@ -17,6 +17,7 @@ binary_url="${DOSH_BINARY_URL:-}"
|
|||||||
binary_base="${DOSH_BINARY_BASE:-}"
|
binary_base="${DOSH_BINARY_BASE:-}"
|
||||||
binary_name="${DOSH_BINARY_NAME:-}"
|
binary_name="${DOSH_BINARY_NAME:-}"
|
||||||
binary_version="${DOSH_BINARY_VERSION:-latest}"
|
binary_version="${DOSH_BINARY_VERSION:-latest}"
|
||||||
|
binary_exact="${DOSH_BINARY_EXACT:-0}"
|
||||||
binary_required="${DOSH_BINARY_REQUIRED:-0}"
|
binary_required="${DOSH_BINARY_REQUIRED:-0}"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
@@ -47,7 +48,9 @@ Environment alternatives:
|
|||||||
DOSH_BINARY_NAME NAME
|
DOSH_BINARY_NAME NAME
|
||||||
Release tarball name; defaults to dosh-OS-ARCH.tar.gz
|
Release tarball name; defaults to dosh-OS-ARCH.tar.gz
|
||||||
DOSH_BINARY_VERSION TAG
|
DOSH_BINARY_VERSION TAG
|
||||||
Release tag when deriving DOSH_BINARY_BASE; default latest
|
Requested release tag; repository version wins unless exact
|
||||||
|
DOSH_BINARY_EXACT=1
|
||||||
|
Require DOSH_BINARY_VERSION exactly, including downgrades
|
||||||
DOSH_BINARY_REQUIRED=1
|
DOSH_BINARY_REQUIRED=1
|
||||||
Fail instead of falling back to source when binary install fails
|
Fail instead of falling back to source when binary install fails
|
||||||
EOF
|
EOF
|
||||||
@@ -173,6 +176,7 @@ config_dir="$HOME/.config/dosh"
|
|||||||
data_dir="$HOME/.local/share/dosh"
|
data_dir="$HOME/.local/share/dosh"
|
||||||
systemd_user_dir="$HOME/.config/systemd/user"
|
systemd_user_dir="$HOME/.config/systemd/user"
|
||||||
src_dir=""
|
src_dir=""
|
||||||
|
resolved_source_ref=""
|
||||||
|
|
||||||
mkdir -p "$bindir" "$config_dir" "$data_dir"
|
mkdir -p "$bindir" "$config_dir" "$data_dir"
|
||||||
|
|
||||||
@@ -228,97 +232,13 @@ release_download_url() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
web_base="$(repo_web_base "$repo")" || return 1
|
web_base="$(repo_web_base "$repo")" || return 1
|
||||||
if [ "$binary_version" = "latest" ]; then
|
release_ref="$(release_source_ref)" || return 1
|
||||||
printf '%s/releases/latest/download/%s\n' "$web_base" "$(release_artifact_name)"
|
printf '%s/releases/download/%s/%s\n' "$web_base" "$release_ref" "$(release_artifact_name)"
|
||||||
else
|
|
||||||
printf '%s/releases/download/%s/%s\n' "$web_base" "$binary_version" "$(release_artifact_name)"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
release_latest_tag_download_url() {
|
|
||||||
if [ -n "$binary_url" ] || [ -n "$binary_base" ] || [ "$binary_version" != "latest" ] || [ -z "$repo" ]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
web_base="$(repo_web_base "$repo")" || return 1
|
|
||||||
latest_url="$(curl -fsSL -o /dev/null -w '%{url_effective}' "$web_base/releases/latest" 2>/dev/null || true)"
|
|
||||||
case "$latest_url" in
|
|
||||||
"$web_base"/releases/tag/*)
|
|
||||||
tag="${latest_url##"$web_base"/releases/tag/}"
|
|
||||||
[ -n "$tag" ] || return 1
|
|
||||||
printf '%s/releases/download/%s/%s\n' "$web_base" "$tag" "$(release_artifact_name)"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
version_core() {
|
|
||||||
value="${1#v}"
|
|
||||||
value="${value%%+*}"
|
|
||||||
printf '%s\n' "${value%%-*}"
|
|
||||||
}
|
|
||||||
|
|
||||||
version_prerelease() {
|
|
||||||
value="${1#v}"
|
|
||||||
value="${value%%+*}"
|
|
||||||
case "$value" in
|
|
||||||
*-*) printf '%s\n' "${value#*-}" ;;
|
|
||||||
*) printf '\n' ;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
version_core_part() {
|
|
||||||
version="$1"
|
|
||||||
index="$2"
|
|
||||||
version_core "$version" \
|
|
||||||
| sed 's/[^0-9][^0-9]*/ /g' \
|
|
||||||
| awk -v index="$index" '{ value=$index; if (value == "") value=0; print value }'
|
|
||||||
}
|
|
||||||
|
|
||||||
prerelease_less_than() {
|
|
||||||
left="$1"
|
|
||||||
right="$2"
|
|
||||||
if [ -z "$left" ] && [ -z "$right" ]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
if [ -z "$left" ]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
if [ -z "$right" ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
if [ "$left" = "$right" ]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
left_rc="$(printf '%s\n' "$left" | sed -n 's/^[Rr][Cc]\([0-9][0-9]*\)$/\1/p')"
|
|
||||||
right_rc="$(printf '%s\n' "$right" | sed -n 's/^[Rr][Cc]\([0-9][0-9]*\)$/\1/p')"
|
|
||||||
if [ -n "$left_rc" ] && [ -n "$right_rc" ]; then
|
|
||||||
[ "$left_rc" -lt "$right_rc" ]
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
first="$(printf '%s\n%s\n' "$left" "$right" | LC_ALL=C sort | sed -n '1p')"
|
|
||||||
[ "$first" = "$left" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
version_less_than() {
|
|
||||||
left="$1"
|
|
||||||
right="$2"
|
|
||||||
for index in 1 2 3 4 5 6 7 8; do
|
|
||||||
lpart="$(version_core_part "$left" "$index")"
|
|
||||||
rpart="$(version_core_part "$right" "$index")"
|
|
||||||
if [ "$lpart" -lt "$rpart" ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
if [ "$lpart" -gt "$rpart" ]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
prerelease_less_than "$(version_prerelease "$left")" "$(version_prerelease "$right")"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
current_source_version() {
|
current_source_version() {
|
||||||
if [ -f Cargo.toml ]; then
|
if [ "$from_current" -eq 1 ]; then
|
||||||
|
[ -f Cargo.toml ] || return 1
|
||||||
sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | sed -n '1p'
|
sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | sed -n '1p'
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@@ -329,32 +249,21 @@ current_source_version() {
|
|||||||
| sed -n '1p'
|
| sed -n '1p'
|
||||||
}
|
}
|
||||||
|
|
||||||
latest_release_tag() {
|
release_source_ref() {
|
||||||
[ -n "$repo" ] || return 1
|
if [ -n "$binary_url" ] || [ -n "$binary_base" ]; then
|
||||||
web_base="$(repo_web_base "$repo")" || return 1
|
|
||||||
latest_url="$(curl -fsSL -o /dev/null -w '%{url_effective}' "$web_base/releases/latest" 2>/dev/null || true)"
|
|
||||||
case "$latest_url" in
|
|
||||||
"$web_base"/releases/tag/*)
|
|
||||||
tag="${latest_url##"$web_base"/releases/tag/}"
|
|
||||||
[ -n "$tag" ] || return 1
|
|
||||||
printf '%s\n' "$tag"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
latest_release_is_stale() {
|
|
||||||
if [ -n "$binary_url" ] || [ -n "$binary_base" ] || [ "$binary_version" != "latest" ]; then
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
latest="$(latest_release_tag || true)"
|
if [ "$binary_version" != "latest" ] && [ "$binary_exact" = "1" ]; then
|
||||||
|
printf '%s\n' "$binary_version"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
current="$(current_source_version || true)"
|
current="$(current_source_version || true)"
|
||||||
[ -n "$latest" ] && [ -n "$current" ] || return 1
|
if [ -n "$current" ]; then
|
||||||
latest="${latest#v}"
|
printf 'v%s\n' "${current#v}"
|
||||||
if version_less_than "$latest" "$current"; then
|
return 0
|
||||||
echo "latest release $latest is older than source $current; skipping stale prebuilt" >&2
|
fi
|
||||||
|
if [ "$binary_version" != "latest" ]; then
|
||||||
|
printf '%s\n' "$binary_version"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
@@ -450,10 +359,8 @@ verify_archive_version() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try_install_prebuilt() {
|
try_install_prebuilt() {
|
||||||
if latest_release_is_stale; then
|
download_url="$(release_download_url)" || return 1
|
||||||
return 1
|
resolved_source_ref="$(release_source_ref || true)"
|
||||||
fi
|
|
||||||
download_url="$(release_latest_tag_download_url || release_download_url)" || return 1
|
|
||||||
tmpdir="$(mktemp -d)"
|
tmpdir="$(mktemp -d)"
|
||||||
archive="$tmpdir/$(release_artifact_name)"
|
archive="$tmpdir/$(release_artifact_name)"
|
||||||
checksum_file="$archive.sha256"
|
checksum_file="$archive.sha256"
|
||||||
@@ -490,7 +397,11 @@ try_install_prebuilt() {
|
|||||||
|
|
||||||
install_from_source() {
|
install_from_source() {
|
||||||
ensure_cargo
|
ensure_cargo
|
||||||
if [ "$from_current" -eq 1 ] || [ -f Cargo.toml ]; then
|
if [ "$from_current" -eq 1 ]; then
|
||||||
|
[ -f Cargo.toml ] || {
|
||||||
|
echo "--from-current requires a Dosh checkout with Cargo.toml" >&2
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
src_dir="$(pwd)"
|
src_dir="$(pwd)"
|
||||||
else
|
else
|
||||||
if [ -z "$repo" ]; then
|
if [ -z "$repo" ]; then
|
||||||
@@ -500,22 +411,27 @@ install_from_source() {
|
|||||||
update_cache="$(safe_update_cache_path "$update_cache")"
|
update_cache="$(safe_update_cache_path "$update_cache")"
|
||||||
need git
|
need git
|
||||||
mkdir -p "$(dirname "$update_cache")"
|
mkdir -p "$(dirname "$update_cache")"
|
||||||
|
source_ref="${resolved_source_ref:-main}"
|
||||||
if [ -d "$update_cache/.git" ]; then
|
if [ -d "$update_cache/.git" ]; then
|
||||||
[ "$quiet" != "1" ] && echo "Updating Dosh source"
|
[ "$quiet" != "1" ] && echo "Updating Dosh source"
|
||||||
git -C "$update_cache" remote set-url origin "$repo"
|
git -C "$update_cache" remote set-url origin "$repo"
|
||||||
if [ "$quiet" = "1" ]; then
|
if [ "$quiet" = "1" ]; then
|
||||||
git -C "$update_cache" fetch -q --depth 1 origin main
|
git -C "$update_cache" fetch -q --depth 1 origin "$source_ref"
|
||||||
else
|
else
|
||||||
git -C "$update_cache" fetch --depth 1 origin main
|
git -C "$update_cache" fetch --depth 1 origin "$source_ref"
|
||||||
|
fi
|
||||||
|
if [ "$source_ref" = "main" ]; then
|
||||||
|
git -C "$update_cache" checkout -q -B main FETCH_HEAD
|
||||||
|
else
|
||||||
|
git -C "$update_cache" checkout -q --detach FETCH_HEAD
|
||||||
fi
|
fi
|
||||||
git -C "$update_cache" checkout -q -B main FETCH_HEAD
|
|
||||||
else
|
else
|
||||||
[ "$quiet" != "1" ] && echo "Downloading Dosh source"
|
[ "$quiet" != "1" ] && echo "Downloading Dosh source"
|
||||||
rm -rf "$update_cache"
|
rm -rf "$update_cache"
|
||||||
if [ "$quiet" = "1" ]; then
|
if [ "$quiet" = "1" ]; then
|
||||||
git clone -q --depth 1 --branch main "$repo" "$update_cache" >/dev/null
|
git clone -q --depth 1 --branch "$source_ref" "$repo" "$update_cache" >/dev/null
|
||||||
else
|
else
|
||||||
git clone --depth 1 --branch main "$repo" "$update_cache" >/dev/null
|
git clone --depth 1 --branch "$source_ref" "$repo" "$update_cache" >/dev/null
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
src_dir="$update_cache"
|
src_dir="$update_cache"
|
||||||
|
|||||||
@@ -0,0 +1,168 @@
|
|||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
$ProgressPreference = "SilentlyContinue"
|
||||||
|
|
||||||
|
$version = "9.8.7-rc3"
|
||||||
|
$root = Join-Path ([System.IO.Path]::GetTempPath()) ("dosh-installer-test-" + [guid]::NewGuid())
|
||||||
|
$webRoot = Join-Path $root "web"
|
||||||
|
$repoRoot = Join-Path $webRoot "repo"
|
||||||
|
$releaseRoot = Join-Path $repoRoot "releases\download\v$version"
|
||||||
|
$rawRoot = Join-Path $repoRoot "raw\branch\main"
|
||||||
|
$stageRoot = Join-Path $root "stage\dosh"
|
||||||
|
$requestLog = Join-Path $root "requests.log"
|
||||||
|
$prefix = Join-Path $root "prefix"
|
||||||
|
$home = Join-Path $root "home"
|
||||||
|
$unrelated = Join-Path $root "unrelated"
|
||||||
|
$job = $null
|
||||||
|
$savedBinaryVersion = $env:DOSH_BINARY_VERSION
|
||||||
|
$savedBinaryExact = $env:DOSH_BINARY_EXACT
|
||||||
|
|
||||||
|
function Invoke-TestInstaller($HomePath, $WorkingDirectory, $InstallPrefix, $Repository) {
|
||||||
|
$savedHome = $env:HOME
|
||||||
|
$savedUserProfile = $env:USERPROFILE
|
||||||
|
try {
|
||||||
|
$env:HOME = $HomePath
|
||||||
|
$env:USERPROFILE = $HomePath
|
||||||
|
Push-Location $WorkingDirectory
|
||||||
|
try {
|
||||||
|
$powershell = (Get-Process -Id $PID).Path
|
||||||
|
& $powershell -NoProfile -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot "..\install.ps1") -Role client -Repo $Repository -Prefix $InstallPrefix -BinaryRequired
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
throw "Windows installer exited with status $LASTEXITCODE"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
$env:HOME = $savedHome
|
||||||
|
$env:USERPROFILE = $savedUserProfile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
New-Item -ItemType Directory -Force -Path $releaseRoot, $rawRoot, (Join-Path $stageRoot "bin"), $home, $unrelated | Out-Null
|
||||||
|
@"
|
||||||
|
[package]
|
||||||
|
name = "dosh"
|
||||||
|
version = "$version"
|
||||||
|
"@ | Set-Content -Encoding ascii -NoNewline (Join-Path $rawRoot "Cargo.toml")
|
||||||
|
@"
|
||||||
|
[package]
|
||||||
|
name = "not-dosh"
|
||||||
|
version = "99.0.0"
|
||||||
|
"@ | Set-Content -Encoding ascii -NoNewline (Join-Path $unrelated "Cargo.toml")
|
||||||
|
"$version`n" | Set-Content -Encoding ascii -NoNewline (Join-Path $stageRoot "VERSION")
|
||||||
|
"fixture" | Set-Content -Encoding ascii -NoNewline (Join-Path $stageRoot "bin\dosh-client.exe")
|
||||||
|
|
||||||
|
$archive = Join-Path $releaseRoot "dosh-windows-x86_64.zip"
|
||||||
|
Compress-Archive -Force -Path $stageRoot -DestinationPath $archive
|
||||||
|
$digest = (Get-FileHash -Algorithm SHA256 $archive).Hash.ToLowerInvariant()
|
||||||
|
"$digest dosh-windows-x86_64.zip`n" | Set-Content -Encoding ascii -NoNewline "$archive.sha256"
|
||||||
|
|
||||||
|
$probe = [System.Net.Sockets.TcpListener]::new([System.Net.IPAddress]::Loopback, 0)
|
||||||
|
$probe.Start()
|
||||||
|
$port = ([System.Net.IPEndPoint]$probe.LocalEndpoint).Port
|
||||||
|
$probe.Stop()
|
||||||
|
$listenPrefix = "http://127.0.0.1:$port/"
|
||||||
|
$job = Start-Job -ArgumentList $webRoot, $listenPrefix, $requestLog -ScriptBlock {
|
||||||
|
param($Root, $Prefix, $Log)
|
||||||
|
$listener = [System.Net.HttpListener]::new()
|
||||||
|
$listener.Prefixes.Add($Prefix)
|
||||||
|
$listener.Start()
|
||||||
|
try {
|
||||||
|
while ($listener.IsListening) {
|
||||||
|
$context = $listener.GetContext()
|
||||||
|
$path = [System.Uri]::UnescapeDataString($context.Request.Url.AbsolutePath.TrimStart('/'))
|
||||||
|
Add-Content -Encoding ascii -Path $Log -Value $context.Request.Url.AbsolutePath
|
||||||
|
$file = Join-Path $Root ($path.Replace('/', [System.IO.Path]::DirectorySeparatorChar))
|
||||||
|
if (Test-Path -LiteralPath $file -PathType Leaf) {
|
||||||
|
$bytes = [System.IO.File]::ReadAllBytes($file)
|
||||||
|
$context.Response.StatusCode = 200
|
||||||
|
$context.Response.ContentLength64 = $bytes.Length
|
||||||
|
if ($context.Request.HttpMethod -ne "HEAD") {
|
||||||
|
$context.Response.OutputStream.Write($bytes, 0, $bytes.Length)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$context.Response.StatusCode = 404
|
||||||
|
}
|
||||||
|
$context.Response.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
$listener.Stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$ready = $false
|
||||||
|
for ($attempt = 0; $attempt -lt 50; $attempt++) {
|
||||||
|
try {
|
||||||
|
Invoke-WebRequest -UseBasicParsing -Uri "${listenPrefix}repo/raw/branch/main/Cargo.toml" | Out-Null
|
||||||
|
$ready = $true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Start-Sleep -Milliseconds 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (-not $ready) {
|
||||||
|
throw "installer fixture HTTP server did not start"
|
||||||
|
}
|
||||||
|
|
||||||
|
$env:DOSH_BINARY_VERSION = "v0.1.17"
|
||||||
|
Remove-Item Env:DOSH_BINARY_EXACT -ErrorAction SilentlyContinue
|
||||||
|
Invoke-TestInstaller $home $unrelated $prefix "${listenPrefix}repo.git"
|
||||||
|
|
||||||
|
if (-not (Test-Path (Join-Path $prefix "bin\dosh-client.exe"))) {
|
||||||
|
throw "Windows installer did not install dosh-client.exe"
|
||||||
|
}
|
||||||
|
$requests = Get-Content $requestLog -Raw
|
||||||
|
if ($requests -notmatch "/repo/raw/branch/main/Cargo.toml") {
|
||||||
|
throw "Windows installer did not read the repository release version"
|
||||||
|
}
|
||||||
|
if ($requests -notmatch "/repo/releases/download/v$([regex]::Escape($version))/dosh-windows-x86_64.zip") {
|
||||||
|
throw "Windows installer did not request the repository-declared release artifact"
|
||||||
|
}
|
||||||
|
if ($requests -match "/releases/latest" -or $requests -match "99.0.0") {
|
||||||
|
throw "Windows installer used a stable redirect or unrelated Cargo.toml"
|
||||||
|
}
|
||||||
|
|
||||||
|
"fixture-v2" | Set-Content -Encoding ascii -NoNewline (Join-Path $stageRoot "bin\dosh-client.exe")
|
||||||
|
Compress-Archive -Force -Path $stageRoot -DestinationPath $archive
|
||||||
|
$digest = (Get-FileHash -Algorithm SHA256 $archive).Hash.ToLowerInvariant()
|
||||||
|
"$digest dosh-windows-x86_64.zip`n" | Set-Content -Encoding ascii -NoNewline "$archive.sha256"
|
||||||
|
|
||||||
|
$installedAlias = Join-Path $prefix "bin\dosh.exe"
|
||||||
|
$lock = [System.IO.File]::Open($installedAlias, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::None)
|
||||||
|
try {
|
||||||
|
Invoke-TestInstaller $home $unrelated $prefix "${listenPrefix}repo.git"
|
||||||
|
$pending = @(Get-ChildItem (Join-Path $prefix "bin") -Filter "dosh.exe.pending.*")
|
||||||
|
if ($pending.Count -ne 1) {
|
||||||
|
throw "locked Windows executable was not staged exactly once"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
$lock.Dispose()
|
||||||
|
}
|
||||||
|
$replaced = $false
|
||||||
|
for ($attempt = 0; $attempt -lt 100; $attempt++) {
|
||||||
|
if ((Get-Content $installedAlias -Raw) -eq "fixture-v2" -and -not (Get-ChildItem (Join-Path $prefix "bin") -Filter "dosh.exe.pending.*")) {
|
||||||
|
$replaced = $true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
Start-Sleep -Milliseconds 100
|
||||||
|
}
|
||||||
|
if (-not $replaced) {
|
||||||
|
throw "staged Windows executable was not applied after its lock was released"
|
||||||
|
}
|
||||||
|
Write-Host "Windows installer runtime test passed"
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
$env:DOSH_BINARY_VERSION = $savedBinaryVersion
|
||||||
|
$env:DOSH_BINARY_EXACT = $savedBinaryExact
|
||||||
|
if ($job) {
|
||||||
|
Stop-Job $job -ErrorAction SilentlyContinue
|
||||||
|
Remove-Job $job -Force -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
Remove-Item -Recurse -Force $root -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
+450
-257
File diff suppressed because it is too large
Load Diff
+132
-38
@@ -27,7 +27,9 @@ use dosh::protocol::{
|
|||||||
StreamClose, StreamData, StreamEof, StreamOpen, StreamOpenOk, StreamOpenReject,
|
StreamClose, StreamData, StreamEof, StreamOpen, StreamOpenOk, StreamOpenReject,
|
||||||
StreamWindowAdjust, TicketAttachBody, TicketAttachEnvelope, TicketAttachOkEnvelope,
|
StreamWindowAdjust, TicketAttachBody, TicketAttachEnvelope, TicketAttachOkEnvelope,
|
||||||
};
|
};
|
||||||
use dosh::pty::{PtyHandle, PtyOutput, adopt_pty_from_fd, spawn_pty_session};
|
use dosh::pty::{
|
||||||
|
PTY_OUTPUT_QUEUE_CAPACITY, PtyHandle, PtyOutput, adopt_pty_from_fd, spawn_pty_session,
|
||||||
|
};
|
||||||
use dosh::udp::{is_transient_udp_error, is_transient_udp_send_error};
|
use dosh::udp::{is_transient_udp_error, is_transient_udp_send_error};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
|
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
|
||||||
@@ -209,7 +211,7 @@ async fn serve(config_path: Option<std::path::PathBuf>) -> Result<()> {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
let (pty_tx, mut pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, mut pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let state = Arc::new(Mutex::new(ServerState::new(
|
let state = Arc::new(Mutex::new(ServerState::new(
|
||||||
config.clone(),
|
config.clone(),
|
||||||
secret,
|
secret,
|
||||||
@@ -242,6 +244,7 @@ async fn serve(config_path: Option<std::path::PathBuf>) -> Result<()> {
|
|||||||
let retransmit_socket = Arc::clone(&socket);
|
let retransmit_socket = Arc::clone(&socket);
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut interval = tokio::time::interval(Duration::from_millis(100));
|
let mut interval = tokio::time::interval(Duration::from_millis(100));
|
||||||
|
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
|
||||||
loop {
|
loop {
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
if let Err(err) = retransmit_pending(&retransmit_state, &retransmit_socket).await {
|
if let Err(err) = retransmit_pending(&retransmit_state, &retransmit_socket).await {
|
||||||
@@ -256,6 +259,7 @@ async fn serve(config_path: Option<std::path::PathBuf>) -> Result<()> {
|
|||||||
let cleanup_state = Arc::clone(&state);
|
let cleanup_state = Arc::clone(&state);
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut interval = tokio::time::interval(Duration::from_secs(5));
|
let mut interval = tokio::time::interval(Duration::from_secs(5));
|
||||||
|
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
|
||||||
loop {
|
loop {
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
cleanup_disconnected_clients(&cleanup_state);
|
cleanup_disconnected_clients(&cleanup_state);
|
||||||
@@ -270,6 +274,7 @@ async fn serve(config_path: Option<std::path::PathBuf>) -> Result<()> {
|
|||||||
let flush_state = Arc::clone(&state);
|
let flush_state = Arc::clone(&state);
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut interval = tokio::time::interval(SCREEN_PERSIST_MAX_AGE);
|
let mut interval = tokio::time::interval(SCREEN_PERSIST_MAX_AGE);
|
||||||
|
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
|
||||||
loop {
|
loop {
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
flush_persistent_screens(&flush_state);
|
flush_persistent_screens(&flush_state);
|
||||||
@@ -293,7 +298,7 @@ async fn serve(config_path: Option<std::path::PathBuf>) -> Result<()> {
|
|||||||
struct ServerState {
|
struct ServerState {
|
||||||
config: ServerConfig,
|
config: ServerConfig,
|
||||||
secret: [u8; 32],
|
secret: [u8; 32],
|
||||||
pty_tx: mpsc::UnboundedSender<PtyOutput>,
|
pty_tx: mpsc::Sender<PtyOutput>,
|
||||||
sessions: HashMap<String, Session>,
|
sessions: HashMap<String, Session>,
|
||||||
pending_native: HashMap<[u8; 16], PendingNativeAuth>,
|
pending_native: HashMap<[u8; 16], PendingNativeAuth>,
|
||||||
next_server_stream_id: u64,
|
next_server_stream_id: u64,
|
||||||
@@ -393,6 +398,10 @@ struct Session {
|
|||||||
holder_control: Option<StdUnixStream>,
|
holder_control: Option<StdUnixStream>,
|
||||||
/// Whether this session's shell lives in a holder process (persistent).
|
/// Whether this session's shell lives in a holder process (persistent).
|
||||||
persistent: bool,
|
persistent: bool,
|
||||||
|
/// The holder survived a server restart but no client has reattached yet.
|
||||||
|
/// Such sessions need the full reconnect window because the client may be
|
||||||
|
/// asleep during an unattended server update.
|
||||||
|
restart_orphaned: bool,
|
||||||
/// Bytes of session output since the screen was last mirrored to disk, used
|
/// Bytes of session output since the screen was last mirrored to disk, used
|
||||||
/// to throttle the (atomic) screen-persistence writes.
|
/// to throttle the (atomic) screen-persistence writes.
|
||||||
bytes_since_persist: usize,
|
bytes_since_persist: usize,
|
||||||
@@ -504,7 +513,7 @@ impl ServerState {
|
|||||||
fn new(
|
fn new(
|
||||||
config: ServerConfig,
|
config: ServerConfig,
|
||||||
secret: [u8; 32],
|
secret: [u8; 32],
|
||||||
pty_tx: mpsc::UnboundedSender<PtyOutput>,
|
pty_tx: mpsc::Sender<PtyOutput>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let per_minute = config.native_auth_rate_limit_per_minute;
|
let per_minute = config.native_auth_rate_limit_per_minute;
|
||||||
Self {
|
Self {
|
||||||
@@ -564,6 +573,7 @@ impl ServerState {
|
|||||||
empty_since: None,
|
empty_since: None,
|
||||||
holder_control: control,
|
holder_control: control,
|
||||||
persistent,
|
persistent,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 0,
|
last_persisted_seq: 0,
|
||||||
last_screen_persist_at: Instant::now() - SCREEN_PERSIST_MAX_AGE,
|
last_screen_persist_at: Instant::now() - SCREEN_PERSIST_MAX_AGE,
|
||||||
@@ -709,6 +719,7 @@ impl ServerState {
|
|||||||
empty_since: Some(Instant::now()),
|
empty_since: Some(Instant::now()),
|
||||||
holder_control: Some(control),
|
holder_control: Some(control),
|
||||||
persistent: true,
|
persistent: true,
|
||||||
|
restart_orphaned: true,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: output_seq,
|
last_persisted_seq: output_seq,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -727,6 +738,7 @@ impl ServerState {
|
|||||||
if let Some(session) = self.sessions.get_mut(session_name) {
|
if let Some(session) = self.sessions.get_mut(session_name) {
|
||||||
session.clients.insert(client_id, client);
|
session.clients.insert(client_id, client);
|
||||||
session.empty_since = None;
|
session.empty_since = None;
|
||||||
|
session.restart_orphaned = false;
|
||||||
self.client_index
|
self.client_index
|
||||||
.insert(client_id, session_name.to_string());
|
.insert(client_id, session_name.to_string());
|
||||||
}
|
}
|
||||||
@@ -3266,15 +3278,25 @@ async fn run_exec_stream_service(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let output = TokioCommand::new("sh")
|
let shell = {
|
||||||
.arg("-lc")
|
state
|
||||||
|
.lock()
|
||||||
|
.expect("server state poisoned")
|
||||||
|
.config
|
||||||
|
.shell
|
||||||
|
.clone()
|
||||||
|
};
|
||||||
|
let output = TokioCommand::new(&shell)
|
||||||
|
.arg("-c")
|
||||||
.arg(&request.command)
|
.arg(&request.command)
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.output()
|
.output()
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("run command {:?}", request.command))?;
|
.with_context(|| {
|
||||||
|
format!("run command {:?} with shell {shell}", request.command)
|
||||||
|
})?;
|
||||||
for chunk in output.stdout.chunks(CHUNK_SIZE) {
|
for chunk in output.stdout.chunks(CHUNK_SIZE) {
|
||||||
send_exec_response_to_client(
|
send_exec_response_to_client(
|
||||||
&state,
|
&state,
|
||||||
@@ -4442,7 +4464,8 @@ fn cleanup_disconnected_clients(state: &Arc<Mutex<ServerState>>) {
|
|||||||
.filter(|(name, session)| {
|
.filter(|(name, session)| {
|
||||||
!prewarm.contains(name.as_str())
|
!prewarm.contains(name.as_str())
|
||||||
&& session.empty_since.is_some_and(|since| {
|
&& session.empty_since.is_some_and(|since| {
|
||||||
now.duration_since(since) >= empty_session_timeout(name, timeout)
|
now.duration_since(since)
|
||||||
|
>= empty_session_timeout(name, timeout, session.restart_orphaned)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.map(|(name, _)| name.clone())
|
.map(|(name, _)| name.clone())
|
||||||
@@ -4462,8 +4485,12 @@ fn cleanup_disconnected_clients(state: &Arc<Mutex<ServerState>>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn empty_session_timeout(name: &str, configured_timeout: Duration) -> Duration {
|
fn empty_session_timeout(
|
||||||
if protocol::is_implicit_session_name(name) {
|
name: &str,
|
||||||
|
configured_timeout: Duration,
|
||||||
|
restart_orphaned: bool,
|
||||||
|
) -> Duration {
|
||||||
|
if protocol::is_implicit_session_name(name) && !restart_orphaned {
|
||||||
configured_timeout.min(Duration::from_secs(IMPLICIT_EMPTY_SESSION_GRACE_SECS))
|
configured_timeout.min(Duration::from_secs(IMPLICIT_EMPTY_SESSION_GRACE_SECS))
|
||||||
} else {
|
} else {
|
||||||
configured_timeout
|
configured_timeout
|
||||||
@@ -4517,7 +4544,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn persists_terminal_sessions_when_enabled() {
|
fn persists_terminal_sessions_when_enabled() {
|
||||||
let (pty_tx, _rx) = mpsc::unbounded_channel();
|
let (pty_tx, _rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let config = ServerConfig {
|
let config = ServerConfig {
|
||||||
persist_sessions: true,
|
persist_sessions: true,
|
||||||
prewarm_sessions: vec!["default".to_string()],
|
prewarm_sessions: vec!["default".to_string()],
|
||||||
@@ -4531,7 +4558,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn persist_disabled_never_persists() {
|
fn persist_disabled_never_persists() {
|
||||||
let (pty_tx, _rx) = mpsc::unbounded_channel();
|
let (pty_tx, _rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let config = ServerConfig {
|
let config = ServerConfig {
|
||||||
persist_sessions: false,
|
persist_sessions: false,
|
||||||
prewarm_sessions: vec!["default".to_string()],
|
prewarm_sessions: vec!["default".to_string()],
|
||||||
@@ -4608,6 +4635,7 @@ mod tests {
|
|||||||
empty_since: Some(Instant::now()),
|
empty_since: Some(Instant::now()),
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: true,
|
persistent: true,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 7,
|
last_persisted_seq: 7,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -4635,6 +4663,7 @@ mod tests {
|
|||||||
empty_since: Some(Instant::now()),
|
empty_since: Some(Instant::now()),
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: true,
|
persistent: true,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 7,
|
last_persisted_seq: 7,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -4655,7 +4684,7 @@ mod tests {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn no_client_pty_output_before_first_reattach_keeps_restored_screen() {
|
async fn no_client_pty_output_before_first_reattach_keeps_restored_screen() {
|
||||||
let restored = b"\x1b[?1049lRESTORED_AFTER_RESTART".to_vec();
|
let restored = b"\x1b[?1049lRESTORED_AFTER_RESTART".to_vec();
|
||||||
let (pty_tx, _rx) = mpsc::unbounded_channel();
|
let (pty_tx, _rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let state = Arc::new(Mutex::new(ServerState::new(
|
let state = Arc::new(Mutex::new(ServerState::new(
|
||||||
ServerConfig {
|
ServerConfig {
|
||||||
persist_sessions: true,
|
persist_sessions: true,
|
||||||
@@ -4682,6 +4711,7 @@ mod tests {
|
|||||||
empty_since: Some(Instant::now()),
|
empty_since: Some(Instant::now()),
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: true,
|
persistent: true,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 7,
|
last_persisted_seq: 7,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -4733,7 +4763,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn unknown_resume_reject_keeps_client_id() {
|
async fn unknown_resume_reject_keeps_client_id() {
|
||||||
let (pty_tx, _rx) = mpsc::unbounded_channel();
|
let (pty_tx, _rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let state = Arc::new(Mutex::new(ServerState::new(
|
let state = Arc::new(Mutex::new(ServerState::new(
|
||||||
ServerConfig::default(),
|
ServerConfig::default(),
|
||||||
[0u8; 32],
|
[0u8; 32],
|
||||||
@@ -4957,7 +4987,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn client_index_stays_in_sync_with_session_clients() {
|
fn client_index_stays_in_sync_with_session_clients() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
state
|
state
|
||||||
.ensure_session("work", 80, 24, "forward-only", &[])
|
.ensure_session("work", 80, 24, "forward-only", &[])
|
||||||
@@ -5004,7 +5034,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cleanup_purges_timed_out_clients_from_index() {
|
fn cleanup_purges_timed_out_clients_from_index() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let config = ServerConfig {
|
let config = ServerConfig {
|
||||||
client_timeout_secs: 1,
|
client_timeout_secs: 1,
|
||||||
..ServerConfig::default()
|
..ServerConfig::default()
|
||||||
@@ -5031,28 +5061,79 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn implicit_empty_session_timeout_is_bounded_for_update_reconnect() {
|
fn implicit_empty_session_timeout_preserves_restart_orphans() {
|
||||||
let configured = Duration::from_secs(2_592_000);
|
let configured = Duration::from_secs(2_592_000);
|
||||||
let implicit = protocol::generate_implicit_session_name();
|
let implicit = protocol::generate_implicit_session_name();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
empty_session_timeout(&implicit, configured),
|
empty_session_timeout(&implicit, configured, false),
|
||||||
Duration::from_secs(IMPLICIT_EMPTY_SESSION_GRACE_SECS)
|
Duration::from_secs(IMPLICIT_EMPTY_SESSION_GRACE_SECS)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
empty_session_timeout("work", configured),
|
empty_session_timeout(&implicit, configured, true),
|
||||||
|
configured,
|
||||||
|
"a sleeping client must retain its restart-surviving shell"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
empty_session_timeout("work", configured, false),
|
||||||
configured,
|
configured,
|
||||||
"named sessions keep the normal long timeout"
|
"named sessions keep the normal long timeout"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
empty_session_timeout(&implicit, Duration::from_secs(1)),
|
empty_session_timeout(&implicit, Duration::from_secs(1), false),
|
||||||
Duration::from_secs(1),
|
Duration::from_secs(1),
|
||||||
"tests/admins can still configure a shorter timeout"
|
"tests/admins can still configure a shorter timeout"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cleanup_keeps_restart_orphan_then_reaps_after_reattach_disconnect() {
|
||||||
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
|
let mut state = ServerState::new(
|
||||||
|
ServerConfig {
|
||||||
|
client_timeout_secs: 2_592_000,
|
||||||
|
prewarm_sessions: Vec::new(),
|
||||||
|
..ServerConfig::default()
|
||||||
|
},
|
||||||
|
[0u8; 32],
|
||||||
|
pty_tx,
|
||||||
|
);
|
||||||
|
let implicit = protocol::generate_implicit_session_name();
|
||||||
|
state
|
||||||
|
.ensure_session(&implicit, 80, 24, "forward-only", &[])
|
||||||
|
.unwrap();
|
||||||
|
{
|
||||||
|
let session = state.sessions.get_mut(&implicit).unwrap();
|
||||||
|
session.empty_since = Some(
|
||||||
|
Instant::now()
|
||||||
|
- Duration::from_secs(IMPLICIT_EMPTY_SESSION_GRACE_SECS + 10),
|
||||||
|
);
|
||||||
|
session.restart_orphaned = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let state = Arc::new(Mutex::new(state));
|
||||||
|
cleanup_disconnected_clients(&state);
|
||||||
|
assert!(
|
||||||
|
state.lock().unwrap().sessions.contains_key(&implicit),
|
||||||
|
"restart orphan was reaped before the reconnect timeout"
|
||||||
|
);
|
||||||
|
|
||||||
|
state
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.sessions
|
||||||
|
.get_mut(&implicit)
|
||||||
|
.unwrap()
|
||||||
|
.restart_orphaned = false;
|
||||||
|
cleanup_disconnected_clients(&state);
|
||||||
|
assert!(
|
||||||
|
!state.lock().unwrap().sessions.contains_key(&implicit),
|
||||||
|
"ordinary abandoned implicit session was not reaped"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn forged_plaintext_detach_does_not_remove_client() {
|
async fn forged_plaintext_detach_does_not_remove_client() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
state
|
state
|
||||||
.ensure_session("work", 80, 24, "forward-only", &[])
|
.ensure_session("work", 80, 24, "forward-only", &[])
|
||||||
@@ -5078,7 +5159,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn authenticated_detach_removes_client() {
|
async fn authenticated_detach_removes_client() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
state
|
state
|
||||||
.ensure_session("work", 80, 24, "forward-only", &[])
|
.ensure_session("work", 80, 24, "forward-only", &[])
|
||||||
@@ -5109,7 +5190,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn duplicate_stream_open_for_open_stream_resends_ok() {
|
async fn duplicate_stream_open_for_open_stream_resends_ok() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
let client_id = [11u8; 16];
|
let client_id = [11u8; 16];
|
||||||
let session_key = [12u8; 32];
|
let session_key = [12u8; 32];
|
||||||
@@ -5131,6 +5212,7 @@ mod tests {
|
|||||||
empty_since: None,
|
empty_since: None,
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 0,
|
last_persisted_seq: 0,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -5173,7 +5255,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn retired_stream_open_is_rejected_not_reopened() {
|
async fn retired_stream_open_is_rejected_not_reopened() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
let client_id = [15u8; 16];
|
let client_id = [15u8; 16];
|
||||||
let session_key = [16u8; 32];
|
let session_key = [16u8; 32];
|
||||||
@@ -5196,6 +5278,7 @@ mod tests {
|
|||||||
empty_since: None,
|
empty_since: None,
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 0,
|
last_persisted_seq: 0,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -5243,7 +5326,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn pending_server_stream_open_is_retransmitted() {
|
async fn pending_server_stream_open_is_retransmitted() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
let client_id = [13u8; 16];
|
let client_id = [13u8; 16];
|
||||||
let session_key = [14u8; 32];
|
let session_key = [14u8; 32];
|
||||||
@@ -5273,6 +5356,7 @@ mod tests {
|
|||||||
empty_since: None,
|
empty_since: None,
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 0,
|
last_persisted_seq: 0,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -5298,7 +5382,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn server_stream_retransmit_uses_observed_rtt() {
|
async fn server_stream_retransmit_uses_observed_rtt() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
let client_id = [15u8; 16];
|
let client_id = [15u8; 16];
|
||||||
let session_key = [16u8; 32];
|
let session_key = [16u8; 32];
|
||||||
@@ -5332,6 +5416,7 @@ mod tests {
|
|||||||
empty_since: None,
|
empty_since: None,
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 0,
|
last_persisted_seq: 0,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -5357,7 +5442,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn forward_only_session_does_not_allocate_pty() {
|
fn forward_only_session_does_not_allocate_pty() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
|
|
||||||
state
|
state
|
||||||
@@ -5369,7 +5454,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cleanup_reaps_abandoned_sessions_but_keeps_prewarmed() {
|
fn cleanup_reaps_abandoned_sessions_but_keeps_prewarmed() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let config = ServerConfig {
|
let config = ServerConfig {
|
||||||
client_timeout_secs: 1,
|
client_timeout_secs: 1,
|
||||||
prewarm_sessions: vec!["default".to_string()],
|
prewarm_sessions: vec!["default".to_string()],
|
||||||
@@ -5454,7 +5539,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn stream_data_waits_for_open_and_credit() {
|
async fn stream_data_waits_for_open_and_credit() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
let client_id = [7u8; 16];
|
let client_id = [7u8; 16];
|
||||||
let session_key = [9u8; 32];
|
let session_key = [9u8; 32];
|
||||||
@@ -5509,6 +5594,7 @@ mod tests {
|
|||||||
empty_since: None,
|
empty_since: None,
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 0,
|
last_persisted_seq: 0,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -5558,7 +5644,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn stream_eof_to_client_does_not_retire_stream() {
|
async fn stream_eof_to_client_does_not_retire_stream() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
let client_id = [13u8; 16];
|
let client_id = [13u8; 16];
|
||||||
let session_key = [14u8; 32];
|
let session_key = [14u8; 32];
|
||||||
@@ -5613,6 +5699,7 @@ mod tests {
|
|||||||
empty_since: None,
|
empty_since: None,
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 0,
|
last_persisted_seq: 0,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -5647,7 +5734,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn pending_server_stream_eof_is_retransmitted() {
|
async fn pending_server_stream_eof_is_retransmitted() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
let client_id = [17u8; 16];
|
let client_id = [17u8; 16];
|
||||||
let session_key = [18u8; 32];
|
let session_key = [18u8; 32];
|
||||||
@@ -5678,6 +5765,7 @@ mod tests {
|
|||||||
empty_since: None,
|
empty_since: None,
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 0,
|
last_persisted_seq: 0,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -5707,7 +5795,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn pending_server_stream_close_is_retransmitted() {
|
async fn pending_server_stream_close_is_retransmitted() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
let client_id = [19u8; 16];
|
let client_id = [19u8; 16];
|
||||||
let session_key = [20u8; 32];
|
let session_key = [20u8; 32];
|
||||||
@@ -5735,6 +5823,7 @@ mod tests {
|
|||||||
empty_since: None,
|
empty_since: None,
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 0,
|
last_persisted_seq: 0,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -5763,7 +5852,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn pending_server_stream_close_expires_after_attempt_cap() {
|
async fn pending_server_stream_close_expires_after_attempt_cap() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
let client_id = [21u8; 16];
|
let client_id = [21u8; 16];
|
||||||
let session_key = [22u8; 32];
|
let session_key = [22u8; 32];
|
||||||
@@ -5791,6 +5880,7 @@ mod tests {
|
|||||||
empty_since: None,
|
empty_since: None,
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 0,
|
last_persisted_seq: 0,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -5808,7 +5898,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn pending_server_stream_window_adjust_is_retransmitted() {
|
async fn pending_server_stream_window_adjust_is_retransmitted() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
let client_id = [23u8; 16];
|
let client_id = [23u8; 16];
|
||||||
let session_key = [24u8; 32];
|
let session_key = [24u8; 32];
|
||||||
@@ -5838,6 +5928,7 @@ mod tests {
|
|||||||
empty_since: None,
|
empty_since: None,
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 0,
|
last_persisted_seq: 0,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -5871,7 +5962,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn pending_server_stream_window_adjust_expires_after_attempt_cap() {
|
async fn pending_server_stream_window_adjust_expires_after_attempt_cap() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
let client_id = [25u8; 16];
|
let client_id = [25u8; 16];
|
||||||
let session_key = [26u8; 32];
|
let session_key = [26u8; 32];
|
||||||
@@ -5901,6 +5992,7 @@ mod tests {
|
|||||||
empty_since: None,
|
empty_since: None,
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 0,
|
last_persisted_seq: 0,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -5922,7 +6014,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn server_stream_send_splits_large_writes() {
|
async fn server_stream_send_splits_large_writes() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
let client_id = [11u8; 16];
|
let client_id = [11u8; 16];
|
||||||
let session_key = [12u8; 32];
|
let session_key = [12u8; 32];
|
||||||
@@ -5977,6 +6069,7 @@ mod tests {
|
|||||||
empty_since: None,
|
empty_since: None,
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 0,
|
last_persisted_seq: 0,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -6029,7 +6122,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn blocked_stream_data_does_not_block_terminal_frames() {
|
async fn blocked_stream_data_does_not_block_terminal_frames() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
let mut state = ServerState::new(ServerConfig::default(), [0u8; 32], pty_tx);
|
||||||
let client_id = [8u8; 16];
|
let client_id = [8u8; 16];
|
||||||
let session_key = [10u8; 32];
|
let session_key = [10u8; 32];
|
||||||
@@ -6084,6 +6177,7 @@ mod tests {
|
|||||||
empty_since: None,
|
empty_since: None,
|
||||||
holder_control: None,
|
holder_control: None,
|
||||||
persistent: false,
|
persistent: false,
|
||||||
|
restart_orphaned: false,
|
||||||
bytes_since_persist: 0,
|
bytes_since_persist: 0,
|
||||||
last_persisted_seq: 0,
|
last_persisted_seq: 0,
|
||||||
last_screen_persist_at: Instant::now(),
|
last_screen_persist_at: Instant::now(),
|
||||||
@@ -6134,7 +6228,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn live_terminal_output_is_never_replaced_by_paced_snapshots() {
|
async fn live_terminal_output_is_never_replaced_by_paced_snapshots() {
|
||||||
let (pty_tx, _pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, _pty_rx) = mpsc::channel(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
let config = ServerConfig {
|
let config = ServerConfig {
|
||||||
output_frame_interval_ms: 1000,
|
output_frame_interval_ms: 1000,
|
||||||
..ServerConfig::default()
|
..ServerConfig::default()
|
||||||
|
|||||||
+35
-26
@@ -201,7 +201,6 @@ impl DoshClientBuilder {
|
|||||||
match connect_sdk_peer(
|
match connect_sdk_peer(
|
||||||
peer_addr,
|
peer_addr,
|
||||||
&self.client.config,
|
&self.client.config,
|
||||||
&host_config,
|
|
||||||
&self.host,
|
&self.host,
|
||||||
&raw_server,
|
&raw_server,
|
||||||
ssh_port,
|
ssh_port,
|
||||||
@@ -244,7 +243,6 @@ impl ConnectedDoshClient {
|
|||||||
async fn connect_sdk_peer(
|
async fn connect_sdk_peer(
|
||||||
peer_addr: SocketAddr,
|
peer_addr: SocketAddr,
|
||||||
config: &ClientConfig,
|
config: &ClientConfig,
|
||||||
host_config: &HostConfig,
|
|
||||||
host: &str,
|
host: &str,
|
||||||
server: &str,
|
server: &str,
|
||||||
ssh_port: Option<u16>,
|
ssh_port: Option<u16>,
|
||||||
@@ -311,18 +309,17 @@ async fn connect_sdk_peer(
|
|||||||
&hello,
|
&hello,
|
||||||
&server_hello.hello,
|
&server_hello.hello,
|
||||||
)?;
|
)?;
|
||||||
let auth = sign_auth(
|
let auth = sign_auth(NativeAuthSignRequest {
|
||||||
config,
|
config,
|
||||||
host_config,
|
hello: &hello,
|
||||||
&hello,
|
server_hello: &server_hello.hello,
|
||||||
&server_hello.hello,
|
requested_forwardings: requested_forwardings.to_vec(),
|
||||||
requested_forwardings.to_vec(),
|
explicit_identity_files: identity_files.to_vec(),
|
||||||
identity_files.to_vec(),
|
|
||||||
use_ssh_agent,
|
use_ssh_agent,
|
||||||
server,
|
server,
|
||||||
ssh_port,
|
ssh_port,
|
||||||
ssh_config,
|
ssh_config,
|
||||||
)?;
|
})?;
|
||||||
let mut pending_id = [0u8; 16];
|
let mut pending_id = [0u8; 16];
|
||||||
pending_id.copy_from_slice(&server_hello.hello.auth_challenge[..16]);
|
pending_id.copy_from_slice(&server_hello.hello.auth_challenge[..16]);
|
||||||
let auth_packet = protocol::encode_encrypted(
|
let auth_packet = protocol::encode_encrypted(
|
||||||
@@ -387,18 +384,30 @@ fn verify_or_trust_host(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sign_auth(
|
struct NativeAuthSignRequest<'a> {
|
||||||
config: &ClientConfig,
|
config: &'a ClientConfig,
|
||||||
_host_config: &HostConfig,
|
hello: &'a NativeClientHello,
|
||||||
hello: &NativeClientHello,
|
server_hello: &'a native::NativeServerHello,
|
||||||
server_hello: &native::NativeServerHello,
|
|
||||||
requested_forwardings: Vec<ForwardingRequest>,
|
requested_forwardings: Vec<ForwardingRequest>,
|
||||||
explicit_identity_files: Vec<PathBuf>,
|
explicit_identity_files: Vec<PathBuf>,
|
||||||
use_ssh_agent: Option<bool>,
|
use_ssh_agent: Option<bool>,
|
||||||
server: &str,
|
server: &'a str,
|
||||||
ssh_port: Option<u16>,
|
ssh_port: Option<u16>,
|
||||||
ssh_config: &SdkSshConfig,
|
ssh_config: &'a SdkSshConfig,
|
||||||
) -> Result<native::NativeUserAuth> {
|
}
|
||||||
|
|
||||||
|
fn sign_auth(request: NativeAuthSignRequest<'_>) -> Result<native::NativeUserAuth> {
|
||||||
|
let NativeAuthSignRequest {
|
||||||
|
config,
|
||||||
|
hello,
|
||||||
|
server_hello,
|
||||||
|
requested_forwardings,
|
||||||
|
explicit_identity_files,
|
||||||
|
use_ssh_agent,
|
||||||
|
server,
|
||||||
|
ssh_port,
|
||||||
|
ssh_config,
|
||||||
|
} = request;
|
||||||
let use_agent = use_ssh_agent.unwrap_or(config.use_ssh_agent);
|
let use_agent = use_ssh_agent.unwrap_or(config.use_ssh_agent);
|
||||||
let mut errors = Vec::new();
|
let mut errors = Vec::new();
|
||||||
if use_agent && !ssh_config.identities_only {
|
if use_agent && !ssh_config.identities_only {
|
||||||
@@ -448,12 +457,6 @@ fn sdk_identity_paths(
|
|||||||
for path in explicit_identity_files {
|
for path in explicit_identity_files {
|
||||||
push_identity_path(&mut paths, path);
|
push_identity_path(&mut paths, path);
|
||||||
}
|
}
|
||||||
for path in &ssh_config.identity_files {
|
|
||||||
push_identity_path(
|
|
||||||
&mut paths,
|
|
||||||
expand_tilde(&expand_ssh_path_tokens(path, token_context)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if !ssh_config.identities_only {
|
if !ssh_config.identities_only {
|
||||||
for path in &config.identity_files {
|
for path in &config.identity_files {
|
||||||
push_identity_path(
|
push_identity_path(
|
||||||
@@ -462,6 +465,12 @@ fn sdk_identity_paths(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for path in &ssh_config.identity_files {
|
||||||
|
push_identity_path(
|
||||||
|
&mut paths,
|
||||||
|
expand_tilde(&expand_ssh_path_tokens(path, token_context)),
|
||||||
|
);
|
||||||
|
}
|
||||||
paths
|
paths
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -818,10 +827,10 @@ fn local_username() -> Option<String> {
|
|||||||
local_username_from_env(|name| std::env::var(name).ok())
|
local_username_from_env(|name| std::env::var(name).ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn local_username_from_env(mut get: impl FnMut(&str) -> Option<String>) -> Option<String> {
|
fn local_username_from_env(get: impl FnMut(&str) -> Option<String>) -> Option<String> {
|
||||||
["USER", "USERNAME"]
|
["USER", "USERNAME"]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|name| get(name))
|
.filter_map(get)
|
||||||
.find(|value| !value.is_empty())
|
.find(|value| !value.is_empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1092,7 +1101,7 @@ mod tests {
|
|||||||
|
|
||||||
let paths = sdk_identity_paths(&config, Vec::new(), &ssh_config, &token_context);
|
let paths = sdk_identity_paths(&config, Vec::new(), &ssh_config, &token_context);
|
||||||
|
|
||||||
assert_eq!(paths, vec![dir.path().join("ssh"), config_identity]);
|
assert_eq!(paths, vec![config_identity, dir.path().join("ssh")]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
+41
-10
@@ -12,6 +12,10 @@ use tokio::sync::mpsc;
|
|||||||
// TUIs often write several KiB on the first draw; sending that as one UDP
|
// TUIs often write several KiB on the first draw; sending that as one UDP
|
||||||
// datagram can fragment and vanish, leaving only a blank alternate screen.
|
// datagram can fragment and vanish, leaving only a blank alternate screen.
|
||||||
const PTY_OUTPUT_CHUNK_BYTES: usize = 1024;
|
const PTY_OUTPUT_CHUNK_BYTES: usize = 1024;
|
||||||
|
/// Shared server queue bound. At the current chunk size this limits queued PTY
|
||||||
|
/// output to roughly 1 MiB before the producing shell receives normal PTY
|
||||||
|
/// backpressure.
|
||||||
|
pub const PTY_OUTPUT_QUEUE_CAPACITY: usize = 1024;
|
||||||
|
|
||||||
/// Backing for a PTY master held by the server.
|
/// Backing for a PTY master held by the server.
|
||||||
///
|
///
|
||||||
@@ -126,7 +130,7 @@ pub fn spawn_pty_session(
|
|||||||
cols: u16,
|
cols: u16,
|
||||||
rows: u16,
|
rows: u16,
|
||||||
env: &[(String, String)],
|
env: &[(String, String)],
|
||||||
tx: mpsc::UnboundedSender<PtyOutput>,
|
tx: mpsc::Sender<PtyOutput>,
|
||||||
) -> Result<PtyHandle> {
|
) -> Result<PtyHandle> {
|
||||||
let pty_system = NativePtySystem::default();
|
let pty_system = NativePtySystem::default();
|
||||||
let pair = pty_system
|
let pair = pty_system
|
||||||
@@ -232,7 +236,7 @@ pub fn build_shell_command(shell: &str, env: &[(String, String)]) -> CommandBuil
|
|||||||
pub fn adopt_pty_from_fd(
|
pub fn adopt_pty_from_fd(
|
||||||
session: String,
|
session: String,
|
||||||
master_fd: RawFd,
|
master_fd: RawFd,
|
||||||
tx: mpsc::UnboundedSender<PtyOutput>,
|
tx: mpsc::Sender<PtyOutput>,
|
||||||
) -> Result<PtyHandle> {
|
) -> Result<PtyHandle> {
|
||||||
// Take ownership of the fd. A clone gives us an independent reader so the
|
// Take ownership of the fd. A clone gives us an independent reader so the
|
||||||
// reader thread and the writer/resize side hold separate `File`s and don't
|
// reader thread and the writer/resize side hold separate `File`s and don't
|
||||||
@@ -252,7 +256,7 @@ pub fn adopt_pty_from_fd(
|
|||||||
fn spawn_reader_thread(
|
fn spawn_reader_thread(
|
||||||
session: String,
|
session: String,
|
||||||
mut reader: Box<dyn Read + Send>,
|
mut reader: Box<dyn Read + Send>,
|
||||||
tx: mpsc::UnboundedSender<PtyOutput>,
|
tx: mpsc::Sender<PtyOutput>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let reader_session = session.clone();
|
let reader_session = session.clone();
|
||||||
thread::Builder::new()
|
thread::Builder::new()
|
||||||
@@ -262,7 +266,7 @@ fn spawn_reader_thread(
|
|||||||
loop {
|
loop {
|
||||||
match reader.read(&mut buf) {
|
match reader.read(&mut buf) {
|
||||||
Ok(0) => {
|
Ok(0) => {
|
||||||
let _ = tx.send(PtyOutput {
|
let _ = tx.blocking_send(PtyOutput {
|
||||||
session: reader_session.clone(),
|
session: reader_session.clone(),
|
||||||
bytes: Vec::new(),
|
bytes: Vec::new(),
|
||||||
exited: true,
|
exited: true,
|
||||||
@@ -271,15 +275,20 @@ fn spawn_reader_thread(
|
|||||||
}
|
}
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
for chunk in buf[..n].chunks(PTY_OUTPUT_CHUNK_BYTES) {
|
for chunk in buf[..n].chunks(PTY_OUTPUT_CHUNK_BYTES) {
|
||||||
let _ = tx.send(PtyOutput {
|
if tx
|
||||||
session: reader_session.clone(),
|
.blocking_send(PtyOutput {
|
||||||
bytes: chunk.to_vec(),
|
session: reader_session.clone(),
|
||||||
exited: false,
|
bytes: chunk.to_vec(),
|
||||||
});
|
exited: false,
|
||||||
|
})
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let _ = tx.send(PtyOutput {
|
let _ = tx.blocking_send(PtyOutput {
|
||||||
session: reader_session.clone(),
|
session: reader_session.clone(),
|
||||||
bytes: Vec::new(),
|
bytes: Vec::new(),
|
||||||
exited: true,
|
exited: true,
|
||||||
@@ -298,6 +307,28 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const _: () = assert!(PTY_OUTPUT_CHUNK_BYTES <= 1200);
|
const _: () = assert!(PTY_OUTPUT_CHUNK_BYTES <= 1200);
|
||||||
|
const _: () = assert!(PTY_OUTPUT_QUEUE_CAPACITY * PTY_OUTPUT_CHUNK_BYTES <= 1024 * 1024);
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pty_output_queue_capacity_is_memory_bounded() {
|
||||||
|
let (tx, _rx) = mpsc::channel::<PtyOutput>(PTY_OUTPUT_QUEUE_CAPACITY);
|
||||||
|
for index in 0..PTY_OUTPUT_QUEUE_CAPACITY {
|
||||||
|
tx.try_send(PtyOutput {
|
||||||
|
session: "load".to_string(),
|
||||||
|
bytes: vec![index as u8; PTY_OUTPUT_CHUNK_BYTES],
|
||||||
|
exited: false,
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
assert!(matches!(
|
||||||
|
tx.try_send(PtyOutput {
|
||||||
|
session: "load".to_string(),
|
||||||
|
bytes: vec![0; PTY_OUTPUT_CHUNK_BYTES],
|
||||||
|
exited: false,
|
||||||
|
}),
|
||||||
|
Err(mpsc::error::TrySendError::Full(_))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn terminfo_available_detects_known_and_unknown() {
|
fn terminfo_available_detects_known_and_unknown() {
|
||||||
|
|||||||
+43
-9
@@ -578,20 +578,43 @@ mod tests {
|
|||||||
.user("sdk-user")
|
.user("sdk-user")
|
||||||
.service("echo")
|
.service("echo")
|
||||||
.connect();
|
.connect();
|
||||||
let accept = async {
|
let handshake = async {
|
||||||
|
tokio::pin!(connect);
|
||||||
|
let mut connected = None;
|
||||||
|
let mut accepted = None;
|
||||||
loop {
|
loop {
|
||||||
if let DoshServerEvent::Accepted(accepted) = server.recv().await.unwrap() {
|
tokio::select! {
|
||||||
break accepted;
|
result = &mut connect, if connected.is_none() => {
|
||||||
|
connected = Some(result?);
|
||||||
|
}
|
||||||
|
event = server.recv(), if accepted.is_none() => {
|
||||||
|
if let DoshServerEvent::Accepted(connection) = event? {
|
||||||
|
accepted = Some(connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if connected.is_some() && accepted.is_some() {
|
||||||
|
return Ok::<_, anyhow::Error>((
|
||||||
|
connected.take().expect("connected result checked"),
|
||||||
|
accepted.take().expect("accepted result checked"),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let (connected, accepted) = tokio::join!(connect, accept);
|
let (connected, accepted) = tokio::time::timeout(Duration::from_secs(3), handshake)
|
||||||
let mut client_transport = connected.unwrap().into_transport();
|
.await
|
||||||
|
.expect("SDK client/server authentication timed out")
|
||||||
|
.unwrap();
|
||||||
|
let mut client_transport = connected.into_transport();
|
||||||
let conn_id = accepted.conn_id;
|
let conn_id = accepted.conn_id;
|
||||||
assert_eq!(accepted.services, vec!["echo".to_string()]);
|
assert_eq!(accepted.services, vec!["echo".to_string()]);
|
||||||
|
|
||||||
let stream_id = client_transport.open_service("echo").await.unwrap();
|
let stream_id = client_transport.open_service("echo").await.unwrap();
|
||||||
match server.recv().await.unwrap() {
|
match tokio::time::timeout(Duration::from_secs(3), server.recv())
|
||||||
|
.await
|
||||||
|
.expect("server timed out waiting for stream open")
|
||||||
|
.unwrap()
|
||||||
|
{
|
||||||
DoshServerEvent::Session {
|
DoshServerEvent::Session {
|
||||||
event: SessionEvent::Stream(TransportEvent::Open(open)),
|
event: SessionEvent::Stream(TransportEvent::Open(open)),
|
||||||
..
|
..
|
||||||
@@ -602,7 +625,10 @@ mod tests {
|
|||||||
other => panic!("unexpected event {other:?}"),
|
other => panic!("unexpected event {other:?}"),
|
||||||
}
|
}
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
client_transport.recv().await.unwrap(),
|
tokio::time::timeout(Duration::from_secs(3), client_transport.recv())
|
||||||
|
.await
|
||||||
|
.expect("client timed out waiting for stream-open acknowledgement")
|
||||||
|
.unwrap(),
|
||||||
SessionEvent::Stream(TransportEvent::OpenOk { .. })
|
SessionEvent::Stream(TransportEvent::OpenOk { .. })
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -611,7 +637,11 @@ mod tests {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
loop {
|
loop {
|
||||||
match server.recv().await.unwrap() {
|
match tokio::time::timeout(Duration::from_secs(3), server.recv())
|
||||||
|
.await
|
||||||
|
.expect("server timed out waiting for stream data")
|
||||||
|
.unwrap()
|
||||||
|
{
|
||||||
DoshServerEvent::Session {
|
DoshServerEvent::Session {
|
||||||
event: SessionEvent::Stream(TransportEvent::Data(data)),
|
event: SessionEvent::Stream(TransportEvent::Data(data)),
|
||||||
..
|
..
|
||||||
@@ -628,7 +658,11 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
loop {
|
loop {
|
||||||
match client_transport.recv().await.unwrap() {
|
match tokio::time::timeout(Duration::from_secs(3), client_transport.recv())
|
||||||
|
.await
|
||||||
|
.expect("client timed out waiting for stream response")
|
||||||
|
.unwrap()
|
||||||
|
{
|
||||||
SessionEvent::Stream(TransportEvent::Data(data)) => {
|
SessionEvent::Stream(TransportEvent::Data(data)) => {
|
||||||
assert_eq!(data.chunks, vec![b"pong".to_vec()]);
|
assert_eq!(data.chunks, vec![b"pong".to_vec()]);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -0,0 +1,265 @@
|
|||||||
|
#![cfg(unix)]
|
||||||
|
|
||||||
|
use sha2::{Digest, Sha256};
|
||||||
|
use std::fs;
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::process::Command;
|
||||||
|
use tempfile::TempDir;
|
||||||
|
|
||||||
|
const VERSION: &str = "9.8.7-rc3";
|
||||||
|
|
||||||
|
fn write_executable(path: &Path, body: &str) {
|
||||||
|
fs::write(path, body).unwrap();
|
||||||
|
let mut permissions = fs::metadata(path).unwrap().permissions();
|
||||||
|
permissions.set_mode(0o755);
|
||||||
|
fs::set_permissions(path, permissions).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct InstallerFixture {
|
||||||
|
root: TempDir,
|
||||||
|
fake_bin: PathBuf,
|
||||||
|
archive: PathBuf,
|
||||||
|
checksum: PathBuf,
|
||||||
|
curl_log: PathBuf,
|
||||||
|
git_log: PathBuf,
|
||||||
|
version: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl InstallerFixture {
|
||||||
|
fn new(version: &str) -> Self {
|
||||||
|
let root = tempfile::tempdir().unwrap();
|
||||||
|
let fake_bin = root.path().join("fake-bin");
|
||||||
|
let stage = root.path().join("stage/dosh");
|
||||||
|
fs::create_dir_all(fake_bin.as_path()).unwrap();
|
||||||
|
fs::create_dir_all(stage.join("bin")).unwrap();
|
||||||
|
fs::write(stage.join("VERSION"), format!("{version}\n")).unwrap();
|
||||||
|
write_executable(
|
||||||
|
&stage.join("bin/dosh-client"),
|
||||||
|
"#!/bin/sh\nprintf 'fixture dosh\\n'\n",
|
||||||
|
);
|
||||||
|
|
||||||
|
let archive = root.path().join("dosh-macos-aarch64.tar.gz");
|
||||||
|
let status = Command::new("tar")
|
||||||
|
.args(["-C", root.path().join("stage").to_str().unwrap(), "-czf"])
|
||||||
|
.arg(&archive)
|
||||||
|
.arg("dosh")
|
||||||
|
.status()
|
||||||
|
.unwrap();
|
||||||
|
assert!(status.success());
|
||||||
|
let digest = Sha256::digest(fs::read(&archive).unwrap());
|
||||||
|
let checksum = root.path().join("dosh-macos-aarch64.tar.gz.sha256");
|
||||||
|
fs::write(
|
||||||
|
&checksum,
|
||||||
|
format!("{digest:x} dosh-macos-aarch64.tar.gz\n"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
write_executable(
|
||||||
|
&fake_bin.join("uname"),
|
||||||
|
"#!/bin/sh\ncase \"${1:-}\" in -s) echo Darwin;; -m) echo arm64;; *) echo Darwin;; esac\n",
|
||||||
|
);
|
||||||
|
let curl_log = root.path().join("curl.log");
|
||||||
|
let git_log = root.path().join("git.log");
|
||||||
|
write_executable(
|
||||||
|
&fake_bin.join("curl"),
|
||||||
|
r#"#!/bin/sh
|
||||||
|
printf '%s\n' "$*" >>"$TEST_CURL_LOG"
|
||||||
|
out=
|
||||||
|
previous=
|
||||||
|
url=
|
||||||
|
for arg in "$@"; do
|
||||||
|
if [ "$previous" = "-o" ]; then out="$arg"; fi
|
||||||
|
previous="$arg"
|
||||||
|
case "$arg" in http://*|https://*) url="$arg";; esac
|
||||||
|
done
|
||||||
|
case "$url" in
|
||||||
|
*/raw/branch/main/Cargo.toml)
|
||||||
|
printf '[package]\nname = "dosh"\nversion = "%s"\n' "$TEST_RELEASE_VERSION"
|
||||||
|
;;
|
||||||
|
*.sha256)
|
||||||
|
cp "$TEST_ARCHIVE_CHECKSUM" "$out"
|
||||||
|
;;
|
||||||
|
*/releases/download/*)
|
||||||
|
[ "${TEST_FAIL_ARCHIVE:-0}" = 1 ] && exit 22
|
||||||
|
cp "$TEST_ARCHIVE" "$out"
|
||||||
|
;;
|
||||||
|
*) exit 22;;
|
||||||
|
esac
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
root,
|
||||||
|
fake_bin,
|
||||||
|
archive,
|
||||||
|
checksum,
|
||||||
|
curl_log,
|
||||||
|
git_log,
|
||||||
|
version: version.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn command(&self, cwd: &Path) -> Command {
|
||||||
|
let mut command = Command::new("sh");
|
||||||
|
command
|
||||||
|
.arg(format!("{}/install.sh", env!("CARGO_MANIFEST_DIR")))
|
||||||
|
.args([
|
||||||
|
"client",
|
||||||
|
"--repo",
|
||||||
|
"https://example.invalid/Palav/dosh.git",
|
||||||
|
"--prefix",
|
||||||
|
])
|
||||||
|
.arg(self.root.path().join("prefix"))
|
||||||
|
.current_dir(cwd)
|
||||||
|
.env("HOME", self.root.path().join("home"))
|
||||||
|
.env(
|
||||||
|
"PATH",
|
||||||
|
format!(
|
||||||
|
"{}:{}",
|
||||||
|
self.fake_bin.display(),
|
||||||
|
std::env::var("PATH").unwrap_or_default()
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.env("DOSH_BINARY_REQUIRED", "1")
|
||||||
|
.env("TEST_RELEASE_VERSION", &self.version)
|
||||||
|
.env("TEST_ARCHIVE", &self.archive)
|
||||||
|
.env("TEST_ARCHIVE_CHECKSUM", &self.checksum)
|
||||||
|
.env("TEST_CURL_LOG", &self.curl_log)
|
||||||
|
.env("TEST_GIT_LOG", &self.git_log);
|
||||||
|
command
|
||||||
|
}
|
||||||
|
|
||||||
|
fn installed_client(&self) -> PathBuf {
|
||||||
|
self.root.path().join("prefix/bin/dosh-client")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unix_installer_uses_repository_version_even_inside_an_unrelated_rust_project() {
|
||||||
|
let fixture = InstallerFixture::new(VERSION);
|
||||||
|
let unrelated = fixture.root.path().join("unrelated");
|
||||||
|
fs::create_dir_all(&unrelated).unwrap();
|
||||||
|
fs::write(
|
||||||
|
unrelated.join("Cargo.toml"),
|
||||||
|
"[package]\nname = \"not-dosh\"\nversion = \"99.0.0\"\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let output = fixture.command(&unrelated).output().unwrap();
|
||||||
|
assert!(
|
||||||
|
output.status.success(),
|
||||||
|
"installer failed: {}",
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
);
|
||||||
|
assert!(fixture.installed_client().is_file());
|
||||||
|
let requests = fs::read_to_string(&fixture.curl_log).unwrap();
|
||||||
|
assert!(requests.contains("/raw/branch/main/Cargo.toml"));
|
||||||
|
assert!(requests.contains(&format!(
|
||||||
|
"/releases/download/v{VERSION}/dosh-macos-aarch64.tar.gz"
|
||||||
|
)));
|
||||||
|
assert!(!requests.contains("/releases/latest"));
|
||||||
|
assert!(!requests.contains("99.0.0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unix_installer_source_fallback_checks_out_the_same_release_tag() {
|
||||||
|
let fixture = InstallerFixture::new(VERSION);
|
||||||
|
write_executable(
|
||||||
|
&fixture.fake_bin.join("git"),
|
||||||
|
r#"#!/bin/sh
|
||||||
|
printf '%s\n' "$*" >>"$TEST_GIT_LOG"
|
||||||
|
if [ "${1:-}" = clone ]; then
|
||||||
|
for destination in "$@"; do :; done
|
||||||
|
mkdir -p "$destination/.git"
|
||||||
|
fi
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
write_executable(
|
||||||
|
&fixture.fake_bin.join("cargo"),
|
||||||
|
"#!/bin/sh\nmkdir -p target/release\nprintf '#!/bin/sh\\n' >target/release/dosh-client\nchmod +x target/release/dosh-client\n",
|
||||||
|
);
|
||||||
|
let cwd = fixture.root.path().join("plain");
|
||||||
|
fs::create_dir_all(&cwd).unwrap();
|
||||||
|
let mut command = fixture.command(&cwd);
|
||||||
|
command
|
||||||
|
.env("DOSH_BINARY_REQUIRED", "0")
|
||||||
|
.env("TEST_FAIL_ARCHIVE", "1");
|
||||||
|
|
||||||
|
let output = command.output().unwrap();
|
||||||
|
assert!(
|
||||||
|
output.status.success(),
|
||||||
|
"installer failed: {}",
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
);
|
||||||
|
assert!(fixture.installed_client().is_file());
|
||||||
|
let git = fs::read_to_string(&fixture.git_log).unwrap();
|
||||||
|
assert!(git.contains(&format!("clone --depth 1 --branch v{VERSION}")));
|
||||||
|
assert!(!git.contains("--branch main"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unix_installer_resolves_a_stable_repository_version_without_latest_redirects() {
|
||||||
|
let version = "1.2.3";
|
||||||
|
let fixture = InstallerFixture::new(version);
|
||||||
|
let cwd = fixture.root.path().join("plain");
|
||||||
|
fs::create_dir_all(&cwd).unwrap();
|
||||||
|
|
||||||
|
let output = fixture.command(&cwd).output().unwrap();
|
||||||
|
assert!(
|
||||||
|
output.status.success(),
|
||||||
|
"installer failed: {}",
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
);
|
||||||
|
let requests = fs::read_to_string(&fixture.curl_log).unwrap();
|
||||||
|
assert!(requests.contains(&format!(
|
||||||
|
"/releases/download/v{version}/dosh-macos-aarch64.tar.gz"
|
||||||
|
)));
|
||||||
|
assert!(!requests.contains("/releases/latest"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unix_installer_repairs_a_legacy_updater_that_requests_its_old_tag() {
|
||||||
|
let fixture = InstallerFixture::new(VERSION);
|
||||||
|
let cwd = fixture.root.path().join("plain");
|
||||||
|
fs::create_dir_all(&cwd).unwrap();
|
||||||
|
let mut command = fixture.command(&cwd);
|
||||||
|
command.env("DOSH_BINARY_VERSION", "v0.1.17");
|
||||||
|
|
||||||
|
let output = command.output().unwrap();
|
||||||
|
assert!(
|
||||||
|
output.status.success(),
|
||||||
|
"installer failed: {}",
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
);
|
||||||
|
let requests = fs::read_to_string(&fixture.curl_log).unwrap();
|
||||||
|
assert!(requests.contains(&format!(
|
||||||
|
"/releases/download/v{VERSION}/dosh-macos-aarch64.tar.gz"
|
||||||
|
)));
|
||||||
|
assert!(!requests.contains("/releases/download/v0.1.17/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unix_installer_honors_an_explicit_exact_release_pin() {
|
||||||
|
let pinned = "0.1.17";
|
||||||
|
let fixture = InstallerFixture::new(pinned);
|
||||||
|
let cwd = fixture.root.path().join("plain");
|
||||||
|
fs::create_dir_all(&cwd).unwrap();
|
||||||
|
let mut command = fixture.command(&cwd);
|
||||||
|
command
|
||||||
|
.env("TEST_RELEASE_VERSION", VERSION)
|
||||||
|
.env("DOSH_BINARY_VERSION", format!("v{pinned}"))
|
||||||
|
.env("DOSH_BINARY_EXACT", "1");
|
||||||
|
|
||||||
|
let output = command.output().unwrap();
|
||||||
|
assert!(
|
||||||
|
output.status.success(),
|
||||||
|
"installer failed: {}",
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
);
|
||||||
|
let requests = fs::read_to_string(&fixture.curl_log).unwrap();
|
||||||
|
assert!(requests.contains(&format!(
|
||||||
|
"/releases/download/v{pinned}/dosh-macos-aarch64.tar.gz"
|
||||||
|
)));
|
||||||
|
assert!(!requests.contains(&format!("/releases/download/v{VERSION}/")));
|
||||||
|
}
|
||||||
@@ -1355,6 +1355,22 @@ fn native_exec_command_smoke() {
|
|||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = tempfile::tempdir().unwrap();
|
||||||
let port = free_udp_port();
|
let port = free_udp_port();
|
||||||
let config = write_server_config(&dir, port);
|
let config = write_server_config(&dir, port);
|
||||||
|
let shell_log = dir.path().join("exec-shell.log");
|
||||||
|
let shell = dir.path().join("exec-shell");
|
||||||
|
fs::write(
|
||||||
|
&shell,
|
||||||
|
format!(
|
||||||
|
"#!/bin/sh\nprintf '%s\\n' \"$*\" >> '{}'\nexec /bin/sh \"$@\"\n",
|
||||||
|
shell_log.display()
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
fs::set_permissions(&shell, fs::Permissions::from_mode(0o700)).unwrap();
|
||||||
|
let raw = fs::read_to_string(&config).unwrap().replace(
|
||||||
|
"shell = \"/bin/sh\"",
|
||||||
|
&format!("shell = {:?}", shell.display().to_string()),
|
||||||
|
);
|
||||||
|
fs::write(&config, raw).unwrap();
|
||||||
write_native_client_auth(&dir, &config);
|
write_native_client_auth(&dir, &config);
|
||||||
let mut server = start_server(&dir, &config);
|
let mut server = start_server(&dir, &config);
|
||||||
let client_bin = env!("CARGO_BIN_EXE_dosh-client");
|
let client_bin = env!("CARGO_BIN_EXE_dosh-client");
|
||||||
@@ -1380,6 +1396,19 @@ fn native_exec_command_smoke() {
|
|||||||
);
|
);
|
||||||
assert_eq!(String::from_utf8_lossy(&output.stdout), "out");
|
assert_eq!(String::from_utf8_lossy(&output.stdout), "out");
|
||||||
assert_eq!(String::from_utf8_lossy(&output.stderr), "err");
|
assert_eq!(String::from_utf8_lossy(&output.stderr), "err");
|
||||||
|
let shell_invocations = fs::read_to_string(shell_log).unwrap();
|
||||||
|
assert!(
|
||||||
|
shell_invocations
|
||||||
|
.lines()
|
||||||
|
.any(|line| line.starts_with("-c ")),
|
||||||
|
"configured shell was not used for exec: {shell_invocations:?}"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
!shell_invocations
|
||||||
|
.lines()
|
||||||
|
.any(|line| line.starts_with("-lc ")),
|
||||||
|
"exec must not start a login shell: {shell_invocations:?}"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
+26
-23
@@ -94,6 +94,8 @@ fn release_gates_test_all_targets() {
|
|||||||
assert!(windows_client.contains("runs-on: windows-latest"));
|
assert!(windows_client.contains("runs-on: windows-latest"));
|
||||||
assert!(windows_client.contains("name: Test Windows client"));
|
assert!(windows_client.contains("name: Test Windows client"));
|
||||||
assert!(windows_client.contains("name: PowerShell syntax check"));
|
assert!(windows_client.contains("name: PowerShell syntax check"));
|
||||||
|
assert!(windows_client.contains("name: Windows installer runtime test"));
|
||||||
|
assert!(windows_client.contains("run: scripts/test-install-windows.ps1"));
|
||||||
assert!(windows_client.contains("shell: pwsh"));
|
assert!(windows_client.contains("shell: pwsh"));
|
||||||
assert!(
|
assert!(
|
||||||
windows_client
|
windows_client
|
||||||
@@ -138,28 +140,24 @@ fn one_dot_zero_gates_default_to_full_length_soaks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn installers_skip_stale_latest_release_prebuilts() {
|
fn installers_resolve_the_repository_declared_release_without_stable_redirects() {
|
||||||
let install = include_str!("../install.sh");
|
let install = include_str!("../install.sh");
|
||||||
assert!(install.contains("latest_release_is_stale"));
|
|
||||||
assert!(install.contains("current_source_version"));
|
assert!(install.contains("current_source_version"));
|
||||||
assert!(install.contains("latest release $latest is older than source $current"));
|
assert!(install.contains("release_source_ref"));
|
||||||
assert!(install.contains("version_prerelease"));
|
assert!(install.contains("printf 'v%s\\n' \"${current#v}\""));
|
||||||
assert!(install.contains("prerelease_less_than"));
|
assert!(install.contains("DOSH_BINARY_EXACT=1"));
|
||||||
assert!(
|
assert!(!install.contains("/releases/latest"));
|
||||||
install.contains("if latest_release_is_stale; then"),
|
assert!(install.contains("resolved_source_ref=\"$(release_source_ref || true)\""));
|
||||||
"unix installer must skip stale latest before downloading a prebuilt"
|
assert!(install.contains("checkout -q --detach FETCH_HEAD"));
|
||||||
);
|
|
||||||
|
|
||||||
let ps1 = include_str!("../install.ps1");
|
let ps1 = include_str!("../install.ps1");
|
||||||
assert!(ps1.contains("Latest-ReleaseIsStale"));
|
|
||||||
assert!(ps1.contains("Current-SourceVersion"));
|
assert!(ps1.contains("Current-SourceVersion"));
|
||||||
assert!(ps1.contains("latest release $latestVersion is older than source $current"));
|
assert!(ps1.contains("Source-ReleaseRef"));
|
||||||
assert!(ps1.contains("Version-Prerelease"));
|
assert!(ps1.contains("\"v$($current.TrimStart('v'))\""));
|
||||||
assert!(ps1.contains("Compare-Prerelease"));
|
assert!(ps1.contains("DOSH_BINARY_EXACT"));
|
||||||
assert!(
|
assert!(!ps1.contains("/releases/latest"));
|
||||||
ps1.contains("if (Latest-ReleaseIsStale)"),
|
assert!(ps1.contains("$script:ResolvedSourceRef = Source-ReleaseRef"));
|
||||||
"windows installer must skip stale latest before downloading a prebuilt"
|
assert!(ps1.contains("checkout -q --detach FETCH_HEAD"));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -198,15 +196,16 @@ fn windows_installer_reuses_persistent_source_update_cache() {
|
|||||||
assert!(ps1.contains("$full -eq $localAppData -or $full -eq $localAppDataDosh"));
|
assert!(ps1.contains("$full -eq $localAppData -or $full -eq $localAppDataDosh"));
|
||||||
assert!(ps1.contains("$sourceCache = Assert-SafeUpdateCache $UpdateCache"));
|
assert!(ps1.contains("$sourceCache = Assert-SafeUpdateCache $UpdateCache"));
|
||||||
assert!(ps1.contains(
|
assert!(ps1.contains(
|
||||||
"$fetchArgs = @(\"-C\", $sourceCache, \"fetch\", \"--depth\", \"1\", \"origin\", \"main\")"
|
"$fetchArgs = @(\"-C\", $sourceCache, \"fetch\", \"--depth\", \"1\", \"origin\", $sourceRef)"
|
||||||
));
|
));
|
||||||
assert!(ps1.contains("$fetchArgs = @(\"-C\", $sourceCache, \"fetch\", \"-q\", \"--depth\", \"1\", \"origin\", \"main\")"));
|
assert!(ps1.contains("$fetchArgs = @(\"-C\", $sourceCache, \"fetch\", \"-q\", \"--depth\", \"1\", \"origin\", $sourceRef)"));
|
||||||
assert!(ps1.contains("git @fetchArgs"));
|
assert!(ps1.contains("git @fetchArgs"));
|
||||||
assert!(ps1.contains("git -C $sourceCache checkout -q -B main FETCH_HEAD"));
|
assert!(ps1.contains("git -C $sourceCache checkout -q -B main FETCH_HEAD"));
|
||||||
|
assert!(ps1.contains("git -C $sourceCache checkout -q --detach FETCH_HEAD"));
|
||||||
assert!(ps1.contains(
|
assert!(ps1.contains(
|
||||||
"$cloneArgs = @(\"clone\", \"--depth\", \"1\", \"--branch\", \"main\", $Repo, $sourceCache)"
|
"$cloneArgs = @(\"clone\", \"--depth\", \"1\", \"--branch\", $sourceRef, $Repo, $sourceCache)"
|
||||||
));
|
));
|
||||||
assert!(ps1.contains("$cloneArgs = @(\"clone\", \"-q\", \"--depth\", \"1\", \"--branch\", \"main\", $Repo, $sourceCache)"));
|
assert!(ps1.contains("$cloneArgs = @(\"clone\", \"-q\", \"--depth\", \"1\", \"--branch\", $sourceRef, $Repo, $sourceCache)"));
|
||||||
assert!(ps1.contains("git @cloneArgs | Out-Null"));
|
assert!(ps1.contains("git @cloneArgs | Out-Null"));
|
||||||
assert!(
|
assert!(
|
||||||
!ps1.contains("git clone --depth 1 $Repo $tmp"),
|
!ps1.contains("git clone --depth 1 $Repo $tmp"),
|
||||||
@@ -218,8 +217,12 @@ fn windows_installer_reuses_persistent_source_update_cache() {
|
|||||||
fn windows_quiet_source_updates_silence_git_like_unix() {
|
fn windows_quiet_source_updates_silence_git_like_unix() {
|
||||||
let install = include_str!("../install.sh");
|
let install = include_str!("../install.sh");
|
||||||
let ps1 = include_str!("../install.ps1");
|
let ps1 = include_str!("../install.ps1");
|
||||||
assert!(install.contains("git -C \"$update_cache\" fetch -q --depth 1 origin main"));
|
assert!(install.contains("git -C \"$update_cache\" fetch -q --depth 1 origin \"$source_ref\""));
|
||||||
assert!(install.contains("git clone -q --depth 1 --branch main \"$repo\" \"$update_cache\""));
|
assert!(
|
||||||
|
install.contains(
|
||||||
|
"git clone -q --depth 1 --branch \"$source_ref\" \"$repo\" \"$update_cache\""
|
||||||
|
)
|
||||||
|
);
|
||||||
assert!(ps1.contains("if ($Quiet)"));
|
assert!(ps1.contains("if ($Quiet)"));
|
||||||
assert!(ps1.contains("\"fetch\", \"-q\", \"--depth\""));
|
assert!(ps1.contains("\"fetch\", \"-q\", \"--depth\""));
|
||||||
assert!(ps1.contains("\"clone\", \"-q\", \"--depth\""));
|
assert!(ps1.contains("\"clone\", \"-q\", \"--depth\""));
|
||||||
|
|||||||
Reference in New Issue
Block a user