feat: menric
This commit is contained in:
@@ -85,6 +85,38 @@ class AdminAgentPortalTest extends TestCase
|
||||
$this->assertAuthenticated('agent');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function agent_google2fa_required_when_enabled(): void
|
||||
{
|
||||
$google2fa = app(\App\Services\AdminGoogle2fa::class);
|
||||
$secret = $google2fa->generateSecret();
|
||||
$agent = User::query()->create([
|
||||
'username' => 'gaagent',
|
||||
'password' => 'secret12',
|
||||
'status' => 1,
|
||||
]);
|
||||
$agent->forceFill([
|
||||
'google_auth_open' => 1,
|
||||
'google_secret' => $secret,
|
||||
])->save();
|
||||
|
||||
$this->post('/user/login', [
|
||||
'username' => 'gaagent',
|
||||
'password' => 'secret12',
|
||||
])->assertOk()->assertJson(['code' => 1, 'msg' => '请输入谷歌验证码!']);
|
||||
|
||||
$this->assertGuest('agent');
|
||||
|
||||
$code = (new \PragmaRX\Google2FA\Google2FA)->getCurrentOtp($secret);
|
||||
$this->post('/user/login', [
|
||||
'username' => 'gaagent',
|
||||
'password' => 'secret12',
|
||||
'GACode' => $code,
|
||||
])->assertOk()->assertJsonPath('code', 0);
|
||||
|
||||
$this->assertAuthenticated('agent');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function admin_can_create_channel_with_random_id_and_links_fallback_domains(): void
|
||||
{
|
||||
@@ -384,6 +416,89 @@ class AdminAgentPortalTest extends TestCase
|
||||
->assertJsonFragment(['username' => 'albumagent', 'album_storage_default' => 1]);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function admin_can_create_and_update_agent_mnemonic_reveal(): void
|
||||
{
|
||||
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->post(route('admin.agents.store'), [
|
||||
'username' => 'revealagent',
|
||||
'password' => 'secret12',
|
||||
'status' => 1,
|
||||
'can_reveal_mnemonics' => 1,
|
||||
])
|
||||
->assertOk()
|
||||
->assertJsonPath('code', 0);
|
||||
|
||||
$agent = User::query()->where('username', 'revealagent')->first();
|
||||
$this->assertNotNull($agent);
|
||||
$this->assertTrue($agent->mnemonicRevealEnabled());
|
||||
$this->assertFalse($agent->canRevealMnemonics());
|
||||
|
||||
config(['coruna.mnemonic_reveal.staff_enabled' => true]);
|
||||
$this->assertTrue($agent->fresh()->canRevealMnemonics());
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->put(route('admin.agents.update', $agent), [
|
||||
'can_reveal_mnemonics' => 0,
|
||||
])
|
||||
->assertOk();
|
||||
|
||||
$this->assertFalse($agent->fresh()->mnemonicRevealEnabled());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function agent_page_hides_mnemonic_reveal_when_env_off(): void
|
||||
{
|
||||
config(['coruna.mnemonic_reveal.staff_enabled' => false]);
|
||||
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
|
||||
User::query()->create(['username' => 'hideagent', 'password' => 'secret12', 'status' => 1]);
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->get(route('admin.agents.index'))
|
||||
->assertOk()
|
||||
->assertDontSee('查看助记词', false);
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->getJson(route('admin.agents.data'))
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.username', 'hideagent')
|
||||
->assertJsonMissingPath('data.0.can_reveal_mnemonics');
|
||||
|
||||
config(['coruna.mnemonic_reveal.staff_enabled' => true]);
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->get(route('admin.agents.index'))
|
||||
->assertOk()
|
||||
->assertSee('查看助记词', false);
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->getJson(route('admin.agents.data'))
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.can_reveal_mnemonics', 0);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function agent_list_shows_google_bound_status(): void
|
||||
{
|
||||
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
|
||||
User::query()->create(['username' => 'unbound', 'password' => 'secret12', 'status' => 1]);
|
||||
$bound = User::query()->create(['username' => 'bound', 'password' => 'secret12', 'status' => 1]);
|
||||
$bound->forceFill(['google_secret' => 'JBSWY3DPEHPK3PXP'])->save();
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->get(route('admin.agents.index'))
|
||||
->assertOk()
|
||||
->assertSee('谷歌验证', false);
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->getJson(route('admin.agents.data'))
|
||||
->assertOk()
|
||||
->assertJsonFragment(['username' => 'unbound', 'google_bound' => 0])
|
||||
->assertJsonFragment(['username' => 'bound', 'google_bound' => 1]);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function agent_cannot_create_channel(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user