Skip to content

Commit 7815d48

Browse files
authored
Merge pull request #22 from lukewaite/fix_21_job_name_sanitization
Properly sanitize job names before passing to AWS Batch
2 parents d582c88 + f25cb24 commit 7815d48

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## [Unreleased]
44

5+
### Fixed
6+
* Correct sanitation of job names which previously blocked creation of class based batch jobs
7+
58
## v0.2.0 (2017-04-07)
69

710
### Added

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
"LukeWaite\\LaravelQueueAwsBatch\\": "src/"
99
}
1010
},
11+
"autoload-dev": {
12+
"psr-4": {
13+
":vendor\\:package_name\\": "tests"
14+
}
15+
},
1116
"require": {
1217
"illuminate/support": "~5.1.0",
1318
"aws/aws-sdk-php": "^3.20.6"

src/Queues/BatchQueue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function getDisplayName($job)
6363
{
6464
if (is_object($job)) {
6565
return method_exists($job, 'displayName')
66-
? $job->displayName() : get_class($job);
66+
? $job->displayName() : str_replace('\\', '_', (string)get_class($job));
6767
} else {
6868
return is_string($job) ? explode('@', $job)[0] : null;
6969
}

tests/BatchJobTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace LukeWaite\LaravelQueueAwsBatch\Tests;
4+
35
use Mockery as m;
46
use PHPUnit\Framework\TestCase;
57

tests/BatchQueueTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace LukeWaite\LaravelQueueAwsBatch\Tests;
4+
35
use Mockery as m;
46
use PHPUnit\Framework\TestCase;
57

@@ -51,6 +53,22 @@ public function testPushProperlyPushesJobOntoDatabase()
5153
$this->queue->push('foo', ['data']);
5254
}
5355

56+
public function testPushProperlySanitizesJobName()
57+
{
58+
$this->database->shouldReceive('table')->with('table')->andReturn($query = m::mock('StdClass'));
59+
60+
$query->shouldReceive('insertGetId')->once()->andReturnUsing(function ($array) {
61+
return 1;
62+
});
63+
64+
$this->batch->shouldReceive('submitJob')->once()->andReturnUsing(function ($array) {
65+
$this->assertRegExp('/^[a-zA-Z0-9_]+$/', $array['jobName']);
66+
$this->assertEquals('LukeWaite_LaravelQueueAwsBatch_Tests_TestJob', $array['jobName']);
67+
});
68+
69+
$this->queue->push(new TestJob());
70+
}
71+
5472
public function testGetJobById()
5573
{
5674
$this->database->shouldReceive('table')->once()->with('table')->andReturn($query = m::mock('StdClass'));
@@ -108,3 +126,8 @@ public function testReleaseWithDelayThrowsException()
108126
$this->queue->release('default', $job, 10);
109127
}
110128
}
129+
130+
class TestJob
131+
{
132+
//
133+
}

0 commit comments

Comments
 (0)