| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dbad947 commit cbaf65e
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,27 @@ | |||
| 1 | 1 | <?php | |
| 2 | 2 | ||
| 3 | + use Illuminate\Encryption\Encrypter; | ||
| 4 | + | ||
| 3 | 5 | class IlluminateQueueClosure { | |
| 4 | 6 | ||
| 7 | + /** | ||
| 8 | + * The encrypter instance. | ||
| 9 | + * | ||
| 10 | + * @var \Illuminate\Encryption\Encrypter $crypt | ||
| 11 | + */ | ||
| 12 | + protected $crypt; | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * Create a new queued Closure job. | ||
| 16 | + * | ||
| 17 | + * @param \Illuminate\Encryption\Encrypter $crypt | ||
| 18 | + * @return void | ||
| 19 | + */ | ||
| 20 | + public function __construct(Encrypter $crypt) | ||
| 21 | + { | ||
| 22 | + $this->crypt = $crypt; | ||
| 23 | + } | ||
| 24 | + | ||
| 5 | 25 | /** | |
| 6 | 26 | * Fire the Closure based queue job. | |
| 7 | 27 | * | |
@@ -11,7 +31,7 @@ class IlluminateQueueClosure { | |||
| 11 | 31 | */ | |
| 12 | 32 | public function fire($job, $data) | |
| 13 | 33 | { | |
| 14 | - $closure = unserialize($data['closure']); | ||
| 34 | + $closure = unserialize($this->crypt->decrypt($data['closure'])); | ||
| 15 | 35 | ||
| 16 | 36 | $closure($job); | |
| 17 | 37 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,6 @@ | |||
| 4 | 4 | use Illuminate\Http\Request; | |
| 5 | 5 | use Illuminate\Http\Response; | |
| 6 | 6 | use Illuminate\Queue\Jobs\IronJob; | |
| 7 | - use Illuminate\Encryption\Encrypter; | ||
| 8 | 7 | ||
| 9 | 8 | class IronQueue extends Queue implements QueueInterface { | |
| 10 | 9 | ||
@@ -15,13 +14,6 @@ class IronQueue extends Queue implements QueueInterface { | |||
| 15 | 14 | */ | |
| 16 | 15 | protected $iron; | |
| 17 | 16 | ||
| 18 | - /** | ||
| 19 | - * The encrypter instance. | ||
| 20 | - * | ||
| 21 | - * @var \Illuminate\Encryption\Encrypter | ||
| 22 | - */ | ||
| 23 | - protected $crypt; | ||
| 24 | - | ||
| 25 | 17 | /** | |
| 26 | 18 | * The current request instance. | |
| 27 | 19 | * | |
@@ -47,16 +39,14 @@ class IronQueue extends Queue implements QueueInterface { | |||
| 47 | 39 | * Create a new IronMQ queue instance. | |
| 48 | 40 | * | |
| 49 | 41 | * @param \IronMQ $iron | |
| 50 | - * @param \Illuminate\Encryption\Encrypter $crypt | ||
| 51 | 42 | * @param \Illuminate\Http\Request $request | |
| 52 | 43 | * @param string $default | |
| 53 | 44 | * @param bool $shouldEncrypt | |
| 54 | 45 | * @return void | |
| 55 | 46 | */ | |
| 56 | - public function __construct(IronMQ $iron, Encrypter $crypt, Request $request, $default, $shouldEncrypt = false) | ||
| 47 | + public function __construct(IronMQ $iron, Request $request, $default, $shouldEncrypt = false) | ||
| 57 | 48 | { | |
| 58 | 49 | $this->iron = $iron; | |
| 59 | - $this->crypt = $crypt; | ||
| 60 | 50 | $this->request = $request; | |
| 61 | 51 | $this->default = $default; | |
| 62 | 52 | $this->shouldEncrypt = $shouldEncrypt; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | use Closure; | |
| 4 | 4 | use DateTime; | |
| 5 | 5 | use Illuminate\Container\Container; | |
| 6 | + use Illuminate\Encryption\Encrypter; | ||
| 6 | 7 | use Illuminate\Support\SerializableClosure; | |
| 7 | 8 | ||
| 8 | 9 | abstract class Queue { | |
@@ -69,7 +70,7 @@ protected function createPayload($job, $data = '', $queue = null) | |||
| 69 | 70 | */ | |
| 70 | 71 | protected function createClosurePayload($job, $data) | |
| 71 | 72 | { | |
| 72 | - $closure = serialize(new SerializableClosure($job)); | ||
| 73 | + $closure = $this->crypt->encrypt(serialize(new SerializableClosure($job))); | ||
| 73 | 74 | ||
| 74 | 75 | return array('job' => 'IlluminateQueueClosure', 'data' => compact('closure')); | |
| 75 | 76 | } | |
@@ -128,4 +129,15 @@ public function setContainer(Container $container) | |||
| 128 | 129 | $this->container = $container; | |
| 129 | 130 | } | |
| 130 | 131 | ||
| 132 | + /** | ||
| 133 | + * Set the encrypter instance. | ||
| 134 | + * | ||
| 135 | + * @param \Illuminate\Encryption\Encrypter $crypt | ||
| 136 | + * @return void | ||
| 137 | + */ | ||
| 138 | + public function setEncrypter(Encrypter $crypt) | ||
| 139 | + { | ||
| 140 | + $this->crypt = $crypt; | ||
| 141 | + } | ||
| 142 | + | ||
| 131 | 143 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,6 +69,8 @@ public function connection($name = null) | |||
| 69 | 69 | $this->connections[$name] = $this->resolve($name); | |
| 70 | 70 | ||
| 71 | 71 | $this->connections[$name]->setContainer($this->app); | |
| 72 | + | ||
| 73 | + $this->connections[$name]->setEncrypter($this->app['encrypter']); | ||
| 72 | 74 | } | |
| 73 | 75 | ||
| 74 | 76 | return $this->connections[$name]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | <?php namespace Illuminate\Queue; | |
| 2 | 2 | ||
| 3 | + use IlluminateQueueClosure; | ||
| 3 | 4 | use Illuminate\Support\ServiceProvider; | |
| 4 | 5 | use Illuminate\Queue\Console\WorkCommand; | |
| 5 | 6 | use Illuminate\Queue\Console\ListenCommand; | |
@@ -36,6 +37,8 @@ public function register() | |||
| 36 | 37 | $this->registerSubscriber(); | |
| 37 | 38 | ||
| 38 | 39 | $this->registerFailedJobServices(); | |
| 40 | + | ||
| 41 | + $this->registerQueueClosure(); | ||
| 39 | 42 | } | |
| 40 | 43 | ||
| 41 | 44 | /** | |
@@ -254,6 +257,19 @@ protected function registerFailedJobServices() | |||
| 254 | 257 | }); | |
| 255 | 258 | } | |
| 256 | 259 | ||
| 260 | + /** | ||
| 261 | + * Register the Illuminate queued closure job. | ||
| 262 | + * | ||
| 263 | + * @return void | ||
| 264 | + */ | ||
| 265 | + protected function registerQueueClosure() | ||
| 266 | + { | ||
| 267 | + $this->app->bindShared('IlluminateQueueClosure', function($app) | ||
| 268 | + { | ||
| 269 | + return new IlluminateQueueClosure($app['encrypter']); | ||
| 270 | + }); | ||
| 271 | + } | ||
| 272 | + | ||
| 257 | 273 | /** | |
| 258 | 274 | * Get the services provided by the provider. | |
| 259 | 275 | * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,9 @@ public function tearDown() | |||
| 12 | 12 | ||
| 13 | 13 | public function testPushProperlyPushesJobOntoIron() | |
| 14 | 14 | { | |
| 15 | - $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default', true); | ||
| 15 | + $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), m::mock('Illuminate\Http\Request'), 'default', true); | ||
| 16 | + $crypt = m::mock('Illuminate\Encryption\Encrypter'); | ||
| 17 | + $queue->setEncrypter($crypt); | ||
| 16 | 18 | $crypt->shouldReceive('encrypt')->once()->with(json_encode(array('job' => 'foo', 'data' => array(1, 2, 3), 'attempts' => 1, 'queue' => 'default')))->andReturn('encrypted'); | |
| 17 | 19 | $iron->shouldReceive('postMessage')->once()->with('default', 'encrypted', array())->andReturn((object) array('id' => 1)); | |
| 18 | 20 | $queue->push('foo', array(1, 2, 3)); | |
@@ -21,7 +23,9 @@ public function testPushProperlyPushesJobOntoIron() | |||
| 21 | 23 | ||
| 22 | 24 | public function testPushProperlyPushesJobOntoIronWithoutEncryption() | |
| 23 | 25 | { | |
| 24 | - $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default'); | ||
| 26 | + $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), m::mock('Illuminate\Http\Request'), 'default'); | ||
| 27 | + $crypt = m::mock('Illuminate\Encryption\Encrypter'); | ||
| 28 | + $queue->setEncrypter($crypt); | ||
| 25 | 29 | $crypt->shouldReceive('encrypt')->never(); | |
| 26 | 30 | $iron->shouldReceive('postMessage')->once()->with('default', json_encode(['job' => 'foo', 'data' => [1, 2, 3], 'attempts' => 1, 'queue' => 'default']), array())->andReturn((object) array('id' => 1)); | |
| 27 | 31 | $queue->push('foo', array(1, 2, 3)); | |
@@ -30,11 +34,14 @@ public function testPushProperlyPushesJobOntoIronWithoutEncryption() | |||
| 30 | 34 | ||
| 31 | 35 | public function testPushProperlyPushesJobOntoIronWithClosures() | |
| 32 | 36 | { | |
| 33 | - $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default', true); | ||
| 37 | + $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), m::mock('Illuminate\Http\Request'), 'default', true); | ||
| 38 | + $crypt = m::mock('Illuminate\Encryption\Encrypter'); | ||
| 39 | + $queue->setEncrypter($crypt); | ||
| 34 | 40 | $name = 'Foo'; | |
| 35 | 41 | $closure = new Illuminate\Support\SerializableClosure($innerClosure = function() use ($name) { return $name; }); | |
| 42 | + $crypt->shouldReceive('encrypt')->once()->with(serialize($closure))->andReturn('serial_closure'); | ||
| 36 | 43 | $crypt->shouldReceive('encrypt')->once()->with(json_encode(array( | |
| 37 | - 'job' => 'IlluminateQueueClosure', 'data' => array('closure' => serialize($closure)), 'attempts' => 1, 'queue' => 'default' | ||
| 44 | + 'job' => 'IlluminateQueueClosure', 'data' => array('closure' => 'serial_closure'), 'attempts' => 1, 'queue' => 'default' | ||
| 38 | 45 | )))->andReturn('encrypted'); | |
| 39 | 46 | $iron->shouldReceive('postMessage')->once()->with('default', 'encrypted', array())->andReturn((object) array('id' => 1)); | |
| 40 | 47 | $queue->push($innerClosure); | |
@@ -43,7 +50,9 @@ public function testPushProperlyPushesJobOntoIronWithClosures() | |||
| 43 | 50 | ||
| 44 | 51 | public function testDelayedPushProperlyPushesJobOntoIron() | |
| 45 | 52 | { | |
| 46 | - $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default', true); | ||
| 53 | + $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), m::mock('Illuminate\Http\Request'), 'default', true); | ||
| 54 | + $crypt = m::mock('Illuminate\Encryption\Encrypter'); | ||
| 55 | + $queue->setEncrypter($crypt); | ||
| 47 | 56 | $crypt->shouldReceive('encrypt')->once()->with(json_encode(array( | |
| 48 | 57 | 'job' => 'foo', 'data' => array(1, 2, 3), 'attempts' => 1, 'queue' => 'default', | |
| 49 | 58 | )))->andReturn('encrypted'); | |
@@ -55,7 +64,9 @@ public function testDelayedPushProperlyPushesJobOntoIron() | |||
| 55 | 64 | public function testDelayedPushProperlyPushesJobOntoIronWithTimestamp() | |
| 56 | 65 | { | |
| 57 | 66 | $now = Carbon\Carbon::now(); | |
| 58 | - $queue = $this->getMock('Illuminate\Queue\IronQueue', array('getTime'), array($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default', true)); | ||
| 67 | + $queue = $this->getMock('Illuminate\Queue\IronQueue', array('getTime'), array($iron = m::mock('IronMQ'), m::mock('Illuminate\Http\Request'), 'default', true)); | ||
| 68 | + $crypt = m::mock('Illuminate\Encryption\Encrypter'); | ||
| 69 | + $queue->setEncrypter($crypt); | ||
| 59 | 70 | $queue->expects($this->once())->method('getTime')->will($this->returnValue($now->getTimestamp())); | |
| 60 | 71 | $crypt->shouldReceive('encrypt')->once()->with(json_encode(array('job' => 'foo', 'data' => array(1, 2, 3), 'attempts' => 1, 'queue' => 'default')))->andReturn('encrypted'); | |
| 61 | 72 | $iron->shouldReceive('postMessage')->once()->with('default', 'encrypted', array('delay' => 5))->andReturn((object) array('id' => 1)); | |
@@ -65,7 +76,9 @@ public function testDelayedPushProperlyPushesJobOntoIronWithTimestamp() | |||
| 65 | 76 | ||
| 66 | 77 | public function testPopProperlyPopsJobOffOfIron() | |
| 67 | 78 | { | |
| 68 | - $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default', true); | ||
| 79 | + $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), m::mock('Illuminate\Http\Request'), 'default', true); | ||
| 80 | + $crypt = m::mock('Illuminate\Encryption\Encrypter'); | ||
| 81 | + $queue->setEncrypter($crypt); | ||
| 69 | 82 | $queue->setContainer(m::mock('Illuminate\Container\Container')); | |
| 70 | 83 | $iron->shouldReceive('getMessage')->once()->with('default')->andReturn($job = m::mock('IronMQ_Message')); | |
| 71 | 84 | $job->body = 'foo'; | |
@@ -78,7 +91,9 @@ public function testPopProperlyPopsJobOffOfIron() | |||
| 78 | 91 | ||
| 79 | 92 | public function testPopProperlyPopsJobOffOfIronWithoutEncryption() | |
| 80 | 93 | { | |
| 81 | - $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default'); | ||
| 94 | + $queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), m::mock('Illuminate\Http\Request'), 'default'); | ||
| 95 | + $crypt = m::mock('Illuminate\Encryption\Encrypter'); | ||
| 96 | + $queue->setEncrypter($crypt); | ||
| 82 | 97 | $queue->setContainer(m::mock('Illuminate\Container\Container')); | |
| 83 | 98 | $iron->shouldReceive('getMessage')->once()->with('default')->andReturn($job = m::mock('IronMQ_Message')); | |
| 84 | 99 | $job->body = 'foo'; | |
@@ -91,7 +106,9 @@ public function testPopProperlyPopsJobOffOfIronWithoutEncryption() | |||
| 91 | 106 | ||
| 92 | 107 | public function testPushedJobsCanBeMarshaled() | |
| 93 | 108 | { | |
| 94 | - $queue = $this->getMock('Illuminate\Queue\IronQueue', array('createPushedIronJob'), array($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), $request = m::mock('Illuminate\Http\Request'), 'default', true)); | ||
| 109 | + $queue = $this->getMock('Illuminate\Queue\IronQueue', array('createPushedIronJob'), array($iron = m::mock('IronMQ'), $request = m::mock('Illuminate\Http\Request'), 'default', true)); | ||
| 110 | + $crypt = m::mock('Illuminate\Encryption\Encrypter'); | ||
| 111 | + $queue->setEncrypter($crypt); | ||
| 95 | 112 | $request->shouldReceive('header')->once()->with('iron-message-id')->andReturn('message-id'); | |
| 96 | 113 | $request->shouldReceive('getContent')->once()->andReturn($content = json_encode(array('foo' => 'bar'))); | |
| 97 | 114 | $crypt->shouldReceive('decrypt')->once()->with($content)->andReturn($content); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,7 @@ public function testDefaultConnectionCanBeResolved() | |||
| 18 | 18 | 'queue.default' => 'sync', | |
| 19 | 19 | 'queue.connections.sync' => array('driver' => 'sync'), | |
| 20 | 20 | ), | |
| 21 | + 'encrypter' => $encrypter = m::mock('Illuminate\Encryption\Encrypter'), | ||
| 21 | 22 | ); | |
| 22 | 23 | ||
| 23 | 24 | $manager = new QueueManager($app); | |
@@ -26,6 +27,7 @@ public function testDefaultConnectionCanBeResolved() | |||
| 26 | 27 | $connector->shouldReceive('connect')->once()->with(array('driver' => 'sync'))->andReturn($queue); | |
| 27 | 28 | $manager->addConnector('sync', function() use ($connector) { return $connector; }); | |
| 28 | 29 | $queue->shouldReceive('setContainer')->once()->with($app); | |
| 30 | + $queue->shouldReceive('setEncrypter')->once()->with($encrypter); | ||
| 29 | 31 | ||
| 30 | 32 | $this->assertTrue($queue === $manager->connection('sync')); | |
| 31 | 33 | } | |
@@ -38,6 +40,7 @@ public function testOtherConnectionCanBeResolved() | |||
| 38 | 40 | 'queue.default' => 'sync', | |
| 39 | 41 | 'queue.connections.foo' => array('driver' => 'bar'), | |
| 40 | 42 | ), | |
| 43 | + 'encrypter' => $encrypter = m::mock('Illuminate\Encryption\Encrypter'), | ||
| 41 | 44 | ); | |
| 42 | 45 | ||
| 43 | 46 | $manager = new QueueManager($app); | |
@@ -46,6 +49,7 @@ public function testOtherConnectionCanBeResolved() | |||
| 46 | 49 | $connector->shouldReceive('connect')->once()->with(array('driver' => 'bar'))->andReturn($queue); | |
| 47 | 50 | $manager->addConnector('bar', function() use ($connector) { return $connector; }); | |
| 48 | 51 | $queue->shouldReceive('setContainer')->once()->with($app); | |
| 52 | + $queue->shouldReceive('setEncrypter')->once()->with($encrypter); | ||
| 49 | 53 | ||
| 50 | 54 | $this->assertTrue($queue === $manager->connection('foo')); | |
| 51 | 55 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments