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
18 changes: 15 additions & 3 deletions app/Services/BulkEventUploadCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,33 @@ public static function key(string $token): string
/**
* Shared temp disk for validate → import. Never use `local` on deployed apps
* (Forge may still set BULK_UPLOAD_TEMP_DISK=local from the old example).
* Also reject glued .env values like `localFACEBOOK_CLIENT_ID=…`.
*/
public static function tempDisk(?string $cachedDisk = null): string
{
$configured = (string) ($cachedDisk ?: config('filesystems.bulk_upload_temp_disk', 's3'));
$cloud = (string) config('filesystems.cloud', 's3');
$disks = config('filesystems.disks', []);

if (app()->environment('local', 'testing')) {
return $configured !== '' ? $configured : 'local';
}

if ($configured === '' || $configured === 'local') {
return $cloud !== '' ? $cloud : 's3';
$usable = $configured !== ''
&& $configured !== 'local'
&& ! str_contains($configured, '=')
&& is_array($disks)
&& array_key_exists($configured, $disks);

if ($usable) {
return $configured;
}

if ($cloud !== '' && is_array($disks) && array_key_exists($cloud, $disks)) {
return $cloud;
}

return $configured;
return 's3';
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/Unit/BulkEventUploadCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,20 @@ public function test_temp_disk_rejects_local_outside_local_environment(): void
$this->assertSame('s3', BulkEventUploadCache::tempDisk('local'));
$this->assertSame('s3', BulkEventUploadCache::tempDisk('s3'));
}

public function test_temp_disk_rejects_glued_env_disk_name(): void
{
config([
'filesystems.bulk_upload_temp_disk' => 'localFACEBOOK_CLIENT_ID=138145760054704',
'filesystems.cloud' => 's3',
'app.env' => 'production',
]);
app()->detectEnvironment(fn () => 'production');

$this->assertSame('s3', BulkEventUploadCache::tempDisk());
$this->assertSame(
's3',
BulkEventUploadCache::tempDisk('localFACEBOOK_CLIENT_ID=138145760054704')
);
}
}
Loading