From 59e868963027f487ce72ecfce92562ad0adf9895 Mon Sep 17 00:00:00 2001 From: nexxo Date: Thu, 30 Jul 2026 11:01:33 +0200 Subject: [PATCH] Never spend real money while the switch says test Co-Authored-By: Claude Opus 5 --- app/Services/Secrets/SecretVault.php | 6 +++ tests/Feature/StripeStrictModeTest.php | 56 ++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 tests/Feature/StripeStrictModeTest.php diff --git a/app/Services/Secrets/SecretVault.php b/app/Services/Secrets/SecretVault.php index 1743a7f..9969aff 100644 --- a/app/Services/Secrets/SecretVault.php +++ b/app/Services/Secrets/SecretVault.php @@ -80,6 +80,12 @@ final class SecretVault 'label' => 'secrets.item.stripe_secret', 'check' => StripeCheck::class, 'env_key' => 'STRIPE_SECRET', + // Kein Rückfall, in keine Richtung, und auch nicht auf die Umgebung. + // Ohne das benutzt ein Testkauf bei fehlendem Testschlüssel still den + // Live-Schlüssel und bucht echtes Geld ab, während die Konsole + // „Testbetrieb aktiv" anzeigt. Jeder andere Eintrag hier bezeichnet + // dasselbe Konto in beiden Modi; dieser nicht. + 'strict' => true, ], 'dns.token' => [ 'config' => 'provisioning.dns.token', diff --git a/tests/Feature/StripeStrictModeTest.php b/tests/Feature/StripeStrictModeTest.php new file mode 100644 index 0000000..157b8ad --- /dev/null +++ b/tests/Feature/StripeStrictModeTest.php @@ -0,0 +1,56 @@ +by = Operator::factory()->create(); + $this->vault = app(SecretVault::class); +}); + +it('does not use the live key while the test mode is active', function () { + $this->vault->put('stripe.secret', 'sk_live_real', $this->by, OperatingMode::Live); + OperatingMode::set(OperatingMode::Test); + + expect($this->vault->get('stripe.secret'))->toBeNull(); +}); + +it('does not use the test key while the live mode is active', function () { + $this->vault->put('stripe.secret', 'sk_test_fake', $this->by, OperatingMode::Test); + OperatingMode::set(OperatingMode::Live); + + expect($this->vault->get('stripe.secret'))->toBeNull(); +}); + +it('ignores the environment for stripe as well', function () { + // Sonst wäre die .env die Hintertür, durch die der Live-Schlüssel doch in + // den Testbetrieb kommt. + config()->set('services.stripe.secret', 'sk_live_from_env'); + OperatingMode::set(OperatingMode::Test); + + expect($this->vault->get('stripe.secret'))->toBeNull(); +}); + +it('uses the key of the active mode when it is there', function () { + $this->vault->put('stripe.secret', 'sk_test_fake', $this->by, OperatingMode::Test); + OperatingMode::set(OperatingMode::Test); + + expect($this->vault->get('stripe.secret'))->toBe('sk_test_fake'); +}); + +it('lets every other entry keep falling back', function () { + // Die Ausnahme ist eine Ausnahme, keine neue Regel. + $this->vault->put('dns.token', 'live-token', $this->by, OperatingMode::Live); + OperatingMode::set(OperatingMode::Test); + + expect($this->vault->get('dns.token'))->toBe('live-token'); +});