67 lines
2.3 KiB
PHP
67 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Utilities;
|
|
|
|
use App\Utilities\TeamSystemDatabaseProfile;
|
|
use RuntimeException;
|
|
use Tests\TestCase;
|
|
|
|
class TeamSystemDatabaseProfileTest extends TestCase
|
|
{
|
|
public function test_password_unlocks_the_fixed_team_profile(): void
|
|
{
|
|
$encoded = TeamSystemDatabaseProfile::seal([
|
|
'host' => 'shared-db.test',
|
|
'port' => 3306,
|
|
'database' => 'shared_system',
|
|
'username' => 'shared_writer',
|
|
], 'correct-password');
|
|
|
|
$settings = (new TeamSystemDatabaseProfile($encoded))->settings('correct-password');
|
|
|
|
$this->assertSame('shared-db.test', $settings['host']);
|
|
$this->assertSame(3306, $settings['port']);
|
|
$this->assertSame('shared_system', $settings['database']);
|
|
$this->assertSame('shared_writer', $settings['username']);
|
|
$this->assertSame('correct-password', $settings['password']);
|
|
$this->assertTrue($settings['tls_required']);
|
|
$this->assertFalse($settings['tls_verify_server_cert']);
|
|
$this->assertSame('', $settings['tls_ca']);
|
|
}
|
|
|
|
public function test_wrong_password_does_not_reveal_connection_details(): void
|
|
{
|
|
$encoded = TeamSystemDatabaseProfile::seal([
|
|
'host' => 'shared-db.test',
|
|
'port' => 3306,
|
|
'database' => 'shared_system',
|
|
'username' => 'shared_writer',
|
|
], 'correct-password');
|
|
|
|
$this->expectException(RuntimeException::class);
|
|
$this->expectExceptionMessage('系统数据库密码不正确,请重新输入。');
|
|
|
|
(new TeamSystemDatabaseProfile($encoded))->settings('wrong-password');
|
|
}
|
|
|
|
public function test_missing_cached_config_uses_embedded_profile(): void
|
|
{
|
|
config(['system_database.team_profile' => null]);
|
|
|
|
$this->expectException(RuntimeException::class);
|
|
$this->expectExceptionMessage('系统数据库密码不正确,请重新输入。');
|
|
|
|
(new TeamSystemDatabaseProfile())->settings('wrong-password');
|
|
}
|
|
|
|
public function test_empty_cached_config_uses_embedded_profile(): void
|
|
{
|
|
config(['system_database.team_profile' => '']);
|
|
|
|
$this->expectException(RuntimeException::class);
|
|
$this->expectExceptionMessage('系统数据库密码不正确,请重新输入。');
|
|
|
|
(new TeamSystemDatabaseProfile())->settings('wrong-password');
|
|
}
|
|
}
|