Skip to content

Commit 830ba53

Browse files
experiment: pass all secrets and variables into module tests
Replaces the two hardcoded TestData fixtures with toJSON(secrets)/toJSON(vars) to dump every secret and variable, and rewrites the environment test to iterate and print every environment variable the job can see. Purpose: observe whether Import-TestData can enumerate a full dump (and how Actions masks secrets).
1 parent 344f360 commit 830ba53

2 files changed

Lines changed: 26 additions & 26 deletions

File tree

.github/workflows/Process-PSModule.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ jobs:
3030
uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@d4020f3c9c3621cebae5d8bf4ffaf10f55c1784a # v6.1.2
3131
secrets:
3232
APIKey: ${{ secrets.APIKey }}
33-
# E2E: push a secret (masked in logs) and a variable (not masked) into the module test jobs.
34-
# Import-TestData exposes each entry as $env:<name>; asserted in tests/Environment.Tests.ps1.
33+
# E2E EXPERIMENT: push ALL secrets and ALL variables into the module test jobs to see whether
34+
# Import-TestData can enumerate them. toJSON(secrets) serializes every secret and always
35+
# includes the auto-injected github_token; toJSON(vars) serializes every repo/org variable.
36+
# The tests iterate every environment variable and print it so the job log shows what is
37+
# visible (Actions redacts registered secret values to ***).
3538
TestData: >-
36-
{ "secrets": { "TEST_SECRET": "${{ secrets.TEST_SECRET }}" },
37-
"variables": { "TEST_VARIABLE": ${{ toJSON(vars.TEST_VARIABLE) }} } }
39+
{ "secrets": ${{ toJSON(secrets) }}, "variables": ${{ toJSON(vars) }} }

tests/Environment.Tests.ps1

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,28 @@
1313
[CmdletBinding()]
1414
param()
1515

16-
Describe 'TestData is pushed into the module tests' {
17-
# TEST_SECRET (from the "secrets" map, masked) and TEST_VARIABLE (from the "variables" map, not
18-
# masked) are public non-secret fixtures that exist only to prove the calling workflow can push
19-
# secrets and variables into the module test jobs. The calling workflow passes them through a
20-
# single TestData object and Import-TestData (from Install-PSModuleHelpers) exposes them as
21-
# environment variables; these tests confirm they arrive with the expected values.
16+
Describe 'TestData exposes all secrets and variables' {
17+
# EXPERIMENT: the calling workflow now passes every secret and every variable through the single
18+
# TestData object via toJSON(secrets)/toJSON(vars). Import-TestData (from Install-PSModuleHelpers)
19+
# exposes each entry as an environment variable. These tests iterate every environment variable
20+
# visible to the job and print it, so the job log shows exactly what reached the module tests.
21+
# GitHub Actions redacts any registered secret value to *** in the log; plain variables print
22+
# verbatim. Inspect the job log to see which names arrived and how they are rendered.
2223

23-
It 'Exposes the secret from the "secrets" map' {
24-
$actual = [System.Environment]::GetEnvironmentVariable('TEST_SECRET')
25-
$actual | Should -Not -BeNullOrEmpty
26-
$actual | Should -BeExactly 'mariustestmodule-secret-fixture-value'
24+
It 'Iterates every environment variable and prints what the job can see' {
25+
$all = Get-ChildItem env: | Sort-Object Name
26+
Write-Host "===== BEGIN environment dump ($($all.Count) variables) ====="
27+
foreach ($entry in $all) {
28+
Write-Host ("{0} = {1}" -f $entry.Name, $entry.Value)
29+
}
30+
Write-Host '===== END environment dump ====='
31+
$all.Count | Should -BeGreaterThan 0
2732
}
2833

29-
It 'Exposes the variable from the "variables" map' {
30-
$actual = [System.Environment]::GetEnvironmentVariable('TEST_VARIABLE')
31-
$actual | Should -Not -BeNullOrEmpty
32-
$actual | Should -BeExactly 'mariustestmodule-variable-fixture-value'
33-
}
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"
34+
It 'Reports the fixture secret and variable arrived' {
35+
# These two fixtures are part of the full dump (a repo secret and a repo variable). If the
36+
# full enumeration worked, both are present; the secret prints as *** because it is masked.
37+
Write-Host "TEST_SECRET = $env:TEST_SECRET"
38+
Write-Host "TEST_VARIABLE = $env:TEST_VARIABLE"
4139
}
4240
}

0 commit comments

Comments
 (0)