test: generate random test tokens instead of hard-coded literals#14
Conversation
Test fixtures passed literal token strings (e.g. 'token-1', 'tok-2') into SecureString construction. GitGuardian's "ConvertTo-SecureString Password" detector flagged the historical inline ConvertTo-SecureString variants as publicly-exposed secrets, and the literals were latent re-introduction risk even after the move to the New-TestSecureString helper. No test asserts on a token's contents -- they only need *a* token -- so: - Add New-TestToken, returning a fresh random value per call. - Make New-TestSecureString's -Value optional, defaulting to a random token when omitted (-Value retained for the rare value-dependent case). - Switch every call site to the random form; the env-var fallback test's literal token becomes New-TestToken. Asserted email/cloud literals are left intact. Net effect: zero credential-shaped literals in the test source, so neither GitGuardian nor PSScriptAnalyzer has anything to flag and a careless refactor can't reintroduce a real-looking secret here. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR refactors the test suite to use randomized test credentials instead of hardcoded literal strings. It introduces a new ChangesTest Token Randomization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates the PowerShell test suite to avoid any hard-coded, credential-shaped token literals by generating throwaway tokens at runtime, reducing the risk of secret-scanner false positives and accidental reintroduction of token-like strings in committed test sources.
Changes:
- Added
New-TestTokentest helper to generate a fresh GUID-based token string per call. - Updated
New-TestSecureStringso-Valueis optional and defaults to a random token. - Replaced literal token usages in unit tests with the random-token helpers (including the env-var fallback test).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/TestHelpers.ps1 | Adds New-TestToken and makes New-TestSecureString default to a generated token when -Value is omitted. |
| tests/Unit/Public/Connect-JsmService.tests.ps1 | Removes hard-coded token literals; uses New-TestSecureString / New-TestToken for token setup paths. |
| tests/Unit/Public/Get-JsmConnection.tests.ps1 | Removes hard-coded token literal; uses New-TestSecureString for the connection fixture. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
What
Test fixtures constructed SecureStrings from literal token strings (
'token-1','tok-2','token','bad', …). This removes those literals in favor of randomly generated values.New-TestTokentotests/TestHelpers.ps1, returning a fresh[guid]::NewGuid().ToString('N')per call.New-TestSecureString's-Valueoptional, defaulting to a random token when omitted (-Valueretained for the rare case a test depends on exact characters).Connect-JsmService.tests.ps1andGet-JsmConnection.tests.ps1to the random form; the env-var fallback test's literal token becomesNew-TestToken. Assertedemail/cloudliterals left intact.Why
GitGuardian's "ConvertTo-SecureString Password" detector flagged the historical inline
ConvertTo-SecureStringvariants of these fixtures as publicly-exposed secrets (the repo is public). The move toNew-TestSecureStringalready stopped the detector firing onmain, but the literal token strings remained a latent re-introduction risk. No test asserts on a token's contents — they only need a token — so generating them at runtime leaves zero credential-shaped literals in the test source: neither GitGuardian nor PSScriptAnalyzer has anything to flag, and a careless refactor can't reintroduce a real-looking secret here.Testing
./build.ps1 -Task Test— 118 passed, 0 failed, 2 skipped (pre-existing git-tag tests), PSScriptAnalyzer clean, coverage 100%.🤖 Generated with Claude Code
Summary by CodeRabbit