From 30077e68ade8a452b355f87fb44d82289da659f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 26 Aug 2026 11:17:17 +0200 Subject: [PATCH] test(bo): add negative authorization tests for unauthenticated and unauthorized requests [AUD-TST-003] --- .../Bo/DiscountsControllerTest.php | 19 ++++++++++++++++++- .../Controllers/Bo/ProductsControllerTest.php | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/Feature/App/Http/Controllers/Bo/DiscountsControllerTest.php b/tests/Feature/App/Http/Controllers/Bo/DiscountsControllerTest.php index 6d0c7751..c70666f1 100644 --- a/tests/Feature/App/Http/Controllers/Bo/DiscountsControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Bo/DiscountsControllerTest.php @@ -92,8 +92,25 @@ describe('DiscountsController', function () { $discount->save(); $response = $this->delete("/bo/discounts/{$discount->id}"); - + // THEN expect(Discount::find($discount->id))->toBeNull(); $response->assertRedirect('/bo/discounts'); }); + + describe('authorization rejections', function () { + it('redirects unauthenticated guest to login', function () { + auth('backend')->logout(); + + $response = $this->get('/bo/discounts'); + $response->assertRedirect('/bo/login'); + }); + + it('denies access to unauthorized user with customer role', function () { + $user = User::factory()->make(['role' => UserRole::Customer]); + $this->actingAs($user, 'backend'); + + $response = $this->get('/bo/discounts'); + expect($response->status())->toBe(403); + }); + }); }); diff --git a/tests/Feature/App/Http/Controllers/Bo/ProductsControllerTest.php b/tests/Feature/App/Http/Controllers/Bo/ProductsControllerTest.php index 4ae1761f..5ca31bbd 100644 --- a/tests/Feature/App/Http/Controllers/Bo/ProductsControllerTest.php +++ b/tests/Feature/App/Http/Controllers/Bo/ProductsControllerTest.php @@ -232,4 +232,21 @@ describe('ProductsController', function () { // THEN expect(Product::find($product->id))->toBeNull(); }); + + describe('authorization rejections', function () { + it('redirects unauthenticated guest to login', function () { + auth('backend')->logout(); + + $response = $this->get('/bo/products'); + $response->assertRedirect('/bo/login'); + }); + + it('denies access to unauthorized user with customer role', function () { + $user = User::factory()->make(['role' => UserRole::Customer]); + $this->actingAs($user, 'backend'); + + $response = $this->get('/bo/products'); + expect($response->status())->toBe(403); + }); + }); });