Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ 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.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`
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.10",
"illuminate/auth": "^13.0",
"illuminate/bus": "^13.0",
"illuminate/console": "^13.0",
Expand Down
8 changes: 5 additions & 3 deletions tests/Feature/AuditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
});
});

Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/ConfigContractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/LifecycleEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/NotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions tests/Unit/Architecture/NoLiteralCredentialsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

use Simtabi\Laranail\Package\Tools\Testing\AssertsNoLiteralCredentials;

uses(AssertsNoLiteralCredentials::class);

it('keeps literal credentials out of the tests', function (): void {
$this->assertNoLiteralCredentialsIn([dirname(__DIR__, 2)], minFiles: 60);

expect(true)->toBeTrue();
});

it('names every generated credential with a single word', function (): void {
$this->assertCredentialPurposesAreWordsIn([dirname(__DIR__, 2)], minFiles: 60);

expect(true)->toBeTrue();
});
5 changes: 3 additions & 2 deletions tests/Unit/SecretLeakTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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]);

Expand Down
Loading