fix(env): preserve empty service variable values (#10850)
This commit is contained in:
parent
9b060958aa
commit
b6a4c7383a
2 changed files with 46 additions and 1 deletions
|
|
@ -356,7 +356,7 @@ private function get_environment_variables(?string $environment_variable = null)
|
||||||
|
|
||||||
private function set_environment_variables(?string $environment_variable = null): ?string
|
private function set_environment_variables(?string $environment_variable = null): ?string
|
||||||
{
|
{
|
||||||
if (is_null($environment_variable) && $environment_variable === '') {
|
if (is_null($environment_variable)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$environment_variable = trim($environment_variable);
|
$environment_variable = trim($environment_variable);
|
||||||
|
|
|
||||||
45
tests/Feature/EnvironmentVariableValueCastingTest.php
Normal file
45
tests/Feature/EnvironmentVariableValueCastingTest.php
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Application;
|
||||||
|
use App\Models\EnvironmentVariable;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class);
|
||||||
|
|
||||||
|
it('stores null environment variable values as database null', function () {
|
||||||
|
$env = EnvironmentVariable::create([
|
||||||
|
'key' => 'NULL_VALUE',
|
||||||
|
'value' => null,
|
||||||
|
'resourceable_type' => Application::class,
|
||||||
|
'resourceable_id' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$rawValue = DB::table('environment_variables')
|
||||||
|
->where('id', $env->id)
|
||||||
|
->value('value');
|
||||||
|
|
||||||
|
expect($rawValue)->toBeNull();
|
||||||
|
|
||||||
|
$env->refresh();
|
||||||
|
expect($env->value)->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preserves intentional empty string environment variable values', function () {
|
||||||
|
$env = EnvironmentVariable::create([
|
||||||
|
'key' => 'EMPTY_STRING_VALUE',
|
||||||
|
'value' => '',
|
||||||
|
'resourceable_type' => Application::class,
|
||||||
|
'resourceable_id' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$rawValue = DB::table('environment_variables')
|
||||||
|
->where('id', $env->id)
|
||||||
|
->value('value');
|
||||||
|
|
||||||
|
expect($rawValue)->not->toBeNull()
|
||||||
|
->and(decrypt($rawValue))->toBe('');
|
||||||
|
|
||||||
|
$env->refresh();
|
||||||
|
expect($env->value)->toBe('');
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue