Some checks failed
lotterLaravel CI / test (push) Has been cancelled
- Updated AGENTS.md to clarify player interface bindings and agent account restrictions. - Improved PlayerAuthLoginController to include captcha verification for player login. - Enhanced AdminPlayerIndexController with permission checks for admin users. - Refactored AdminPlayerStoreController to enforce agent node restrictions for non-super admins. - Introduced new error codes for player authentication failures and updated related services. - Enhanced validation rules for agent profiles to include settlement cycle options. - Improved AdminCaptchaService to support separate scopes for admin and player captcha handling. - Updated various services to ensure proper credit management and settlement processes.
84 lines
2.7 KiB
PHP
84 lines
2.7 KiB
PHP
<?php
|
|
|
|
use App\Models\AdminRole;
|
|
use App\Models\AdminUser;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
$this->artisan('lottery:admin-auth-sync')->assertExitCode(0);
|
|
});
|
|
|
|
function makeFinanceReportAdminToken(): string
|
|
{
|
|
$admin = AdminUser::query()->create([
|
|
'username' => 'finance_report_tester',
|
|
'name' => 'Tester',
|
|
'email' => null,
|
|
'password' => Hash::make('secret-strong'),
|
|
'status' => 0,
|
|
]);
|
|
|
|
$role = AdminRole::query()->where('slug', 'site_finance')->firstOrFail();
|
|
$siteId = AdminUser::defaultAdminSiteId();
|
|
$admin->roles()->sync([
|
|
(int) $role->id => [
|
|
'site_id' => $siteId,
|
|
'granted_at' => now(),
|
|
],
|
|
]);
|
|
|
|
return $admin->createToken('test', ['*'], now()->addDay())->plainTextToken;
|
|
}
|
|
|
|
test('finance role with report legacy can access report jobs after rbac seed', function (): void {
|
|
$finance = AdminRole::query()->where('slug', 'site_finance')->firstOrFail();
|
|
expect($finance->legacyPermissionSlugs())->toContain('prd.report.view');
|
|
|
|
$hasReportAction = DB::table('admin_role_menu_actions as rma')
|
|
->join('admin_menu_actions as ma', 'ma.id', '=', 'rma.menu_action_id')
|
|
->where('rma.role_id', $finance->id)
|
|
->where('ma.permission_code', 'service.report.view')
|
|
->exists();
|
|
|
|
expect($hasReportAction)->toBeTrue();
|
|
|
|
$token = makeFinanceReportAdminToken();
|
|
|
|
$this->withHeader('Authorization', 'Bearer '.$token)
|
|
->getJson('/api/v1/admin/report-jobs')
|
|
->assertOk();
|
|
});
|
|
|
|
test('report read api resources bind service.report.view only', function (): void {
|
|
$codes = [
|
|
'admin.reports.daily-profit',
|
|
'admin.report-jobs.index',
|
|
];
|
|
|
|
foreach ($codes as $code) {
|
|
$bindings = bindingsForResource($code);
|
|
expect($bindings)->toBe(['service.report.view']);
|
|
}
|
|
});
|
|
|
|
test('report export api resources bind service.report.export', function (): void {
|
|
expect(bindingsForResource('admin.report-jobs.download'))->toBe(['service.report.export']);
|
|
expect(bindingsForResource('admin.report-jobs.store'))->toBe(['service.report.export']);
|
|
});
|
|
|
|
/** @return list<string> */
|
|
function bindingsForResource(string $code): array
|
|
{
|
|
return DB::table('admin_api_resources as ar')
|
|
->join('admin_api_resource_bindings as arb', 'arb.api_resource_id', '=', 'ar.id')
|
|
->join('admin_menu_actions as ma', 'ma.id', '=', 'arb.menu_action_id')
|
|
->where('ar.code', $code)
|
|
->orderBy('ma.permission_code')
|
|
->pluck('ma.permission_code')
|
|
->all();
|
|
}
|