feat: new channel
This commit is contained in:
@@ -4,10 +4,8 @@ namespace Tests\Feature;
|
||||
|
||||
use App\Models\Channel;
|
||||
use App\Models\Device;
|
||||
use App\Models\PageVisit;
|
||||
use App\Services\CorunaCrypto;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -17,20 +15,21 @@ class NewBuilderIngestTest extends TestCase
|
||||
|
||||
private const SHARED_C = '202700cfb1ad3de68e11239dcc26c30b';
|
||||
|
||||
private const CHANNEL_ID = 'FAFA9988';
|
||||
private const CHANNEL_ID = '3.1.07';
|
||||
|
||||
private function xxbbPost(string $path, array $payload, string $ts = '1786468227899')
|
||||
private function xxbbPost(string $path, array $payload, string $ts = '1786468227899', array $headers = [])
|
||||
{
|
||||
$enc = (new CorunaCrypto('Ek8pl31K2yeHgQwy'))->encryptJson($payload, $ts);
|
||||
|
||||
return $this->call('POST', $path, [], [], [], [
|
||||
$server = array_merge([
|
||||
'CONTENT_TYPE' => 'text/plain',
|
||||
'HTTP_X_TS' => $ts,
|
||||
], $enc['body']);
|
||||
], $headers);
|
||||
|
||||
return $this->call('POST', $path, [], [], [], $server, $enc['body']);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function new_builder_device_uses_recent_visit_not_native_c(): void
|
||||
public function core_routes_write_channel_from_ver_header(): void
|
||||
{
|
||||
Channel::query()->create([
|
||||
'channel_id' => self::CHANNEL_ID,
|
||||
@@ -38,104 +37,74 @@ class NewBuilderIngestTest extends TestCase
|
||||
'user_id' => 0,
|
||||
'status' => 1,
|
||||
]);
|
||||
Cache::flush();
|
||||
$this->call('POST', '/api/iptj', [], [], [], [
|
||||
'CONTENT_TYPE' => 'application/json',
|
||||
'REMOTE_ADDR' => '203.0.113.9',
|
||||
], json_encode([
|
||||
'channelCode' => 'fafa9988',
|
||||
'deviceVersion' => 'iOS 16.6',
|
||||
'domain' => 'landing.example',
|
||||
'sessionId' => '11111111-2222-4333-8444-555555555555',
|
||||
]))->assertOk();
|
||||
|
||||
$this->call('POST', '/event', [], [], [], [
|
||||
'CONTENT_TYPE' => 'text/plain',
|
||||
'HTTP_X_TS' => '1786468227899',
|
||||
'REMOTE_ADDR' => '203.0.113.9',
|
||||
], (new CorunaCrypto('Ek8pl31K2yeHgQwy'))->encryptJson([
|
||||
$this->xxbbPost('/event', [
|
||||
'd' => '000C30D83CD0402E',
|
||||
'f' => '000C30D83CD0402E',
|
||||
'c' => self::SHARED_C,
|
||||
'et' => 'injection_success',
|
||||
'm' => 'iPhone12,8',
|
||||
'pv' => '16.6',
|
||||
], '1786468227899')['body'])->assertOk();
|
||||
], '1786468227899', [
|
||||
'HTTP_VER' => self::CHANNEL_ID,
|
||||
'HTTP_SDKV' => self::CHANNEL_ID,
|
||||
])->assertOk();
|
||||
|
||||
$device = Device::query()->where('device_id', '000C30D83CD0402E')->first();
|
||||
$this->assertNotNull($device);
|
||||
$this->assertSame(self::CHANNEL_ID, $device->channel_id);
|
||||
$this->assertSame('landing.example', $device->source_domain);
|
||||
$this->assertNotSame(self::SHARED_C, $device->channel_id);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function new_builder_device_matches_visit_across_ipv4_and_ipv6(): void
|
||||
public function core_routes_prefer_ver_over_sdkv(): void
|
||||
{
|
||||
Channel::query()->create([
|
||||
'channel_id' => self::CHANNEL_ID,
|
||||
'builder_type' => Channel::BUILDER_NEW,
|
||||
'user_id' => 0,
|
||||
'status' => 1,
|
||||
]);
|
||||
PageVisit::query()->create([
|
||||
'channel_id' => self::CHANNEL_ID,
|
||||
'client_uid' => 'landing.example',
|
||||
'ip' => '203.0.113.9',
|
||||
'domain' => 'landing.example',
|
||||
'created_at' => now(),
|
||||
]);
|
||||
$this->xxbbPost('/a', [
|
||||
'd' => '000C30D83CD0402E',
|
||||
'deviceInfo' => ['productType' => 'iPhone12,8', 'productVersion' => '16.6'],
|
||||
], '1786468227899', [
|
||||
'HTTP_VER' => '4.2.01',
|
||||
'HTTP_SDKV' => '5.5.55',
|
||||
])->assertOk();
|
||||
|
||||
$this->call('POST', '/event', [], [], [], [
|
||||
'CONTENT_TYPE' => 'text/plain',
|
||||
'HTTP_X_TS' => '1786468227899',
|
||||
'REMOTE_ADDR' => '2001:db8::9',
|
||||
], (new CorunaCrypto('Ek8pl31K2yeHgQwy'))->encryptJson([
|
||||
$device = Device::query()->where('device_id', '000C30D83CD0402E')->first();
|
||||
$this->assertSame('4.2.01', $device->channel_id);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function core_routes_accept_sdkv_when_ver_missing(): void
|
||||
{
|
||||
$this->xxbbPost('/u', [
|
||||
'd' => '000C30D83CD0402E',
|
||||
'c' => self::SHARED_C,
|
||||
'et' => 'injection_success',
|
||||
], '1786468227899')['body'])->assertOk();
|
||||
'al' => [],
|
||||
], '1786468227899', [
|
||||
'HTTP_SDKV' => self::CHANNEL_ID,
|
||||
])->assertOk();
|
||||
|
||||
$device = Device::query()->where('device_id', '000C30D83CD0402E')->first();
|
||||
$this->assertSame(self::CHANNEL_ID, $device->channel_id);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function non_core_routes_do_not_write_channel_id(): void
|
||||
{
|
||||
$this->xxbbPost('/uj', [
|
||||
'd' => '000C30D83CD0402E',
|
||||
'a' => 'b',
|
||||
'result' => 'abandon ability able about above absent absorb abstract absurd abuse access',
|
||||
], '1786468227899', [
|
||||
'HTTP_VER' => self::CHANNEL_ID,
|
||||
'HTTP_SDKV' => self::CHANNEL_ID,
|
||||
])->assertOk();
|
||||
|
||||
$device = Device::query()->where('device_id', '000C30D83CD0402E')->first();
|
||||
$this->assertNotNull($device);
|
||||
$this->assertSame(self::CHANNEL_ID, $device->channel_id);
|
||||
$this->assertSame('landing.example', $device->source_domain);
|
||||
$this->assertSame('2001:db8::9', $device->ip);
|
||||
$this->assertNull($device->channel_id);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function new_builder_device_matches_ipv4_mapped_ipv6(): void
|
||||
{
|
||||
Channel::query()->create([
|
||||
'channel_id' => self::CHANNEL_ID,
|
||||
'builder_type' => Channel::BUILDER_NEW,
|
||||
'user_id' => 0,
|
||||
'status' => 1,
|
||||
]);
|
||||
PageVisit::query()->create([
|
||||
'channel_id' => self::CHANNEL_ID,
|
||||
'client_uid' => 'landing.example',
|
||||
'ip' => '::ffff:203.0.113.9',
|
||||
'domain' => 'landing.example',
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
$this->call('POST', '/event', [], [], [], [
|
||||
'CONTENT_TYPE' => 'text/plain',
|
||||
'HTTP_X_TS' => '1786468227899',
|
||||
'REMOTE_ADDR' => '203.0.113.9',
|
||||
], (new CorunaCrypto('Ek8pl31K2yeHgQwy'))->encryptJson([
|
||||
'd' => '000C30D83CD0402E',
|
||||
'c' => self::SHARED_C,
|
||||
'et' => 'injection_success',
|
||||
], '1786468227899')['body'])->assertOk();
|
||||
|
||||
$device = Device::query()->where('device_id', '000C30D83CD0402E')->first();
|
||||
$this->assertSame(self::CHANNEL_ID, $device->channel_id);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function new_builder_device_without_visit_is_still_created(): void
|
||||
public function core_without_ver_headers_still_creates_device(): void
|
||||
{
|
||||
$this->xxbbPost('/event', [
|
||||
'd' => '000C30D83CD0402E',
|
||||
@@ -150,6 +119,21 @@ class NewBuilderIngestTest extends TestCase
|
||||
$this->assertNull($device->source_domain);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function invalid_ver_header_does_not_write_channel_id(): void
|
||||
{
|
||||
$this->xxbbPost('/event', [
|
||||
'd' => '000C30D83CD0402E',
|
||||
'c' => self::SHARED_C,
|
||||
'et' => 'injection_success',
|
||||
], '1786468227899', [
|
||||
'HTTP_VER' => 'FAFA9988',
|
||||
])->assertOk();
|
||||
|
||||
$device = Device::query()->where('device_id', '000C30D83CD0402E')->first();
|
||||
$this->assertNull($device->channel_id);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function old_builder_put_still_writes_payload_c(): void
|
||||
{
|
||||
@@ -173,37 +157,23 @@ class NewBuilderIngestTest extends TestCase
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function claimed_visit_is_not_reused_by_second_device(): void
|
||||
public function later_core_request_fills_empty_channel_id(): void
|
||||
{
|
||||
Channel::query()->create([
|
||||
'channel_id' => self::CHANNEL_ID,
|
||||
'builder_type' => Channel::BUILDER_NEW,
|
||||
'user_id' => 0,
|
||||
'status' => 1,
|
||||
]);
|
||||
PageVisit::query()->create([
|
||||
'channel_id' => self::CHANNEL_ID,
|
||||
'client_uid' => 'landing.example',
|
||||
'ip' => '127.0.0.1',
|
||||
'domain' => 'landing.example',
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
$this->xxbbPost('/event', [
|
||||
'd' => '000C30D83CD0402E',
|
||||
'c' => self::SHARED_C,
|
||||
'et' => 'injection_success',
|
||||
])->assertOk();
|
||||
$this->xxbbPost('/event', [
|
||||
'd' => '111C30D83CD0402E',
|
||||
'c' => self::SHARED_C,
|
||||
'et' => 'injection_success',
|
||||
|
||||
$this->assertNull(Device::query()->where('device_id', '000C30D83CD0402E')->value('channel_id'));
|
||||
|
||||
$this->xxbbPost('/a', [
|
||||
'd' => '000C30D83CD0402E',
|
||||
'deviceInfo' => ['productType' => 'iPhone12,8', 'productVersion' => '16.6'],
|
||||
], '1786468227900', [
|
||||
'HTTP_VER' => self::CHANNEL_ID,
|
||||
])->assertOk();
|
||||
|
||||
$first = Device::query()->where('device_id', '000C30D83CD0402E')->first();
|
||||
$second = Device::query()->where('device_id', '111C30D83CD0402E')->first();
|
||||
$this->assertSame(self::CHANNEL_ID, $first->channel_id);
|
||||
$this->assertNull($second->channel_id);
|
||||
$this->assertNotNull($second);
|
||||
$this->assertSame(self::CHANNEL_ID, Device::query()->where('device_id', '000C30D83CD0402E')->value('channel_id'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user