feat: harden admin auth and ticket workflows
- add rotating admin refresh tokens and password gates\n- expand ticket galleries, exports, and client resources\n- improve IP allocation auditing and dashboard data\n- enforce encrypted client access tokens on public routes
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Models\IpPoolLog;
|
||||
use App\Models\Mail as MailLog;
|
||||
use App\Models\ModuleIpAddress;
|
||||
use App\Models\ModuleNetwork;
|
||||
use App\Models\Template;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
@@ -74,6 +75,8 @@ class IpAllocationTest extends TestCase
|
||||
public function test_allocate_assigns_ips_logs_and_emails_customer(): void
|
||||
{
|
||||
Mail::fake();
|
||||
$template = Template::where('scenario', IpAllocationMail::ALLOCATED)->sole();
|
||||
$template->update(['metadata' => [...$template->metadata, 'mail' => ['cc' => ['sale@tgs.com.vn'], 'bcc' => ['audit@tgs.com.vn']]]]);
|
||||
$first = $this->pool('10.0.0.5');
|
||||
$second = $this->pool('10.0.0.6');
|
||||
|
||||
@@ -92,6 +95,7 @@ class IpAllocationTest extends TestCase
|
||||
$log = IpPoolLog::where('ip_pool_id', $first->id)->sole();
|
||||
$this->assertSame([IpPoolLog::ALLOCATED, 'free', 'assigned', $this->admin->id], [$log->action, $log->status_from, $log->status_to, $log->user_id]);
|
||||
$this->assertSame(['2026-10-15', 'Colo <b>1U</b>'], [$log->effective_date->toDateString(), $log->service_name]);
|
||||
$this->assertSame(['kythuat@tgs.com.vn, sale@tgs.com.vn', 'audit@tgs.com.vn'], [$log->email_cc, $log->email_bcc]);
|
||||
|
||||
Mail::assertQueued(IpAllocationMail::class, fn (IpAllocationMail $mail) => $mail->type === IpAllocationMail::ALLOCATED
|
||||
&& count($mail->ips) === 2
|
||||
@@ -248,4 +252,46 @@ class IpAllocationTest extends TestCase
|
||||
->assertJsonPath('data.0.action', IpPoolLog::ALLOCATED)
|
||||
->assertJsonPath('data.0.customer_name', 'Công ty A');
|
||||
}
|
||||
|
||||
public function test_audit_log_lists_every_ip_with_filters(): void
|
||||
{
|
||||
IpPoolLog::record($this->pool('10.0.0.8'), IpPoolLog::ALLOCATED, 'free', ['customer_name' => 'Công ty A']);
|
||||
IpPoolLog::record($this->pool('10.0.0.9'), IpPoolLog::REVOKED, 'assigned', ['customer_name' => 'Công ty B']);
|
||||
|
||||
$this->actingAs($this->admin, 'admin')
|
||||
->getJson(self::BASE . '/logs')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.total', 2)
|
||||
->assertJsonPath('data.items.0.ip_address', '10.0.0.9');
|
||||
|
||||
$this->actingAs($this->admin, 'admin')
|
||||
->getJson(self::BASE . '/logs?' . http_build_query(['action' => [IpPoolLog::ALLOCATED], 'filter' => 'Công ty']))
|
||||
->assertOk()
|
||||
->assertJsonPath('data.total', 1)
|
||||
->assertJsonPath('data.items.0.ip_address', '10.0.0.8');
|
||||
}
|
||||
|
||||
public function test_dashboard_aggregates_usage_and_money_per_block_and_customer(): void
|
||||
{
|
||||
$this->pool('10.0.0.5', ['ip_block' => 'A', 'status' => 'assigned', 'customer_id' => $this->customer->id, 'customer_name' => 'Công ty A', 'monthly_cost' => 100, 'selling_price' => 300]);
|
||||
$this->pool('10.0.0.6', ['ip_block' => 'A', 'ip_role' => 'ADDON', 'status' => 'assigned', 'customer_name' => 'Khách import', 'selling_price' => 50]);
|
||||
$this->pool('10.0.0.7', ['ip_block' => 'A', 'monthly_cost' => 40, 'selling_price' => 999]);
|
||||
$this->pool('10.0.0.8', ['ip_block' => 'B', 'status' => 'reserved']);
|
||||
|
||||
$response = $this->actingAs($this->admin, 'admin')
|
||||
->getJson(self::BASE . '/dashboard')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.summary.total', 4)
|
||||
->assertJsonPath('data.summary.primary', 3)
|
||||
->assertJsonPath('data.summary.addon', 1)
|
||||
->assertJsonPath('data.summary.assigned', 2)
|
||||
->assertJsonPath('data.summary.reserved', 1)
|
||||
->assertJsonPath('data.blocks.0.ip_block', 'A')
|
||||
->assertJsonPath('data.blocks.0.assigned', 2)
|
||||
->assertJsonPath('data.top_customers.0.customer_uuid', $this->customer->uuid);
|
||||
|
||||
$this->assertEquals([140, 350, 210], [$response->json('data.summary.cost'), $response->json('data.summary.revenue'), $response->json('data.summary.profit')]);
|
||||
$this->assertEqualsWithDelta(2 / 3, $response->json('data.blocks.0.usage_rate'), 0.0001);
|
||||
$this->assertSame(['Công ty A', 'Khách import'], array_column($response->json('data.top_customers'), 'customer_name'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user