Skip to content

Generate test credentials at run time - #50

Merged
imanimanyara merged 3 commits into
mainfrom
chore/generated-test-credentials
Oct 19, 2026
Merged

imanimanyara merged 3 commits into
mainfrom
chore/generated-test-credentials

Conversation

@imanimanyara

@imanimanyara imanimanyara commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Why

GitGuardian raised 28 incidents across laranail by 2026-10-18; 27 were test literals or false positives, each closed by hand. A value generated at run time never reaches the repository, so there is nothing to report.

What changed

  • laranail/package-tools floor raised to ^0.1.9 (require-dev), the first release shipping TestCredentials and AssertsNoLiteralCredentials.
  • 15 flagged literals replaced (plus the positional uses of the same values, so each test reads one source):
    • AccessLogMiddlewareTest: the password, token and nested API key fed to redaction, and the value stored verbatim under an override, are generated; the redaction assertions are unchanged.
    • CrudControllerTest, AuditableTest: the guarded/hidden secret attribute values are generated; the audit test still proves the value never appears in the stored JSON.
    • FacadesTest: the OpenAI key keeps its sk- shape via sprintf('sk-%s', TestCredentials::secret('openai')); Gemini and Claude keys are generated.
    • TokenTest: the HMAC signing secret (8 sites) is TestCredentials::secret('signing').
    • RejectCommonPasswordsTest: the HIBP breached-password fixture (its hash is faked from the value) and the never-transmit plaintext are generated.
  • 4 exemptions, each marked on its line:
    • RejectCommonPasswordsTest: 'Summer2024' -- a weak input the zxcvbn rule must reject.
    • SecurityDataTest (2): 'not-an-array', 'not-a-list' under security.passwords -- malformed config values, not credentials.
    • ApiResponseTraitFeatureTest: 'password' => 'required' -- a validation rule, not a credential.
  • New PHPUnit guard tests/Architecture/NoLiteralCredentialsTest.php scans tests/ (127 files, floor 114), in a new Architecture testsuite in phpunit.xml.
  • CHANGELOG gains an [Unreleased] section with the entry.

Verification

  • Scanner: 19 literals before, 0 after.
  • Pest 1198 passed, 1 skipped (1197 before, plus the guard); laranail-pint passed; PHPStan no errors; Rector dry-run clean (its existing "skipped rule is never registered" warning is unchanged config, not from this PR).
  • Red proof: appended $probe = ['secret' => 's3cr3t']; to TokenTest.php, the guard failed naming that line, then restored the file with git checkout.

Follow-up: package-tools 0.1.10

This commit raises the laranail/package-tools floor to ^0.1.10 and adds a second test to NoLiteralCredentialsTest, assertCredentialPurposesAreWordsIn(), which fails the suite on any generated-credential purpose that is not a single plain lowercase word. Renamed 0 purposes (all were already single words). Markers removed: 3 whole comment lines -- SecurityDataTest.php (two) and ApiResponseTraitFeatureTest.php (one); both files now match main exactly, so neither literal line is in this diff. The RejectCommonPasswordsTest marker is still needed and stays.

Red proof: a scratch line calling TestCredentials::password() with a hyphenated purpose turned the new test red; the file was restored with git checkout HEAD, and nothing committed contains it. Local gates: Pest, laranail-pint, PHPStan and Rector all pass.

GitGuardian raised 28 incidents across laranail, nearly all of them
literal credentials in tests. Redaction inputs, signing secrets, LLM
API keys and HIBP fixture passwords are now generated per run with
TestCredentials. Four literals stay, marked with the reason: a weak
password the zxcvbn rule must reject, two malformed config values and
a validation rule. A PHPUnit guard fails the suite on any literal left
behind, in a new Architecture suite. Raises the laranail/package-tools
floor to ^0.1.9, the first release with these helpers.
Copilot AI balanced review requested due to automatic review settings October 19, 2026 12:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gitguardian

gitguardian Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

A marker trailing a literal's own line put that line in the pull
request's diff, and GitGuardian then reported the two malformed config
values already on main as passwords. On the line above, the literal's
line is unchanged from main and stays out of the diff.
Secret scanning reads a compound purpose passed to TestCredentials, such
as a hyphenated one, as the password itself, so a generated credential
can be reported as a leaked one. A single plain lowercase word never has
been. Rename every purpose to one word, and switch on
assertCredentialPurposesAreWordsIn() so a new compound purpose fails the
suite instead of reaching a pull request.

package-tools 0.1.10 ships that check and a scanner that no longer
reports some lines earlier releases did, so the floor rises to ^0.1.10
and exemption markers the scanner no longer needs are removed.
@imanimanyara
imanimanyara merged commit 7e0935d into main Oct 19, 2026
14 checks passed
@imanimanyara
imanimanyara deleted the chore/generated-test-credentials branch October 19, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants