mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 19:34:04 +00:00
Move encrypted cookie assertion to "cookie identification works"
This commit is contained in:
parent
dec9350643
commit
62ae70399c
1 changed files with 5 additions and 9 deletions
|
|
@ -89,6 +89,11 @@ test('cookie identification works', function (string|null $tenantModelColumn) {
|
|||
// Default cookie name
|
||||
$this->withoutExceptionHandling()->withUnencryptedCookie('tenant', $payload)->get('test')->assertSee($tenant->id);
|
||||
|
||||
// Encrypted cookie (encrypt cookie like MakesHttpRequests does)
|
||||
$encryptedPayload = encrypt(CookieValuePrefix::create('tenant', app('encrypter')->getKey()) . $payload, false);
|
||||
|
||||
$this->withoutExceptionHandling()->withUnencryptedCookie('tenant', $encryptedPayload)->get('test')->assertSee($tenant->id);
|
||||
|
||||
// Custom cookie name
|
||||
config(['tenancy.identification.resolvers.' . RequestDataTenantResolver::class . '.cookie' => 'custom_tenant_id']);
|
||||
$this->withoutExceptionHandling()->withUnencryptedCookie('custom_tenant_id', $payload)->get('test')->assertSee($tenant->id);
|
||||
|
|
@ -98,15 +103,6 @@ test('cookie identification works', function (string|null $tenantModelColumn) {
|
|||
expect(fn () => $this->withoutExceptionHandling()->withUnencryptedCookie('tenant', $payload)->get('test'))->toThrow(TenantCouldNotBeIdentifiedByRequestDataException::class);
|
||||
})->with([null, 'slug']);
|
||||
|
||||
test('cookie identification works with encrypted cookies', function () {
|
||||
$tenant = Tenant::create(['id' => 'acme']);
|
||||
|
||||
// Mimic MakesHttpRequests cookie encryption
|
||||
$encryptedCookie = encrypt(CookieValuePrefix::create('tenant', app('encrypter')->getKey()) . 'acme', false);
|
||||
|
||||
$this->withoutExceptionHandling()->withUnencryptedCookie('tenant', $encryptedCookie)->get('test')->assertSee($tenant->id);
|
||||
});
|
||||
|
||||
test('an exception is thrown when no tenant data is provided in the request', function () {
|
||||
pest()->expectException(TenantCouldNotBeIdentifiedByRequestDataException::class);
|
||||
$this->withoutExceptionHandling()->get('test');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue