Skip to content

🌟 [Major]: Fixed test secret inputs replaced by TestData#365

Open
Marius Storhaug (MariusStorhaug) wants to merge 11 commits into
mainfrom
feat/52-test-secrets
Open

🌟 [Major]: Fixed test secret inputs replaced by TestData#365
Marius Storhaug (MariusStorhaug) wants to merge 11 commits into
mainfrom
feat/52-test-secrets

Conversation

@MariusStorhaug

@MariusStorhaug Marius Storhaug (MariusStorhaug) commented Jul 8, 2026

Copy link
Copy Markdown
Member

Module test jobs now use a TestData object for optional test secrets and non-secret variables. This replaces the previous fixed TEST_* workflow secret inputs: callers that used those inputs must pass the same names inside TestData, while callers that need different names can expose them without changing the shared workflow.

Breaking Changes

Removed: fixed TEST_* workflow secret inputs

The reusable workflow no longer declares or accepts these individual test-secret inputs:

  • TEST_APP_ENT_CLIENT_ID
  • TEST_APP_ENT_PRIVATE_KEY
  • TEST_APP_ORG_CLIENT_ID
  • TEST_APP_ORG_PRIVATE_KEY
  • TEST_USER_ORG_FG_PAT
  • TEST_USER_USER_FG_PAT
  • TEST_USER_PAT

Callers using any of these inputs must move them into the secrets map inside TestData. The names can stay the same, so existing Pester tests can continue reading the same environment variables.

jobs:
  Process-PSModule:
    uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@v5
    secrets:
      APIKey: ${{ secrets.APIKey }}
      TestData: >-
        { "secrets": { "TEST_USER_PAT": "${{ secrets.TEST_USER_PAT }}",
        "TEST_APP_ORG_CLIENT_ID": "${{ secrets.TEST_APP_ORG_CLIENT_ID }}" } }
$env:TEST_USER_PAT
$env:TEST_APP_ORG_CLIENT_ID

New: Caller-selected TestData

TestData is an optional single-line JSON object with secrets and variables maps. Entries from both maps become environment variables in BeforeAll-ModuleLocal, Test-ModuleLocal, and AfterAll-ModuleLocal.

TestData: >-
  { "secrets": { "CONFLUENCE_API_TOKEN": "${{ secrets.CONFLUENCE_API_TOKEN }}" },
  "variables": { "CONFLUENCE_SITE": ${{ toJSON(vars.CONFLUENCE_SITE) }},
  "CONFLUENCE_SPACE_KEY": ${{ toJSON(vars.CONFLUENCE_SPACE_KEY) }} } }
$env:CONFLUENCE_API_TOKEN # from the secrets map, masked in logs
$env:CONFLUENCE_SITE      # from the variables map, not masked

Values under secrets are masked before being exposed to the test jobs. Values under variables are exposed without masking for normal, non-sensitive configuration. Modules that do not need secrets or variables can omit TestData entirely.

Because the workflow does not use secrets: inherit, only the values explicitly listed in TestData are exposed to module tests.

New: Safe TestData validation and formatting

TestData must parse as a JSON object containing only optional secrets and variables maps. Values in those maps must be scalar values. Keys must be safe environment-variable names matching ^[A-Za-z_][A-Za-z0-9_]*$, must not be duplicated across secrets and variables, and must not override reserved variables such as PATH, CI, GITHUB_*, RUNNER_* or ACTIONS_*.

Pass TestData as a single-line value after YAML folding. Keep the JSON compact, or keep every JSON content line at the same indentation level inside the folded >- block.

Do not pretty-print TestData with nested indentation. YAML preserves more-indented lines inside a folded scalar, which can make GitHub register brace-only lines such as {, } or }, as individual masks and turn unrelated log output into ***.

Use the direct quoted form for single-line secrets:

"CONFLUENCE_API_TOKEN": "${{ secrets.CONFLUENCE_API_TOKEN }}"

Use toJSON(vars.NAME) for variables so normal configuration values are JSON-encoded safely:

"CONFLUENCE_SITE": ${{ toJSON(vars.CONFLUENCE_SITE) }}

For multi-line secrets, or secrets containing quotes or backslashes, base64-encode the secret and decode it in the test.

Technical Details

  • workflow.yml declares and forwards a single optional TestData secret instead of the seven fixed TEST_* secrets.
  • .github/scripts/Expose-TestData.ps1 contains the shared TestData parsing, validation, masking, and UTF-8 GITHUB_ENV export logic used by the ModuleLocal workflows.
  • BeforeAll-ModuleLocal.yml, Test-ModuleLocal.yml, and AfterAll-ModuleLocal.yml call the shared helper instead of duplicating the security-sensitive exposure logic.
  • Test-Module.yml no longer declares or exports the obsolete fixed TEST_* secrets.
  • The fixture-backed self-test workflows skip forked pull_request runs where repository secrets and variables are unavailable, while still running for trusted PRs, schedules, and manual dispatches.
  • The parse failure path uses stable messages that do not echo the raw secret payload, and secret keys are no longer printed in logs.
  • The self-test workflows pass dedicated fixture data through TestData, and the environment Pester tests assert the exact exposed secret and variable values.
  • README.md documents the breaking migration path, the TestData contract, safe YAML folding, safe key names, environment-scoped value usage, the difference between masked secrets and unmasked variables, and base64 guidance for complex secret values.
  • The diff also addresses Replace duplicated test-secret blocks with secrets: inherit in ModuleLocal workflows #322's duplicated fixed-secret pass-through without adopting broad secrets: inherit.

