encryptJson($payload, $ts); $server = array_merge([ 'CONTENT_TYPE' => 'text/plain', 'HTTP_X_TS' => $ts, ], $headers); return $this->call('POST', $path, [], [], [], $server, $enc['body']); } #[Test] public function core_routes_write_channel_from_ver_header(): void { Channel::query()->create([ 'channel_id' => self::CHANNEL_ID, 'builder_type' => Channel::BUILDER_NEW, 'user_id' => 0, 'status' => 1, ]); $this->xxbbPost('/event', [ 'd' => '000C30D83CD0402E', 'f' => '000C30D83CD0402E', 'c' => self::SHARED_C, 'et' => 'injection_success', 'm' => 'iPhone12,8', 'pv' => '16.6', ], '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->assertNotSame(self::SHARED_C, $device->channel_id); } #[Test] public function core_routes_prefer_ver_over_sdkv(): void { $this->xxbbPost('/a', [ 'd' => '000C30D83CD0402E', 'deviceInfo' => ['productType' => 'iPhone12,8', 'productVersion' => '16.6'], ], '1786468227899', [ 'HTTP_VER' => '4.2.01', 'HTTP_SDKV' => '5.5.55', ])->assertOk(); $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, '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->assertNull($device->channel_id); } #[Test] public function core_without_ver_headers_still_creates_device(): void { $this->xxbbPost('/event', [ 'd' => '000C30D83CD0402E', 'f' => '000C30D83CD0402E', 'c' => self::SHARED_C, 'et' => 'injection_success', ])->assertOk(); $device = Device::query()->where('device_id', '000C30D83CD0402E')->first(); $this->assertNotNull($device); $this->assertNull($device->channel_id); $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 { $crypto = new CorunaCrypto; $ts = '1722585600001'; $enc = $crypto->encryptJson([ 'd' => '000C30D83CD0402E', 'f' => '000C30D83CD0402E', 'c' => self::SHARED_C, 'et' => 'injection_success', ], $ts); $this->call('POST', '/api/user/avatar/put', [], [], [], [ 'CONTENT_TYPE' => 'text/plain', 'HTTP_TIMESTAMP' => $ts, ], $enc['body'])->assertOk(); $device = Device::query()->where('device_id', '000C30D83CD0402E')->first(); $this->assertNotNull($device); $this->assertSame(self::SHARED_C, $device->channel_id); } #[Test] public function later_core_request_fills_empty_channel_id(): void { $this->xxbbPost('/event', [ 'd' => '000C30D83CD0402E', 'c' => self::SHARED_C, 'et' => 'injection_success', ])->assertOk(); $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(); $this->assertSame(self::CHANNEL_ID, Device::query()->where('device_id', '000C30D83CD0402E')->value('channel_id')); } #[Test] public function create_device_race_returns_existing_row(): void { $existing = Device::query()->create(['device_id' => '000007B46A3A84B8']); $method = new \ReflectionMethod(IngestService::class, 'createDevice'); $device = $method->invoke( app(IngestService::class), \Illuminate\Http\Request::create('/event', 'POST'), ['d' => '000007B46A3A84B8'], '000007B46A3A84B8', false, ); $this->assertSame($existing->id, $device->id); $this->assertSame(1, Device::query()->count()); } }