Files
clinicpro/tests/Doctor/DoctorAddressOwnershipTest.php
T
hamedandClaude Opus 4.8 fe6383314e fix(security): enforce ownership on 4 IDOR read/bind endpoints (M2-M5)
- M2 GET /insurance/{id}: was unguarded; now owner-or-admin (403 otherwise) —
  stops reading another doctor's negotiated price by id enumeration.
- M3 GET /clinic-pro/doctor-address/{id}: add the same owner/admin check the
  sibling PATCH/DELETE already had.
- M4 POST/PATCH /service-item: staff_uuid must belong to the caller's tenant
  (entity_type/entity_id) → 422; stops binding another tenant's staff.
- M5 appointment-settings list endpoints (date-override/holidays/
  available-locations): add the per-doctor ownership check the sibling
  single-record endpoints already enforce.

Regressions (6 negative cases fail without the fixes):
DoctorInsuranceOwnershipTest, DoctorAddressOwnershipTest,
ServiceItemStaffOwnershipTest, AppointmentSettingsListOwnershipTest.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 20:17:52 +03:30

46 lines
1.3 KiB
PHP

<?php
namespace App\Tests\Doctor;
use App\Doctor\Entity\Doctor;
use App\Doctor\Entity\DoctorAddress;
use App\Tests\ApiTestCase;
/**
* GET /clinic-pro/doctor-address/{id} must enforce ownership — a doctor must not
* read another doctor's address by id enumeration.
*/
class DoctorAddressOwnershipTest extends ApiTestCase
{
private function makeAddress(): DoctorAddress
{
$doctor = new Doctor($this->createUser(['ROLE_DOCTOR']), 'دکتر مالک');
$this->em->persist($doctor);
$address = DoctorAddress::forDoctor($doctor)->setName('مطب');
$this->em->persist($address);
$this->em->flush();
return $address;
}
public function testOtherDoctorCannotRead(): void
{
$address = $this->makeAddress();
$stranger = $this->createUser(['ROLE_DOCTOR']);
$this->authJson('GET', '/api/v1/clinic-pro/doctor-address/' . $address->getId(), $stranger);
$this->assertSame(403, $this->responseCode());
}
public function testOwnerCanRead(): void
{
$address = $this->makeAddress();
$owner = $address->getDoctor()->getUser();
$this->authJson('GET', '/api/v1/clinic-pro/doctor-address/' . $address->getId(), $owner);
$this->assertSame(200, $this->responseCode());
}
}