…via TestSecrets

Replaces the seven hard-coded TEST_* secrets with a single optional TestSecrets JSON input. The calling workflow decides which org/repo secrets to expose by building a JSON object with toJSON(secrets.<name>); each entry is expanded into an environment variable (multi-line safe and masked) in the BeforeAll/Test/AfterAll ModuleLocal jobs, so tests read them via $env:<name>. No secret names are hard-coded in the shared workflow and secrets: inherit is not required. Closes #52.
Comment thread .github/workflows/Workflow-Test-Default.yml Fixed
Comment thread .github/workflows/Workflow-Test-Default.yml Fixed
Comment thread .github/workflows/Workflow-Test-Default.yml Fixed
Comment thread .github/workflows/Workflow-Test-Default.yml Fixed
Comment thread .github/workflows/Workflow-Test-Default.yml Fixed
Comment thread .github/workflows/Workflow-Test-WithManifest.yml Fixed
Comment thread .github/workflows/Workflow-Test-WithManifest.yml Fixed
Comment thread .github/workflows/Workflow-Test-WithManifest.yml Fixed
Comment thread .github/workflows/Workflow-Test-WithManifest.yml Fixed
Comment thread .github/workflows/Workflow-Test-WithManifest.yml Fixed
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Super-linter summary

Language Validation result
CHECKOV Pass ✅
GITLEAKS Pass ✅
GIT_MERGE_CONFLICT_MARKERS Pass ✅
MARKDOWN Pass ✅
NATURAL_LANGUAGE Pass ✅
POWERSHELL Pass ✅
PRE_COMMIT Pass ✅
SPELL_CODESPELL Pass ✅
TRIVY Pass ✅
YAML Pass ✅

All files and directories linted successfully

For more information, see the GitHub Actions workflow run

Powered by Super-linter

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the reusable Process-PSModule GitHub Actions workflow to let calling workflows pass an optional TestSecrets JSON object, which is expanded into environment variables for the *-ModuleLocal test jobs—removing the previous fixed list of TEST_* secrets and avoiding secrets: inherit.

Changes:

  • Replaces the fixed seven TEST_* secret pass-throughs with a single optional TestSecrets secret in the top-level reusable workflow and its nested ModuleLocal workflows.
  • Adds a PowerShell step in BeforeAll-ModuleLocal, Test-ModuleLocal, and AfterAll-ModuleLocal to expand TestSecrets JSON into $GITHUB_ENV and mask values.
  • Updates self-test workflows and Pester environment tests, and rewrites the README Secrets documentation to describe TestSecrets.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/srcWithManifestTestRepo/tests/Environments/Environment.Tests.ps1 Adds assertion that a caller-defined env var flows through from TestSecrets.
tests/srcTestRepo/tests/Environment.Tests.ps1 Same validation as above for the default self-test repo.
README.md Updates Secrets documentation to describe APIKey + optional TestSecrets JSON.
.github/workflows/workflow.yml Declares TestSecrets and passes only that secret to ModuleLocal jobs.
.github/workflows/Workflow-Test-WithManifest.yml Builds TestSecrets JSON (including a literal proving arbitrary names).
.github/workflows/Workflow-Test-Default.yml Builds TestSecrets JSON (including a literal proving arbitrary names).
.github/workflows/Test-ModuleLocal.yml Adds the JSON→env expansion/masking step for tests.
.github/workflows/BeforeAll-ModuleLocal.yml Adds the JSON→env expansion/masking step for setup scripts.
.github/workflows/AfterAll-ModuleLocal.yml Adds the JSON→env expansion/masking step for teardown scripts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/Test-ModuleLocal.yml Outdated
Comment thread .github/workflows/BeforeAll-ModuleLocal.yml Outdated
Comment thread .github/workflows/AfterAll-ModuleLocal.yml Outdated
Comment thread README.md Outdated
…r-masking

A multi-line secret makes GitHub register every line (including standalone { and } braces) as its own mask, which over-masks unrelated log output (563 masked lines vs 25 on main). Use a folded (>-) block so the source stays readable but the secret value is a single line, registering one mask. Per-value protection is unchanged (the expose step still ::add-mask::es each value).
Copilot AI review requested due to automatic review settings July 8, 2026 01:36
Comment thread .github/workflows/Workflow-Test-Default.yml Fixed
Comment thread .github/workflows/Workflow-Test-WithManifest.yml Fixed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment thread .github/workflows/Test-ModuleLocal.yml Outdated
Comment thread .github/workflows/BeforeAll-ModuleLocal.yml Outdated
Comment thread .github/workflows/AfterAll-ModuleLocal.yml Outdated
Comment thread .github/workflows/Test-ModuleLocal.yml Outdated
…masking probe

