Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

1.2 KB
Raw Blame
<?php

use Illuminate\Log\LogManager;
use Monolog\Handler\TestHandler;

it('redacts secrets when Laravel creates a configured log channel', function (string $channel) {
    config(['logging.redaction_enabled' => true, 'constants.coolify.self_hosted' => true]);
    $configuration = config("logging.channels.{$channel}");
    $configuration['driver'] = 'monolog';
    $configuration['handler'] = TestHandler::class;
    config([
        "logging.channels.{$channel}" => $configuration,
        'logging.channels.emergency.path' => '/dev/null',
    ]);
    $logger = (new LogManager(app()))->channel($channel);
    $handler = $logger->getLogger()->getHandlers()[0];

    expect($handler)->toBeInstanceOf(TestHandler::class);

    $logger->error('password=coolify-canary-channel-secret', [
        'token' => 'coolify-canary-context-secret',
        'user_email' => '[email protected]',
    ]);

    $record = $handler->getRecords()[0];

    expect($record->message)->toBe('password='.REDACTED);
    expect($record->context['token'])->toBe(REDACTED);
    expect($record->context['user_email'])->toBe($channel === 'audit' ? '[email protected]' : REDACTED);
})->with(['single', 'audit']);