-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add support for encrypted jobs (#287)
* Add support for encrypted jobs * Add test for EncryptedJob * Include interface
- Loading branch information
1 parent
5c49cd5
commit 1262cda
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
tests/Identification/Queue/Integration/EncryptedJobTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the tenancy/tenancy package. | ||
* | ||
* Copyright Tenancy for Laravel | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @see https://tenancy.dev | ||
* @see https://github.com/tenancy | ||
*/ | ||
|
||
namespace Tenancy\Tests\Identification\Queue\Integration; | ||
|
||
use Illuminate\Queue\Events\JobProcessed; | ||
use Illuminate\Queue\Events\JobProcessing; | ||
use Illuminate\Support\Facades\Event; | ||
use Tenancy\Identification\Drivers\Queue\Providers\IdentificationProvider; | ||
use Tenancy\Testing\TestCase; | ||
use Tenancy\Tests\Mocks\Jobs\EncryptedJob; | ||
|
||
class EncryptedJobTest extends TestCase | ||
{ | ||
protected array $additionalProviders = [IdentificationProvider::class]; | ||
|
||
/** @test */ | ||
public function jobs_do_not_contain_the_tenant_when_none_identified() | ||
{ | ||
Event::listen([JobProcessing::class, JobProcessed::class], function ($event) { | ||
$payload = json_decode($event->job->getRawBody(), true); | ||
|
||
$this->assertArrayNotHasKey('tenant_identifier', $payload); | ||
$this->assertArrayNotHasKey('tenant_key', $payload); | ||
}); | ||
|
||
dispatch(new EncryptedJob()); | ||
} | ||
|
||
/** @test */ | ||
public function jobs_do_contain_the_tenant_when_one_is_identified() | ||
{ | ||
$tenant = $this->mockTenant(); | ||
|
||
$this->environment->setTenant($tenant); | ||
|
||
Event::listen([JobProcessing::class, JobProcessed::class], function ($event) use ($tenant) { | ||
$payload = json_decode($event->job->getRawBody(), true); | ||
|
||
$this->assertEquals($tenant->getTenantIdentifier(), $payload['tenant_identifier']); | ||
$this->assertEquals($tenant->getTenantKey(), $payload['tenant_key']); | ||
}); | ||
|
||
dispatch(new EncryptedJob()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the tenancy/tenancy package. | ||
* | ||
* Copyright Tenancy for Laravel | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @see https://tenancy.dev | ||
* @see https://github.com/tenancy | ||
*/ | ||
|
||
namespace Tenancy\Tests\Mocks\Jobs; | ||
|
||
use Illuminate\Contracts\Queue\ShouldBeEncrypted; | ||
|
||
class EncryptedJob extends SimpleJob implements ShouldBeEncrypted | ||
{ | ||
} |