Skip to content

Commit c494cd5

Browse files
senamakelmedullabot
andcommitted
test(audit): deliver full foreign-account script as UTF-8 without BOM
Co-authored-by: Medulla <medulla@tinyhumans.ai>
1 parent 0eca18f commit c494cd5

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎crates/tinysecurity-audit/src/sink_windows_negative_tests.rs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ exit 0
352352
$file = Join-Path $PSHOME 'powershell.exe'
353353
$start = [Diagnostics.ProcessStartInfo]::new()
354354
$start.FileName = $file
355-
$start.Arguments = '-NoProfile -NonInteractive -Command "try { $o=[Console]::Out; $o.WriteLine(''audit-account-stage=94 bootstrap=1''); $s=[Console]::In.ReadToEnd(); $p=([int[]][char[]]$s.Substring(0,[Math]::Min(3,$s.Length)) -join ''-''); $e=[int]$s.StartsWith(''$ErrorActionPreference''); $o.WriteLine(''audit-account-stage=94 bootstrap=2 source-length=''+$s.Length+'' reader-codepage=''+[Console]::InputEncoding.CodePage+'' prefix=''+$p+'' expected-prefix=''+$e); $b=[ScriptBlock]::Create($s); $o.WriteLine(''audit-account-stage=94 bootstrap=3''); & $b } catch { $k=0; if($_.Exception -is [System.Management.Automation.ParseException]){$k=4}; if($_.Exception -is [System.Management.Automation.CommandNotFoundException]){$k=5}; $o.WriteLine(''audit-account-stage=95 category=''+$k+'' hresult=''+$_.Exception.HResult); if($null -ne $_.Exception.InnerException){$o.WriteLine(''audit-account-stage=95 inner-hresult=''+$_.Exception.InnerException.HResult)}; exit 89 }"'
355+
$start.Arguments = '-NoProfile -NonInteractive -Command "try { [Console]::InputEncoding=[Text.UTF8Encoding]::new($false); $s=[Console]::In.ReadToEnd(); if(-not $s.StartsWith(''$ErrorActionPreference'')){exit 89}; [Console]::WriteLine(''audit-account-stage=94 utf8-prefix=1''); & ([ScriptBlock]::Create($s)) } catch { exit 89 }"'
356356
$start.UseShellExecute = $false
357357
$start.UserName = $network.UserName
358358
$start.Domain = $network.Domain
@@ -374,17 +374,19 @@ exit 0
374374
$started = $true
375375
$stdout = $process.StandardOutput.ReadToEndAsync()
376376
$stderr = $process.StandardError.ReadToEndAsync()
377-
Write-Output ('audit-account-stage=97 writer-codepage=' + $process.StandardInput.Encoding.CodePage + ' preamble-length=' + $process.StandardInput.Encoding.GetPreamble().Length)
378-
$process.StandardInput.WriteLine($childScript)
379-
$process.StandardInput.Close()
377+
$inputWriter = [IO.StreamWriter]::new($process.StandardInput.BaseStream, [Text.UTF8Encoding]::new($false))
378+
try {
379+
Write-Output ('audit-account-stage=97 writer-codepage=' + $inputWriter.Encoding.CodePage + ' preamble-length=' + $inputWriter.Encoding.GetPreamble().Length)
380+
$inputWriter.WriteLine($childScript)
381+
} finally { $inputWriter.Dispose() }
380382
$stage = 40
381383
if (-not $process.WaitForExit(30000)) { throw 'ordinary account helper timeout' }
382384
$code = $process.ExitCode
383385
# Require every exact child phase once; raw stdout/stderr stay in memory.
384386
$requiredPhases = @('audit-account-stage=90 foreign-identity=1 nonadmin=1', 'audit-account-stage=91 exact-control-read=1', 'audit-account-stage=92 private-file-denials=6', 'audit-account-stage=93 namespace-denial=1')
385387
$allLines = @($stdout.Result.Split([char]10) | ForEach-Object { $_.TrimEnd([char]13) } | Where-Object { $_.Length -gt 0 })
386388
$lines = @($allLines | Where-Object { $requiredPhases -ccontains $_ })
387-
$diagnostics = @($allLines | Where-Object { $_ -cmatch '^audit-account-stage=94 bootstrap=[13]$|^audit-account-stage=94 bootstrap=2 source-length=[0-9]+ reader-codepage=[0-9]+ prefix=[0-9-]* expected-prefix=[01]$|^audit-account-stage=95 (category=[0-9]+ hresult=-?[0-9]+|inner-hresult=-?[0-9]+)$|^audit-account-stage=96 (child-entry|identity-read)=1$' })
389+
$diagnostics = @($allLines | Where-Object { $_ -cmatch '^audit-account-stage=94 utf8-prefix=1$|^audit-account-stage=96 (child-entry|identity-read)=1$' })
388390
foreach ($line in $allLines) {
389391
if (($requiredPhases -ccontains $line) -or ($diagnostics -ccontains $line)) { Write-Output $line }
390392
}

0 commit comments

Comments
 (0)