Skip to content
Snippets Groups Projects
Verified Commit 2eaad711 authored by Dillenn Terumalai's avatar Dillenn Terumalai :speech_balloon:
Browse files

fix: Added base64 encoding/decoding for storing serialized class

parent abcc9a0f
No related branches found
No related tags found
No related merge requests found
Pipeline #5548 passed
......@@ -27,7 +27,7 @@ class JobModelFactory extends Factory
'job_name' => 'default',
'partition' => 'normal',
'payload' => serialize('random string'),
'job' => serialize('random string'),
'job' => base64_encode(serialize('random string')),
'std_out_path' => '/path/to/std/out',
'std_err_path' => '/path/to/std/err',
'export_path' => null,
......
......@@ -26,7 +26,7 @@ class DatabaseJobRepository implements JobRepository
'id' => $job->id,
'job_name' => $job->name,
'partition' => $job->partition,
'job' => serialize($job),
'job' => base64_encode(serialize($job)),
'payload' => serialize($payload),
'std_out_path' => "{$job->exportPath}/{$job->name}_{$job->id}.out",
'std_err_path' => "{$job->exportPath}/{$job->name}_{$job->id}.err",
......
......@@ -105,7 +105,7 @@ class JobModel extends Model
*/
public function getJobAttribute($value)
{
return unserialize($value, ['allowed_classes' => true]);
return unserialize(base64_decode($value), ['allowed_classes' => true]);
}
/**
......
......@@ -59,8 +59,8 @@ EOF";
{
$class = 'O:18:"App\Jobs\SimpleJob":5:{s:7:"message";s:6:"World!";s:4:"name";s:7:"default";s:9:"partition";s:6:"normal";s:6:"memory";s:2:"1G";s:7:"timeout";s:8:"00:01:00";}';
$clusterJob = JobModel::factory()->create(['job' => serialize($class)]);
$this->assertEquals($class, unserialize($clusterJob->getRawOriginal('job')));
$clusterJob = JobModel::factory()->create(['job' => base64_encode(serialize($class))]);
$this->assertEquals($class, unserialize(base64_decode($clusterJob->getRawOriginal('job'))));
}
/** @test */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment