File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
tests/Feature/TenantAwareJobs Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 22
33namespace Spatie \Multitenancy \Actions ;
44
5+ use Illuminate \Contracts \Encryption \Encrypter ;
56use Illuminate \Queue \Events \JobProcessing ;
67use Illuminate \Queue \Events \JobRetryRequested ;
78use Illuminate \Support \Arr ;
@@ -49,8 +50,14 @@ protected function isTenantAware(JobProcessing|JobRetryRequested $event): bool
4950 {
5051 $ payload = $ this ->getEventPayload ($ event );
5152
53+ $ serializedCommand = $ payload ['data ' ]['command ' ];
54+
55+ if (! str_starts_with ($ serializedCommand , 'O: ' )) {
56+ $ serializedCommand = app (Encrypter::class)->decrypt ($ serializedCommand );
57+ }
58+
5259 try {
53- $ command = unserialize ($ payload [ ' data ' ][ ' command ' ] );
60+ $ command = unserialize ($ serializedCommand );
5461 } catch (Throwable ) {
5562 /**
5663 * We might need the tenant to unserialize jobs as models could
@@ -62,7 +69,7 @@ protected function isTenantAware(JobProcessing|JobRetryRequested $event): bool
6269 $ tenant ?->makeCurrent();
6370 }
6471
65- $ command = unserialize ($ payload [ ' data ' ][ ' command ' ] );
72+ $ command = unserialize ($ serializedCommand );
6673 }
6774
6875 $ job = $ this ->getJobFromQueueable ($ command );
Original file line number Diff line number Diff line change 44use Illuminate \Queue \Events \JobFailed ;
55use Illuminate \Support \Facades \Event ;
66use Spatie \Multitenancy \Models \Tenant ;
7+ use Spatie \Multitenancy \Tests \Feature \TenantAwareJobs \TestClasses \EncryptedTenantAware ;
78use Spatie \Multitenancy \Tests \Feature \TenantAwareJobs \TestClasses \NotTenantAwareTestJob ;
89use Spatie \Multitenancy \Tests \Feature \TenantAwareJobs \TestClasses \TenantAwareTestJob ;
910use Spatie \Multitenancy \Tests \Feature \TenantAwareJobs \TestClasses \TestJob ;
102103 $ currentTenantIdInJob = $ this ->valuestore ->get ('tenantId ' );
103104 expect ($ currentTenantIdInJob )->toBeNull ();
104105});
106+
107+ it ('will decrypt encrypted jobs ' , function () {
108+ config ()->set ('multitenancy.queues_are_tenant_aware_by_default ' , true );
109+
110+ $ this ->tenant ->makeCurrent ();
111+
112+ $ job = new EncryptedTenantAware ($ this ->valuestore );
113+ app (Dispatcher::class)->dispatch ($ job );
114+
115+ $ this ->artisan ('queue:work --once ' )->assertExitCode (0 );
116+
117+ Event::assertNotDispatched (JobFailed::class);
118+ });
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Spatie \Multitenancy \Tests \Feature \TenantAwareJobs \TestClasses ;
4+
5+ use Illuminate \Contracts \Queue \ShouldBeEncrypted ;
6+ use Spatie \Multitenancy \Jobs \TenantAware ;
7+
8+ class EncryptedTenantAware extends TestJob implements TenantAware, ShouldBeEncrypted
9+ {
10+ }
You can’t perform that action at this time.
0 commit comments