Skip to content

Commit 5643f7b

Browse files
Marius StorhaugMarius Storhaug
authored andcommitted
test: print the secret and variable in plain text to show masking
Adds an It block that Write-Hosts both values. GitHub Actions masks TEST_SECRET (registered via ::add-mask:: by Import-TestData) to *** in the log, while TEST_VARIABLE is printed verbatim - demonstrating that only the secrets map is masked.
1 parent 39faaef commit 5643f7b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

tests/Environment.Tests.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
'PSUseDeclaredVarsMoreThanAssignments', '',
77
Justification = 'Required for Pester tests'
88
)]
9+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
10+
'PSAvoidUsingWriteHost', '',
11+
Justification = 'Deliberately prints the values to the log to demonstrate GitHub Actions masking'
12+
)]
913
[CmdletBinding()]
1014
param()
1115

@@ -27,4 +31,12 @@ Describe 'TestData is pushed into the module tests' {
2731
$actual | Should -Not -BeNullOrEmpty
2832
$actual | Should -BeExactly 'mariustestmodule-variable-fixture-value'
2933
}
34+
35+
It 'Masks the secret in the log even when a test prints it in plain text' {
36+
# Deliberately try to leak both values to the log with Write-Host. Because Import-TestData
37+
# registered the secret via ::add-mask::, GitHub Actions redacts it to *** in the log, while
38+
# the variable (not masked) is printed verbatim. Inspect the job log to see the difference.
39+
Write-Host "Secret in plain text: $env:TEST_SECRET"
40+
Write-Host "Variable in plain text: $env:TEST_VARIABLE"
41+
}
3042
}

0 commit comments

Comments
 (0)