Skip to content

Commit 62ae703

Browse files
committed
Move encrypted cookie assertion to "cookie identification works"
1 parent dec9350 commit 62ae703

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

tests/RequestDataIdentificationTest.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@
8989
// Default cookie name
9090
$this->withoutExceptionHandling()->withUnencryptedCookie('tenant', $payload)->get('test')->assertSee($tenant->id);
9191

92+
// Encrypted cookie (encrypt cookie like MakesHttpRequests does)
93+
$encryptedPayload = encrypt(CookieValuePrefix::create('tenant', app('encrypter')->getKey()) . $payload, false);
94+
95+
$this->withoutExceptionHandling()->withUnencryptedCookie('tenant', $encryptedPayload)->get('test')->assertSee($tenant->id);
96+
9297
// Custom cookie name
9398
config(['tenancy.identification.resolvers.' . RequestDataTenantResolver::class . '.cookie' => 'custom_tenant_id']);
9499
$this->withoutExceptionHandling()->withUnencryptedCookie('custom_tenant_id', $payload)->get('test')->assertSee($tenant->id);
@@ -98,15 +103,6 @@
98103
expect(fn () => $this->withoutExceptionHandling()->withUnencryptedCookie('tenant', $payload)->get('test'))->toThrow(TenantCouldNotBeIdentifiedByRequestDataException::class);
99104
})->with([null, 'slug']);
100105

101-
test('cookie identification works with encrypted cookies', function () {
102-
$tenant = Tenant::create(['id' => 'acme']);
103-
104-
// Mimic MakesHttpRequests cookie encryption
105-
$encryptedCookie = encrypt(CookieValuePrefix::create('tenant', app('encrypter')->getKey()) . 'acme', false);
106-
107-
$this->withoutExceptionHandling()->withUnencryptedCookie('tenant', $encryptedCookie)->get('test')->assertSee($tenant->id);
108-
});
109-
110106
test('an exception is thrown when no tenant data is provided in the request', function () {
111107
pest()->expectException(TenantCouldNotBeIdentifiedByRequestDataException::class);
112108
$this->withoutExceptionHandling()->get('test');

0 commit comments

Comments
 (0)