-
Notifications
You must be signed in to change notification settings - Fork 0
🌟 [Major]: Fixed test secret inputs replaced by TestData #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Marius Storhaug (MariusStorhaug)
wants to merge
11
commits into
main
Choose a base branch
from
feat/52-test-secrets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fdb8ae5
🚀 [Feature]: Modules can expose caller-selected secrets to test jobs …
MariusStorhaug 772d65f
🩹 [Patch]: Pass TestSecrets as a single-line value to prevent log ove…
MariusStorhaug e5dfca3
🧪 [Test]: Use throwaway temp secret values in self-tests + temporary …
MariusStorhaug 93ca6f2
🧪 [Test]: Remove temporary masking probe after verifying secrets rend…
MariusStorhaug c501e35
🧪 [Test]: Prove TestSecrets plumbing with dedicated repo secrets
MariusStorhaug 5ae2f4c
🚀 [Feature]: Add TestVariables input for non-secret test configuration
MariusStorhaug ea01935
♻️ [Maintenance]: Combine TestSecrets and TestVariables into a single…
MariusStorhaug 06d6d85
Document safe TestData formatting
MariusStorhaug 39864d1
Document TestData migration path
MariusStorhaug cdfd9ae
Harden TestData parsing per review
MariusStorhaug 4dc521f
Extract shared TestData exposure helper
MariusStorhaug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| if ([string]::IsNullOrWhiteSpace($env:PSMODULE_TEST_DATA)) { | ||
| Write-Output 'No test data was provided by the calling workflow.' | ||
| return | ||
| } | ||
| try { | ||
| $data = $env:PSMODULE_TEST_DATA | ConvertFrom-Json -ErrorAction Stop | ||
| } catch { | ||
| throw "The 'TestData' secret must be valid JSON with 'secrets' and/or 'variables' maps." | ||
| } | ||
| if ($null -eq $data -or $data -isnot [pscustomobject]) { | ||
| throw "The 'TestData' secret must be a JSON object with 'secrets' and/or 'variables' maps." | ||
| } | ||
| $allowedTopLevelKeys = @('secrets', 'variables') | ||
| foreach ($propertyName in $data.PSObject.Properties.Name) { | ||
| if ($allowedTopLevelKeys -notcontains $propertyName) { | ||
| throw "The 'TestData' secret only supports 'secrets' and 'variables' maps." | ||
| } | ||
| } | ||
| $reservedNames = @('CI', 'HOME', 'PATH', 'PWD', 'SHELL', 'PSMODULE_TEST_DATA') | ||
| $reservedPrefixes = @('GITHUB_', 'RUNNER_', 'ACTIONS_') | ||
| function Assert-EnvironmentName { | ||
| <# | ||
| .SYNOPSIS | ||
| Validates that a TestData key can safely be written to GITHUB_ENV. | ||
| #> | ||
| param([string] $Name) | ||
| if ($Name -notmatch '^[A-Za-z_][A-Za-z0-9_]*$') { | ||
| throw 'TestData keys must be valid environment variable names.' | ||
| } | ||
| $normalized = $Name.ToUpperInvariant() | ||
| if ($reservedNames -contains $normalized) { | ||
| throw 'TestData keys must not override reserved environment variables.' | ||
| } | ||
| foreach ($prefix in $reservedPrefixes) { | ||
| if ($normalized.StartsWith($prefix)) { | ||
| throw 'TestData keys must not override reserved environment variables.' | ||
| } | ||
| } | ||
| } | ||
| function Assert-Map { | ||
| <# | ||
| .SYNOPSIS | ||
| Validates that a TestData section is a JSON object map. | ||
| #> | ||
| param( | ||
| [object] $Map, | ||
| [string] $Name | ||
| ) | ||
| if ($null -eq $Map) { return } | ||
| if ($Map -isnot [pscustomobject]) { | ||
| throw "The 'TestData.$Name' value must be a JSON object." | ||
| } | ||
| } | ||
| function Get-EnvironmentValue { | ||
| <# | ||
| .SYNOPSIS | ||
| Converts a scalar TestData value to an environment variable value. | ||
| #> | ||
| param( | ||
| [object] $Value, | ||
| [string] $Name | ||
| ) | ||
| if ($null -eq $Value) { return '' } | ||
| if ( | ||
| $Value -is [pscustomobject] -or | ||
| ($Value -is [System.Collections.IEnumerable] -and $Value -isnot [string]) | ||
| ) { | ||
| throw "Values in 'TestData.$Name' must be scalar values." | ||
| } | ||
| return [string]$Value | ||
| } | ||
| function Add-EnvFromMap { | ||
| <# | ||
| .SYNOPSIS | ||
| Writes validated TestData entries to GITHUB_ENV. | ||
| #> | ||
| param( | ||
| [object] $Map, | ||
| [string] $Name, | ||
| [switch] $Mask | ||
| ) | ||
| Assert-Map -Map $Map -Name $Name | ||
| if ($null -eq $Map) { return } | ||
| $count = 0 | ||
| foreach ($item in $Map.PSObject.Properties) { | ||
| $name = $item.Name | ||
| Assert-EnvironmentName -Name $name | ||
| $value = Get-EnvironmentValue -Value $item.Value -Name $Name | ||
| if ($Mask) { | ||
| foreach ($line in ($value -split "`n")) { | ||
| $line = $line.TrimEnd("`r") | ||
| if ($line.Length -gt 0) { | ||
| Write-Output "::add-mask::$line" | ||
| } | ||
| } | ||
| } | ||
| do { | ||
| $delimiter = "GHENV_$([guid]::NewGuid().ToString('N'))" | ||
| } while ($value.Contains($delimiter)) | ||
| Add-Content -Path $env:GITHUB_ENV -Value "$name<<$delimiter" -Encoding utf8 | ||
| Add-Content -Path $env:GITHUB_ENV -Value $value -Encoding utf8 | ||
| Add-Content -Path $env:GITHUB_ENV -Value $delimiter -Encoding utf8 | ||
| $count++ | ||
| } | ||
| if ($count -gt 0) { | ||
| if ($Mask) { | ||
| Write-Output "Exposed $count secret value(s) as environment variables." | ||
| } else { | ||
| Write-Output "Exposed $count variable value(s) as environment variables." | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Assert-Map -Map $data.secrets -Name 'secrets' | ||
| Assert-Map -Map $data.variables -Name 'variables' | ||
|
|
||
| $secretNames = @() | ||
| if ($null -ne $data.secrets) { | ||
| $secretNames = @($data.secrets.PSObject.Properties.Name) | ||
| } | ||
| $variableNames = @() | ||
| if ($null -ne $data.variables) { | ||
| $variableNames = @($data.variables.PSObject.Properties.Name) | ||
| } | ||
| $secretNameSet = [System.Collections.Generic.HashSet[string]]::new( | ||
| [System.StringComparer]::OrdinalIgnoreCase | ||
| ) | ||
| foreach ($secretName in $secretNames) { | ||
| [void] $secretNameSet.Add($secretName) | ||
| } | ||
| foreach ($variableName in $variableNames) { | ||
| if ($secretNameSet.Contains($variableName)) { | ||
| throw 'TestData keys must not be duplicated across secrets and variables.' | ||
| } | ||
| } | ||
|
|
||
| Add-EnvFromMap -Map $data.secrets -Name 'secrets' -Mask | ||
| Add-EnvFromMap -Map $data.variables -Name 'variables' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.