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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,30 @@ function Invoke-Download([string]$Uri, [string]$Path) {
Invoke-WebRequest -UseBasicParsing -Uri $Uri -OutFile $Path
}

function Invoke-GhProbe([string]$GhPath, [string[]]$Arguments) {
# Windows PowerShell 5.1 turns redirected native stderr into a terminating
# NativeCommandError under ErrorActionPreference=Stop, so a gh that is
# installed but not logged in would abort the install. Rely on the exit code.
$ErrorActionPreference = 'Continue'
& $GhPath @Arguments *> $null
return $LASTEXITCODE
}

function Test-AvailableAttestation([string]$ArtifactPath) {
$gh = Get-Command gh -ErrorAction SilentlyContinue
if (-not $gh) {
Write-Warning 'GitHub CLI attestation verification is unavailable; the checksum and artifact share the GitHub Release trust boundary.'
return
}
& $gh.Source attestation verify --help *> $null
if ($LASTEXITCODE -ne 0) {
if ((Invoke-GhProbe $gh.Source @('attestation', 'verify', '--help')) -ne 0) {
Write-Warning 'GitHub CLI attestation verification is unavailable; the checksum and artifact share the GitHub Release trust boundary.'
return
}
& $gh.Source auth status --hostname github.com *> $null
if ($LASTEXITCODE -ne 0) {
if ((Invoke-GhProbe $gh.Source @('auth', 'status', '--hostname', 'github.com')) -ne 0) {
Write-Warning 'GitHub CLI is not authenticated; the checksum and artifact share the GitHub Release trust boundary.'
return
}
& $gh.Source attestation verify $ArtifactPath --hostname github.com --repo $Repository *> $null
if ($LASTEXITCODE -ne 0) {
if ((Invoke-GhProbe $gh.Source @('attestation', 'verify', $ArtifactPath, '--hostname', 'github.com', '--repo', $Repository)) -ne 0) {
Fail 'GitHub artifact attestation verification failed.'
}
}
Expand Down
36 changes: 36 additions & 0 deletions scripts/install.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $Installer = Join-Path $Root 'scripts/install.ps1'
. $Installer
$ProductionInvokeInstalledHelper = (Get-Command Invoke-InstalledHelper -CommandType Function).ScriptBlock
$ProductionGetNativeArchitecture = (Get-Command Get-NativeArchitecture -CommandType Function).ScriptBlock
$ProductionTestAvailableAttestation = (Get-Command Test-AvailableAttestation -CommandType Function).ScriptBlock

$TestsRun = 0
$TestsFailed = 0
Expand Down Expand Up @@ -146,6 +147,41 @@ if ($helperSuccess -eq 0 -and $helperFailure -eq 7) {
FailTest 'keeps helper stdout out of Invoke-InstalledHelper exit-code results' ("success=[$helperSuccess] failure=[$helperFailure]")
}

# A gh that is installed but not logged in writes to stderr. Windows PowerShell
# 5.1 must not turn that redirected native stderr into a terminating error.
$ghFixture = Join-Path ([IO.Path]::GetTempPath()) ('tailchrome-gh-' + [guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $ghFixture | Out-Null
if ($WindowsTest) {
@'
@echo off
if "%1"=="auth" (
echo You are not logged into any GitHub hosts. 1>&2
exit /b 1
)
exit /b 0
'@ | Set-Content -LiteralPath (Join-Path $ghFixture 'gh.cmd') -Encoding Ascii
} else {
$ghScript = Join-Path $ghFixture 'gh'
"#!/bin/sh`nif [ `"`$1`" = auth ]; then echo 'You are not logged into any GitHub hosts.' >&2; exit 1; fi`nexit 0`n" |
Set-Content -LiteralPath $ghScript -NoNewline
& chmod +x $ghScript
}
$savedPath = $env:PATH
$env:PATH = $ghFixture + [IO.Path]::PathSeparator + $env:PATH
try {
$ghWarnings = (& $ProductionTestAvailableAttestation 'unused-artifact' 3>&1 | Out-String)
if ($ghWarnings -like '*GitHub CLI is not authenticated*') {
Pass 'warns instead of aborting when gh is installed but not logged in'
} else {
FailTest 'warns instead of aborting when gh is installed but not logged in' ("output=[$ghWarnings]")
}
} catch {
FailTest 'warns instead of aborting when gh is installed but not logged in' $_.Exception.Message
} finally {
$env:PATH = $savedPath
Remove-Item -LiteralPath $ghFixture -Recurse -Force -ErrorAction SilentlyContinue
}

New-Fixture
$popupBin = Join-Path $script:Fixture "scriptblock bin/owner's helper"
New-Item -ItemType Directory -Path $popupBin -Force | Out-Null
Expand Down
Loading