actingAs($customer, 'client') ->withHeaders(['x-access-token' => $this->buildClientAccessToken()]); } public function test_client_cannot_fetch_another_customers_service_by_uuid(): void { $owner = Customer::factory()->create(); $attacker = Customer::factory()->create(); $product = Product::factory()->create(['product_type' => 'hosting', 'is_active' => true]); $order = Order::create([ 'order_num' => 'ORD-' . uniqid(), 'customer_id' => $owner->id, 'sub_total' => 100000, 'total' => 100000, 'status' => OrderStatus::ACTIVE->value, ]); $orderItem = OrderItem::create([ 'order_id' => $order->id, 'product_id' => $product->id, 'billing_cycle' => 'monthly', 'months' => 1, 'quantity' => 1, 'price' => 100000, ]); $service = Service::create([ 'customer_id' => $owner->id, 'product_id' => $product->id, 'order_item_id' => $orderItem->id, 'status' => 'active', 'server_name' => 'owner-server', ]); $response = $this->actingAsCustomer($attacker)->getJson("/v1/client/service/{$service->uuid}"); $response->assertStatus(404); } public function test_client_can_fetch_own_service_by_uuid(): void { $owner = Customer::factory()->create(); $product = Product::factory()->create(['product_type' => 'hosting', 'is_active' => true]); $order = Order::create([ 'order_num' => 'ORD-' . uniqid(), 'customer_id' => $owner->id, 'sub_total' => 100000, 'total' => 100000, 'status' => OrderStatus::ACTIVE->value, ]); $orderItem = OrderItem::create([ 'order_id' => $order->id, 'product_id' => $product->id, 'billing_cycle' => 'monthly', 'months' => 1, 'quantity' => 1, 'price' => 100000, ]); $service = Service::create([ 'customer_id' => $owner->id, 'product_id' => $product->id, 'order_item_id' => $orderItem->id, 'status' => 'active', 'server_name' => 'owner-server', ]); $response = $this->actingAsCustomer($owner)->getJson("/v1/client/service/{$service->uuid}"); $this->assertNotSame(404, $response->status()); } }