70 lines
2.8 KiB
PHP
70 lines
2.8 KiB
PHP
<?php
|
|
|
|
use App\Models\Operator;
|
|
use App\Services\Secrets\SecretVault;
|
|
use App\Support\OperatingMode;
|
|
|
|
/**
|
|
* Stripe ist vom Rückfall ausgenommen — in BEIDE Richtungen.
|
|
*
|
|
* Fiele der Testbetrieb bei fehlendem Testschlüssel auf den Live-Schlüssel
|
|
* zurück, bucht ein Testkauf echtes Geld ab, während die Konsole „Testbetrieb
|
|
* aktiv" anzeigt. Das ist die eine Stelle in diesem Vorhaben, deren Ausfall
|
|
* Geld kostet, und deshalb steht sie als eigener Test da statt als Kommentar.
|
|
*/
|
|
beforeEach(function () {
|
|
$this->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');
|
|
});
|
|
|
|
it('does not report the environment as the source of a strict key', function () {
|
|
// source() muss dieselbe Regel anwenden wie get(): ist der Eintrag strikt
|
|
// und der Platz des aktiven Modus leer, ist die Quelle 'none', nicht
|
|
// 'environment'. Sonst meldet die Konsole dem Betreiber einen Stripe-
|
|
// Schlüssel als „in Kraft" (source sagt 'environment'), während die
|
|
// Kasse ihn nicht benutzt (get gibt null zurück). Dieser stille Widerspruch
|
|
// ist genau die Art, gegen die dieses Vorhaben gebaut ist.
|
|
config()->set('services.stripe.secret', 'sk_live_from_env');
|
|
OperatingMode::set(OperatingMode::Test);
|
|
|
|
expect($this->vault->source('stripe.secret'))->toBe('none');
|
|
});
|