129 lines
6.3 KiB
PHP
129 lines
6.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Services\VMangosAccountRegistrar;
|
|
use App\Services\VMangosAccountService;
|
|
use App\Services\VMangosSrpService;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Tests\TestCase;
|
|
|
|
class VMangosAccountIntegrationTest extends TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
config([
|
|
'moonwell.auth_connection' => 'vmangos_auth',
|
|
'moonwell.characters_connection' => 'vmangos_characters',
|
|
'moonwell.registration.realm_id' => -1,
|
|
'moonwell.registration.gmlevel' => 0,
|
|
'database.connections.vmangos_auth' => ['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => ''],
|
|
'database.connections.vmangos_characters' => ['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => ''],
|
|
]);
|
|
DB::purge('vmangos_auth');
|
|
DB::purge('vmangos_characters');
|
|
|
|
Schema::connection('vmangos_auth')->create('account', function (Blueprint $table): void {
|
|
$table->increments('id');
|
|
$table->string('username', 32)->unique();
|
|
$table->text('s');
|
|
$table->text('v');
|
|
$table->unsignedTinyInteger('expansion')->default(0);
|
|
$table->string('email')->nullable();
|
|
$table->dateTime('joindate');
|
|
$table->dateTime('last_login')->nullable();
|
|
$table->boolean('locked')->default(false);
|
|
$table->boolean('online')->default(false);
|
|
$table->string('sessionkey')->nullable();
|
|
});
|
|
Schema::connection('vmangos_auth')->create('realmlist', function (Blueprint $table): void {
|
|
$table->increments('id');
|
|
});
|
|
Schema::connection('vmangos_auth')->create('realmcharacters', function (Blueprint $table): void {
|
|
$table->unsignedInteger('realmid');
|
|
$table->unsignedInteger('acctid');
|
|
$table->unsignedTinyInteger('numchars');
|
|
$table->primary(['realmid', 'acctid']);
|
|
});
|
|
Schema::connection('vmangos_auth')->create('account_access', function (Blueprint $table): void {
|
|
$table->unsignedInteger('id');
|
|
$table->integer('RealmID');
|
|
$table->unsignedTinyInteger('gmlevel');
|
|
$table->primary(['id', 'RealmID']);
|
|
});
|
|
Schema::connection('vmangos_auth')->create('site_credentials', function (Blueprint $table): void {
|
|
$table->unsignedInteger('account_id')->primary();
|
|
$table->unsignedInteger('legacy_account_id')->nullable()->unique();
|
|
$table->char('salt_hex', 64);
|
|
$table->char('verifier_hex', 64);
|
|
$table->timestamps();
|
|
});
|
|
Schema::connection('vmangos_characters')->create('characters', function (Blueprint $table): void {
|
|
$table->unsignedInteger('guid')->primary();
|
|
$table->unsignedInteger('account');
|
|
$table->string('name');
|
|
$table->unsignedTinyInteger('race');
|
|
$table->unsignedTinyInteger('class');
|
|
$table->unsignedTinyInteger('gender');
|
|
$table->unsignedTinyInteger('level');
|
|
$table->boolean('online');
|
|
$table->unsignedInteger('money');
|
|
$table->unsignedInteger('played_time_total');
|
|
});
|
|
}
|
|
|
|
public function test_srp_matches_vmangos_core_control_vector(): void
|
|
{
|
|
$srp = app(VMangosSrpService::class);
|
|
$salt = 'D04E6342FE6CB5FAE54C6182F885778D0AEFE4BFCDDC6B5C7DF7DC25FF6E3C2D';
|
|
$verifier = '46FD48476D925C4422DD1761C299C79FD6C92B5243E4F3C6C62576C0DABD8260';
|
|
|
|
$this->assertSame($verifier, $srp->makeVerifierHex('VMANGOS', '4EVER', $salt));
|
|
$this->assertTrue($srp->credentialsMatch('vmangos', '4ever', $salt, $verifier));
|
|
$this->assertFalse($srp->credentialsMatch('vmangos', 'wrong', $salt, $verifier));
|
|
}
|
|
|
|
public function test_registration_login_password_access_and_characters_use_vmangos_schema(): void
|
|
{
|
|
DB::connection('vmangos_auth')->table('realmlist')->insert([['id' => 1], ['id' => 2]]);
|
|
$registered = app(VMangosAccountRegistrar::class)->register('PlayerOne', 'player@example.com', 'Pass1234');
|
|
$id = $registered['id'];
|
|
$this->assertSame('PLAYERONE', $registered['username']);
|
|
$this->assertDatabaseHas('account', ['id' => $id, 'username' => 'PLAYERONE', 'expansion' => 0], 'vmangos_auth');
|
|
$this->assertSame(2, DB::connection('vmangos_auth')->table('realmcharacters')->where('acctid', $id)->count());
|
|
$this->assertDatabaseHas('account_access', ['id' => $id, 'RealmID' => -1, 'gmlevel' => 0], 'vmangos_auth');
|
|
$gameCredential = DB::connection('vmangos_auth')->table('account')->where('id', $id)->first();
|
|
$this->assertFalse(app(VMangosSrpService::class)->credentialsMatch('PLAYERONE', 'Pass1234', $gameCredential->s, $gameCredential->v));
|
|
|
|
$accounts = app(VMangosAccountService::class);
|
|
$user = $accounts->findUserByUsername('playerone');
|
|
$this->assertNotNull($user);
|
|
$this->assertTrue($accounts->validatePassword($user, 'Pass1234'));
|
|
$this->assertFalse($accounts->validatePassword($user, 'Wrong1234'));
|
|
|
|
DB::connection('vmangos_auth')->table('account')->where('id', $id)->update(['last_login' => '0000-00-00 00:00:00']);
|
|
$this->assertSame('—', $accounts->findUserById($id)->lastLoginLabel());
|
|
|
|
$accounts->updateAccessLevel($id, 3);
|
|
$this->assertSame(3, $accounts->findUserById($id)->gmLevel);
|
|
|
|
DB::connection('vmangos_characters')->table('characters')->insert([
|
|
'guid' => 11, 'account' => $id, 'name' => 'Hero', 'race' => 1, 'class' => 1,
|
|
'gender' => 0, 'level' => 60, 'online' => 1, 'money' => 12345, 'played_time_total' => 7200,
|
|
]);
|
|
$character = $accounts->charactersForAccount($id)->first();
|
|
$this->assertSame('Hero', $character['name']);
|
|
$this->assertSame('2ч 0м', $character['played']);
|
|
|
|
$accounts->updatePassword($user, 'NewPass123');
|
|
$fresh = $accounts->findUserById($id);
|
|
$this->assertFalse($accounts->validatePassword($fresh, 'Pass1234'));
|
|
$this->assertTrue($accounts->validatePassword($fresh, 'NewPass123'));
|
|
$this->assertSame($gameCredential->v, DB::connection('vmangos_auth')->table('account')->where('id', $id)->value('v'));
|
|
}
|
|
}
|