Self-tests no longer depend on real repository secrets; they pass known throwaway values through TestSecrets so masking can be verified conclusively. Adds a temporary MASKPROBE that will be removed after log verification.
Copilot AI review requested due to automatic review settings July 8, 2026 01:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Comment thread tests/srcTestRepo/tests/Environment.Tests.ps1 Outdated
Comment thread tests/srcWithManifestTestRepo/tests/Environments/Environment.Tests.ps1 Outdated
Comment thread .github/workflows/Test-ModuleLocal.yml Outdated
Comment thread .github/workflows/BeforeAll-ModuleLocal.yml Outdated
Comment thread .github/workflows/AfterAll-ModuleLocal.yml Outdated
Comment thread README.md Outdated
Copilot AI review requested due to automatic review settings July 8, 2026 01:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Comment thread .github/workflows/Test-ModuleLocal.yml Outdated
Comment thread .github/workflows/Test-ModuleLocal.yml Outdated
Comment thread .github/workflows/BeforeAll-ModuleLocal.yml Outdated
Comment thread .github/workflows/BeforeAll-ModuleLocal.yml Outdated
Comment thread .github/workflows/AfterAll-ModuleLocal.yml Outdated
Comment thread .github/workflows/AfterAll-ModuleLocal.yml Outdated
Comment thread README.md Outdated
Self-tests now pass two dedicated, non-sensitive repository secrets (PSMODULE_TEST_SINGLELINE_SECRET, PSMODULE_TEST_MULTILINE_SECRET) through TestSecrets and assert the exact value and length (and multi-line integrity) in Environment.Tests.ps1. This exercises the real GitHub-secret path (masked, passed through, exposed as $env:<name>) instead of literal placeholders.
Copilot AI review requested due to automatic review settings July 8, 2026 02:15
Comment thread .github/workflows/Workflow-Test-Default.yml Fixed
Comment thread .github/workflows/Workflow-Test-WithManifest.yml Fixed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment thread .github/workflows/Test-ModuleLocal.yml Outdated
Comment thread .github/workflows/BeforeAll-ModuleLocal.yml Outdated
Comment thread .github/workflows/AfterAll-ModuleLocal.yml Outdated
Comment thread .github/workflows/Workflow-Test-Default.yml Outdated
Adds a TestVariables workflow input (symmetric to TestSecrets) that exposes caller-selected NON-SECRET values as environment variables in the module test jobs, without masking. The expose step is refactored into a shared helper that masks secrets but not variables. Self-tests prove it via a dedicated PSMODULE_TEST_VARIABLE repo variable (asserted value + length). README documents both.
Copilot AI review requested due to automatic review settings July 8, 2026 02:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment thread .github/workflows/Test-ModuleLocal.yml Outdated
Comment thread .github/workflows/BeforeAll-ModuleLocal.yml Outdated
Comment thread .github/workflows/AfterAll-ModuleLocal.yml Outdated
Comment thread README.md Outdated
@MariusStorhaug Marius Storhaug (MariusStorhaug) changed the title 🚀 [Feature]: Module tests can use caller-selected secrets and variables 🌟 [Major]: Test secret inputs moved to TestData Jul 8, 2026
@MariusStorhaug Marius Storhaug (MariusStorhaug) changed the title 🌟 [Major]: Test secret inputs moved to TestData 🌟 [Major]: Fixed test secret inputs replaced by TestData Jul 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 10 comments.

Comment thread .github/workflows/Test-ModuleLocal.yml Outdated
Comment thread .github/workflows/Test-ModuleLocal.yml Outdated
Comment thread .github/workflows/BeforeAll-ModuleLocal.yml Outdated
Comment thread .github/workflows/BeforeAll-ModuleLocal.yml Outdated
Comment thread .github/workflows/AfterAll-ModuleLocal.yml Outdated
Comment thread .github/workflows/AfterAll-ModuleLocal.yml Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread .github/workflows/workflow.yml

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comment thread .github/workflows/BeforeAll-ModuleLocal.yml
Comment thread .github/workflows/Test-ModuleLocal.yml
Comment thread .github/workflows/AfterAll-ModuleLocal.yml
Copilot AI review requested due to automatic review settings July 8, 2026 13:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread .github/workflows/workflow.yml

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Comment thread .github/scripts/Expose-TestData.ps1
Comment thread .github/scripts/Expose-TestData.ps1 Outdated
Copilot AI review requested due to automatic review settings July 8, 2026 13:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Comment thread .github/workflows/Workflow-Test-Default.yml
Comment thread .github/workflows/Workflow-Test-WithManifest.yml

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support passing arbitrary secrets as environment variables to test jobs

3 participants