Skip to content

Generate test credentials at run time - #18

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

imanimanyara merged 2 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, the first release shipping TestCredentials and AssertsNoLiteralCredentials.
  • 10 flagged literals replaced (plus the other uses of the same values, so each test reads one source), 0 exempted:
    • the operator password: TestCase::PASSWORD (a constant cannot hold a generated value) becomes TestCase::password(), returning TestCredentials::password('operator'); its one caller is updated;
    • the wrong password (3 sites) is TestCredentials::password('wrong'), with a new assertion that it differs from the operator's;
    • the redaction canary (fixture command, SecretRedactorTest, AuditTest, ExecuteTest, SecurityReviewTest) is TestCredentials::secret('canary'), hex so it survives the redactor's NAME=value and URL parsing; every "never reaches the output" assertion reads the same value;
    • the config secrets the redactor must hide (reporting DB password, services.acme.secret) are generated.
  • New guard tests/Arch/NoLiteralCredentialsTest.php scans tests/ (47 files, floor 42). It sits in tests/Arch, which phpunit.xml already runs.
  • CHANGELOG [Unreleased] entry.

Verification

  • Scanner: 10 literals before, 0 after.
  • Pest 254 passed (253 before, plus the guard); laranail-pint passed; PHPStan no errors; Rector dry-run clean.
  • Red proof: appended $probe = ['password' => 'nope-nope']; to DestructiveTest.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: 0 (none present).

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. The operator password, the wrong
password, the redaction canary and the config secrets the redactor
must hide are now generated per run with TestCredentials; the
redaction tests still prove the value never reaches output. The
TestCase::PASSWORD constant becomes TestCase::password(), since a
constant cannot hold a generated value. A guard test in tests/Arch
fails the suite on any literal left behind. 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:38

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.

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 e7dcf43 into main Oct 19, 2026
14 checks passed
@imanimanyara
imanimanyara deleted the chore/generated-test-credentials branch October 19, 2026 14:49
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