/
mikopbx
/
ModuleBeelinePbx
Обзор
Документация
Войти
/
mikopbx
/
ModuleBeelinePbx
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
master
tests/EventLogFormatterTest.php
74 строки
3 KB
boffart
Инициализация модуля ModuleBeelinePbx
08 июл 2026, 17:11
08 июл 2026, 17:11
1cc4e1a
Код
Авторство
О чём код?
<?php /* * MikoPBX - free phone system for small business * Copyright © 2017-2024 Alexey Portnov and Nikolay Beketov * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. */ namespace Modules\ModuleBeelinePbx\Tests; use Modules\ModuleBeelinePbx\Lib\EventLogFormatter; use PHPUnit\Framework\TestCase; /** * Тесты сборки лог-пейлоада входящего события (заглушка EventController). */ class EventLogFormatterTest extends TestCase { /** * Небольшое тело пишется целиком, поля запроса переносятся как есть. */ public function testBuildKeepsSmallBody(): void { $body = '<Event><callState>Alerting</callState></Event>'; $payload = EventLogFormatter::build( 'POST', ['Content-Type' => 'application/xml', 'X-Subscription-Id' => 'sub-1'], ['subscriptionId' => 'sub-1'], $body, '10.0.0.1' ); $this->assertSame('POST', $payload['method']); $this->assertSame('10.0.0.1', $payload['remote_addr']); $this->assertSame(['subscriptionId' => 'sub-1'], $payload['query']); $this->assertSame($body, $payload['body']); $this->assertSame(strlen($body), $payload['body_length']); $this->assertFalse($payload['body_truncated']); $this->assertSame('application/xml', $payload['headers']['Content-Type']); $this->assertSame('sub-1', $payload['headers']['X-Subscription-Id']); } /** * Тело больше порога усекается, длина фиксируется исходная, флаг усечения выставлен. */ public function testBuildTruncatesLargeBody(): void { $body = str_repeat('A', 250); $payload = EventLogFormatter::build('POST', [], [], $body, '10.0.0.1', 100); $this->assertSame(250, $payload['body_length']); $this->assertTrue($payload['body_truncated']); $this->assertSame(100, strlen($payload['body'])); } /** * Чувствительные заголовки маскируются (регистронезависимо), прочие — нет. */ public function testMaskSensitiveHeaders(): void { $masked = EventLogFormatter::maskSensitiveHeaders([ 'Authorization' => 'Bearer secret-token-value', 'X-MPBX-API-AUTH-TOKEN' => '7cd245ea-e341-49fc-940a', 'Content-Type' => 'application/xml', ]); $this->assertSame('Bear***', $masked['Authorization']); $this->assertSame('7cd2***', $masked['X-MPBX-API-AUTH-TOKEN']); $this->assertSame('application/xml', $masked['Content-Type']); } }