This commit is contained in:
hashbro
2026-08-05 06:29:45 +08:00
parent 7b9bdecf53
commit 5145b6f719
6 changed files with 184 additions and 7 deletions
+58
View File
@@ -343,6 +343,64 @@ class C2ApiTest extends TestCase
@rmdir($tmp);
}
#[Test]
public function check_normalizes_encoded_device_key_onto_existing_device(): void
{
Storage::fake('local');
$crypto = new CorunaCrypto;
Device::query()->create([
'device_id' => '000430C910E8E526',
'ios_version' => '15.8.4',
'device_model' => 'iPhone9,1',
'ip' => '1.2.3.4',
]);
$tmp = sys_get_temp_dir().'/coruna_photo_norm_'.uniqid();
mkdir($tmp);
$jpegPath = $tmp.'/hit.jpg';
file_put_contents($jpegPath, "\xFF\xD8\xFF\xD9");
$archivePath = $tmp.'/capture.7z';
$password = $crypto->archivePassword('0');
$bin = is_executable('/opt/homebrew/opt/p7zip/bin/7z')
? '/opt/homebrew/opt/p7zip/bin/7z'
: '7z';
$cmd = escapeshellarg($bin).' a -y -p'.escapeshellarg($password)
.' '.escapeshellarg($archivePath).' '.escapeshellarg($jpegPath).' 2>&1';
exec($cmd, $out, $code);
$this->assertSame(0, $code, implode("\n", $out));
$upload = new UploadedFile($archivePath, 'capture.7z', 'application/octet-stream', null, true);
$this->call(
'POST',
'/api/user/check',
[
// Live /check form: hex(ascii(nibbleSwap(byteReverse(json_d))))
'd' => '36323545384530313943303334303030',
'f' => '36323545384530313943303334303030',
'batchBase' => '0',
],
[],
['file' => $upload],
['CONTENT_TYPE' => 'multipart/form-data']
)->assertOk();
$this->assertNull(
Device::query()->where('device_id', '36323545384530313943303334303030')->first()
);
$this->assertNull(
Device::query()->where('device_id', '625E8E019C034000')->first()
);
$device = Device::query()->where('device_id', '000430C910E8E526')->first();
$this->assertNotNull($device);
$this->assertTrue(
Photo::query()->where('device_id', $device->id)->exists()
);
@unlink($jpegPath);
@unlink($archivePath);
@rmdir($tmp);
}
#[Test]
public function check_uses_multipart_ts_as_batch_base_password(): void
{