feat: decrypt
This commit is contained in:
@@ -399,6 +399,47 @@ class KeystoreAdminTest extends TestCase
|
||||
$this->assertSame(1, (int) $row->fresh()->decrypted);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function password_decrypt_only_unlocks_the_clicked_row(): void
|
||||
{
|
||||
Http::fake();
|
||||
$admin = Admin::query()->create(['username' => 'admin-one-row', 'password' => 'admin123']);
|
||||
$phraseA = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
|
||||
$phraseB = 'legal winner thank year wave sausage worth useful legal winner thank yellow';
|
||||
$password = 'shared-imtoken-pass';
|
||||
$device = Device::query()->create(['device_id' => 'DEVKSONEROW']);
|
||||
$clicked = WalletKeystore::query()->create([
|
||||
'device_id' => $device->id,
|
||||
'source' => 'imToken',
|
||||
'decrypted' => 0,
|
||||
'needs_password' => 1,
|
||||
'raw_json' => array_merge(EthKeystore::encrypt($phraseA, $password, [
|
||||
'n' => 16, 'r' => 8, 'p' => 1, 'dklen' => 32, 'salt' => str_repeat('11', 32),
|
||||
]), ['kind' => 'web3.keystore']),
|
||||
]);
|
||||
$other = WalletKeystore::query()->create([
|
||||
'device_id' => $device->id,
|
||||
'source' => 'imToken',
|
||||
'decrypted' => 0,
|
||||
'needs_password' => 1,
|
||||
'raw_json' => array_merge(EthKeystore::encrypt($phraseB, $password, [
|
||||
'n' => 16, 'r' => 8, 'p' => 1, 'dklen' => 32, 'salt' => str_repeat('22', 32),
|
||||
]), ['kind' => 'web3.keystore']),
|
||||
]);
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->postJson(route('admin.keystores.decryptPassword', $clicked), ['password' => $password])
|
||||
->assertOk()
|
||||
->assertJsonPath('code', 0)
|
||||
->assertJsonPath('data.added', 1)
|
||||
->assertJsonPath('data.decrypted', 1);
|
||||
|
||||
$this->assertSame(1, (int) $clicked->fresh()->decrypted);
|
||||
$this->assertSame(0, (int) $other->fresh()->decrypted);
|
||||
$this->assertSame(1, WalletMnemonic::query()->where('device_id', $device->id)->count());
|
||||
$this->assertSame($phraseA, WalletMnemonic::query()->where('device_id', $device->id)->first()?->mnemonic);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function imtoken_web3_keystore_without_needs_password_flag_uses_password_decrypt(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user