From 5e3ded7696babdb940a99bf95611036549a08766 Mon Sep 17 00:00:00 2001 From: Imani Manyara Date: Mon, 19 Oct 2026 08:38:21 -0400 Subject: [PATCH 1/2] Generate test credentials at run time Secret scanning cannot tell a test password from a leaked one: GitGuardian raised 28 incidents across laranail, 27 of them test literals closed by hand. Tests now take secrets and tokens from package-tools' TestCredentials, and a guard test fails on any literal left behind. The package-tools floor rises to ^0.1.9, the release that ships the helpers, so the prefer-lowest legs resolve them. --- CHANGELOG.md | 4 ++++ composer.json | 2 +- tests/Feature/AuditTest.php | 8 +++++--- tests/Feature/ConfigContractTest.php | 3 ++- tests/Feature/LifecycleEventsTest.php | 3 ++- tests/Feature/NotificationsTest.php | 3 ++- .../Unit/Architecture/NoLiteralCredentialsTest.php | 13 +++++++++++++ tests/Unit/SecretLeakTest.php | 5 +++-- 8 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 tests/Unit/Architecture/NoLiteralCredentialsTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 1321ba3..1973f1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- **Test credentials are generated at run time.** Secrets and tokens in the tests come from + `TestCredentials` instead of literals, which secret scanning reported as leaks. A guard test + fails on any literal left behind. The `laranail/package-tools` floor is now `^0.1.9`, the + release that ships these helpers. - **The editor prompts through `laranail/console` instead of `laravel/prompts`.** `laranail::env-kit.edit` imported `select()`, `text()`, `confirm()` and `SelectPrompt` from `laravel/prompts` without declaring the package; it arrived only because `laranail/console` diff --git a/composer.json b/composer.json index e62f789..a083b90 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "php": "^8.4.1 || ^8.5", "ext-mbstring": "*", "laranail/console": "^0.1.7", - "laranail/package-tools": "^0.1", + "laranail/package-tools": "^0.1.9", "illuminate/auth": "^13.0", "illuminate/bus": "^13.0", "illuminate/console": "^13.0", diff --git a/tests/Feature/AuditTest.php b/tests/Feature/AuditTest.php index 3cfa353..3cfc67d 100644 --- a/tests/Feature/AuditTest.php +++ b/tests/Feature/AuditTest.php @@ -10,6 +10,7 @@ use Simtabi\Laranail\EnvKit\Headless\Audit\FileAuditSink; use Simtabi\Laranail\EnvKit\Headless\Document\EnvDocument; use Simtabi\Laranail\EnvKit\Headless\Pipeline\Pipes\Audit; +use Simtabi\Laranail\Package\Tools\Testing\TestCredentials; use Simtabi\Laranail\EnvKit\Headless\Pipeline\CommitContext; use Simtabi\Laranail\EnvKit\Headless\Security\SecretRedactor; use Simtabi\Laranail\EnvKit\Headless\Contracts\AuditSinkInterface; @@ -43,11 +44,12 @@ Event::fake(); $this->bindEnv("A=1\n", ['laranail.env-kit.auto_backup' => false]); - EnvKit::set('API_TOKEN', 'abc123'); + $value = TestCredentials::secret('token'); + EnvKit::set('API_TOKEN', $value); - Event::assertDispatched(AfterWrite::class, function (AfterWrite $event): bool { + Event::assertDispatched(AfterWrite::class, function (AfterWrite $event) use ($value): bool { return $event->changes[0]['key'] === 'API_TOKEN' - && $event->changes[0]['new'] !== 'abc123'; // masked (API_TOKEN matches *_TOKEN) + && $event->changes[0]['new'] !== $value; // masked (API_TOKEN matches *_TOKEN) }); }); diff --git a/tests/Feature/ConfigContractTest.php b/tests/Feature/ConfigContractTest.php index 165eb7f..7848e65 100644 --- a/tests/Feature/ConfigContractTest.php +++ b/tests/Feature/ConfigContractTest.php @@ -4,6 +4,7 @@ use Simtabi\Laranail\EnvKit\Headless\EnvKitManager; use Simtabi\Laranail\EnvKit\Headless\Tests\TestCase; +use Simtabi\Laranail\Package\Tools\Testing\TestCredentials; use Simtabi\Laranail\EnvKit\Headless\Contracts\ValueCipherInterface; use Simtabi\Laranail\EnvKit\Headless\Exceptions\ProtectedKeyException; @@ -104,7 +105,7 @@ function shippedEnvKitConfig(): array // The concrete class, not Throwable: Pest's toThrow() falls back to matching the *message* // for anything class_exists() rejects, and Throwable is an interface -- so the loose spelling // silently asserts that the message contains the word 'Throwable'. - expect(fn () => EnvKit::set('DB_PASSWORD', 'should-be-refused'))->toThrow(ProtectedKeyException::class); + expect(fn () => EnvKit::set('DB_PASSWORD', TestCredentials::secret('refused')))->toThrow(ProtectedKeyException::class); }); it('can build a cipher for every driver its config can name', function (): void { diff --git a/tests/Feature/LifecycleEventsTest.php b/tests/Feature/LifecycleEventsTest.php index 11c85bc..b0f443b 100644 --- a/tests/Feature/LifecycleEventsTest.php +++ b/tests/Feature/LifecycleEventsTest.php @@ -11,6 +11,7 @@ use Simtabi\Laranail\EnvKit\Headless\Events\BackupCreated; use Simtabi\Laranail\EnvKit\Headless\Events\BeforeRestore; use Simtabi\Laranail\EnvKit\Headless\Events\WriteRejected; +use Simtabi\Laranail\Package\Tools\Testing\TestCredentials; use Simtabi\Laranail\EnvKit\Headless\Events\WriteRolledBack; use Simtabi\Laranail\EnvKit\Headless\Events\ConflictDetected; use Simtabi\Laranail\EnvKit\Headless\Contracts\WriterInterface; @@ -26,7 +27,7 @@ app(EnvKitConfigurator::class)->resolveActorUsing(fn () => 'alice'); Event::fake([BeforeWrite::class, AfterWrite::class]); - EnvKit::set('WIDGET_PASSWORD', 'newsecret'); + EnvKit::set('WIDGET_PASSWORD', TestCredentials::secret('widget')); Event::assertDispatched(BeforeWrite::class, fn (BeforeWrite $e) => $e->actor === 'alice' && $e->operation === 'write' diff --git a/tests/Feature/NotificationsTest.php b/tests/Feature/NotificationsTest.php index e46e6db..2d92079 100644 --- a/tests/Feature/NotificationsTest.php +++ b/tests/Feature/NotificationsTest.php @@ -6,6 +6,7 @@ use Illuminate\Notifications\AnonymousNotifiable; use Simtabi\Laranail\EnvKit\Headless\Facades\EnvKit; use Simtabi\Laranail\EnvKit\Headless\Tests\TestCase; +use Simtabi\Laranail\Package\Tools\Testing\TestCredentials; use Simtabi\Laranail\EnvKit\Headless\Extension\EnvKitConfigurator; use Simtabi\Laranail\EnvKit\Headless\Notifications\EnvKitEventNotification; @@ -67,7 +68,7 @@ function enableEnvKitNotifications(): array app(EnvKitConfigurator::class)->resolveActorUsing(fn () => 'alice'); Notification::fake(); - EnvKit::set('WIDGET_PASSWORD', 'newsecret'); + EnvKit::set('WIDGET_PASSWORD', TestCredentials::secret('widget')); Notification::assertSentOnDemand( EnvKitEventNotification::class, diff --git a/tests/Unit/Architecture/NoLiteralCredentialsTest.php b/tests/Unit/Architecture/NoLiteralCredentialsTest.php new file mode 100644 index 0000000..3fe1d03 --- /dev/null +++ b/tests/Unit/Architecture/NoLiteralCredentialsTest.php @@ -0,0 +1,13 @@ +assertNoLiteralCredentialsIn([dirname(__DIR__, 2)], minFiles: 60); + + expect(true)->toBeTrue(); +}); diff --git a/tests/Unit/SecretLeakTest.php b/tests/Unit/SecretLeakTest.php index cfd2abb..efc5eeb 100644 --- a/tests/Unit/SecretLeakTest.php +++ b/tests/Unit/SecretLeakTest.php @@ -2,12 +2,13 @@ declare(strict_types=1); +use Simtabi\Laranail\Package\Tools\Testing\TestCredentials; use Simtabi\Laranail\EnvKit\Headless\Security\SecretRedactor; use Simtabi\Laranail\EnvKit\Headless\Security\ValueSanitizer; use Simtabi\Laranail\EnvKit\Headless\Exceptions\InvalidValueException; it('never puts a raw secret value in an exception message', function () { - $secret = 'super-secret-token-ABC123'; + $secret = TestCredentials::secret('leak'); $thrown = null; try { @@ -22,7 +23,7 @@ }); it('scrubs a secret out of any message via the redactor', function () { - $secret = 'test-secret-not-real'; + $secret = TestCredentials::secret('scrub'); $scrubbed = (new SecretRedactor)->scrub('dsn=postgres://u:' . $secret . '@h/db', [$secret]); From 94f9ef9ab05eb29cc0b468544fb5f540287d0227 Mon Sep 17 00:00:00 2001 From: Imani Manyara Date: Mon, 19 Oct 2026 10:31:20 -0400 Subject: [PATCH 2/2] Adopt package-tools 0.1.10's credential checks GitGuardian reads a compound purpose such as TestCredentials::password('smtp-new') as the password itself, so a generated credential can be reported as a leaked one. package-tools 0.1.10 adds assertCredentialPurposesAreWordsIn(), which fails on any purpose that is not a single plain lowercase word; the guard test now runs it beside the literal check, over the same directories and file floor. Raise the package-tools floor to ^0.1.10 for it. That release's scanner also recognises Eloquent cast names, provider names and reference keys as non-credentials, so exemption markers it no longer needs are removed. Each was checked by confirming CredentialLiterals::in() reports nothing on the line the marker covered. --- CHANGELOG.md | 5 +++-- composer.json | 2 +- tests/Unit/Architecture/NoLiteralCredentialsTest.php | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1973f1e..31489ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,8 +26,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Test credentials are generated at run time.** Secrets and tokens in the tests come from `TestCredentials` instead of literals, which secret scanning reported as leaks. A guard test - fails on any literal left behind. The `laranail/package-tools` floor is now `^0.1.9`, the - release that ships these helpers. + fails on any literal left behind. The `laranail/package-tools` floor is now `^0.1.10`, which + adds a second check: every purpose passed to `TestCredentials` must be a single plain lowercase + word, because secret scanning reads a compound purpose as the password itself. - **The editor prompts through `laranail/console` instead of `laravel/prompts`.** `laranail::env-kit.edit` imported `select()`, `text()`, `confirm()` and `SelectPrompt` from `laravel/prompts` without declaring the package; it arrived only because `laranail/console` diff --git a/composer.json b/composer.json index a083b90..74a555a 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "php": "^8.4.1 || ^8.5", "ext-mbstring": "*", "laranail/console": "^0.1.7", - "laranail/package-tools": "^0.1.9", + "laranail/package-tools": "^0.1.10", "illuminate/auth": "^13.0", "illuminate/bus": "^13.0", "illuminate/console": "^13.0", diff --git a/tests/Unit/Architecture/NoLiteralCredentialsTest.php b/tests/Unit/Architecture/NoLiteralCredentialsTest.php index 3fe1d03..b9b8a26 100644 --- a/tests/Unit/Architecture/NoLiteralCredentialsTest.php +++ b/tests/Unit/Architecture/NoLiteralCredentialsTest.php @@ -11,3 +11,9 @@ expect(true)->toBeTrue(); }); + +it('names every generated credential with a single word', function (): void { + $this->assertCredentialPurposesAreWordsIn([dirname(__DIR__, 2)], minFiles: 60); + + expect(true)->toBeTrue(); +});