mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Add no_proxy and other proxy related settings Set user agent on all http client requests Unify http client usage * Style fixes * Remove useless use statements * Correct variable, good job phpstan * Add tests fix https_proxy bug add tcp:// to the config settings format * style and lint fixes * Remove guzzle from the direct dependencies * Use built in Laravel testing functionality * update baseline
59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace LibreNMS\Tests\Unit;
|
|
|
|
use App\Models\AlertTransport;
|
|
use Illuminate\Http\Client\Request;
|
|
use Illuminate\Support\Facades\Http as LaravelHttp;
|
|
use LibreNMS\Tests\TestCase;
|
|
|
|
class ApiTransportTest extends TestCase
|
|
{
|
|
public function testGetMultilineVariables(): void
|
|
{
|
|
/** @var AlertTransport $transport */
|
|
$transport = AlertTransport::factory()->api('text={{ $msg }}')->make();
|
|
|
|
LaravelHttp::fake([
|
|
'*' => LaravelHttp::response(),
|
|
]);
|
|
|
|
$obj = ['msg' => "This is a multi-line\nalert."];
|
|
$result = $transport->instance()->deliverAlert($obj);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
LaravelHttp::assertSentCount(1);
|
|
LaravelHttp::assertSent(function (Request $request) {
|
|
return $request->method() == 'GET' &&
|
|
$request->url() == 'https://librenms.org?text=This%20is%20a%20multi-line%0Aalert.';
|
|
});
|
|
}
|
|
|
|
public function testPostMultilineVariables(): void
|
|
{
|
|
/** @var AlertTransport $transport */
|
|
$transport = AlertTransport::factory()->api(
|
|
'text={{ $msg }}',
|
|
'post',
|
|
'bodytext={{ $msg }}',
|
|
)->make();
|
|
|
|
LaravelHttp::fake([
|
|
'*' => LaravelHttp::response(),
|
|
]);
|
|
|
|
$obj = ['msg' => "This is a post multi-line\nalert."];
|
|
$result = $transport->instance()->deliverAlert($obj);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
LaravelHttp::assertSentCount(1);
|
|
LaravelHttp::assertSent(function (Request $request) {
|
|
return $request->method() == 'POST' &&
|
|
$request->url() == 'https://librenms.org?text=This%20is%20a%20post%20multi-line%0Aalert.' &&
|
|
$request->body() == "bodytext=This is a post multi-line\nalert.";
|
|
});
|
|
}
|
|
}
|