CaiWuXiTong/tests/Feature/Installation/BootstrapInstallationTest.php
chenxi fcfc401eff fix: 财务系统仅允许钉钉账号登录 (#1068)
登录页仅保留钉钉入口;停用密码、找回密码、重置密码和邀请注册登录;旧密码会话立即失效。
2026-11-11 11:02:49 +08:00

90 lines
3.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Tests\Feature\Installation;
use App\Models\Auth\DingTalkIdentity;
use App\Utilities\Installer;
use Database\Seeds\Permissions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Facades\Notification;
use Tests\CreatesApplication;
class BootstrapInstallationTest extends BaseTestCase
{
use CreatesApplication;
use RefreshDatabase;
public function test_fresh_bootstrap_administrator_can_open_wizard_dashboard_and_database_settings(): void
{
$this->artisan('db:seed', [
'--class' => Permissions::class,
'--force' => true,
])->assertSuccessful();
config([
'mail.from.address' => 'test@example.com',
'mail.from.name' => 'CaiWuXiTong Test',
]);
Notification::fake();
$company = Installer::createCompany(
'本地引导环境',
'local-bootstrap@caiwu.test',
'zh-CN'
);
Installer::createUser(
'local-bootstrap@caiwu.test',
'temporary-test-secret',
'zh-CN',
$company->id
);
$user = user_model_class()::where('email', 'local-bootstrap@caiwu.test')->firstOrFail();
$identity = DingTalkIdentity::query()->create([
'user_id' => $user->id,
'union_id' => 'install-bootstrap-dingtalk-identity',
'dingtalk_user_id' => 'install-bootstrap-user',
]);
$role = $user->roles()->where('name', 'super_admin')->firstOrFail();
$this->assertTrue($role->hasPermission('read-admin-panel'));
$this->assertTrue($role->hasPermission('create-common-companies'));
$this->assertTrue($role->hasPermission('read-common-companies'));
$this->assertTrue($role->hasPermission('read-common-dashboards'));
$this->assertFalse($role->hasPermission('read-client-portal'));
$this->assertTrue($user->companies()->whereKey($company->id)->exists());
$this->assertTrue($user->can('read-admin-panel'));
$this->assertTrue($user->can('read-common-companies'));
$this->assertTrue($user->hasPermission('read-admin-panel'));
$this->assertTrue($user->hasPermission('read-common-companies'));
$company->makeCurrent();
app('url')->defaults(['company_id' => $company->id]);
config([
'debugbar.enabled' => false,
'system_database.mode' => 'bootstrap',
'upstreams.stored_configuration.enabled' => false,
]);
foreach (array_keys(config('firewall.middleware', [])) as $middleware) {
config(["firewall.middleware.{$middleware}.enabled" => false]);
}
foreach ([
route('wizard.edit'),
route('dashboard'),
route('system-settings.databases.index'),
] as $url) {
$response = $this->actingAs($user)->withSession([
'dingtalk_identity_id' => $identity->id,
'dingtalk_roster_checked_at' => now()->timestamp,
])->get($url);
$this->assertNotSame(
403,
$response->getStatusCode(),
$url . ' 不应返回 403:' . mb_substr(strip_tags($response->getContent()), 0, 500)
);
}
}
}