Files
michaelschiemer/tests/debug/test-mask-before-after.php
Michael Schiemer 95147ff23e refactor(deployment): Remove WireGuard VPN dependency and restore public service access
Remove WireGuard integration from production deployment to simplify infrastructure:
- Remove docker-compose-direct-access.yml (VPN-bound services)
- Remove VPN-only middlewares from Grafana, Prometheus, Portainer
- Remove WireGuard middleware definitions from Traefik
- Remove WireGuard IPs (10.8.0.0/24) from Traefik forwarded headers

All monitoring services now publicly accessible via subdomains:
- grafana.michaelschiemer.de (with Grafana native auth)
- prometheus.michaelschiemer.de (with Basic Auth)
- portainer.michaelschiemer.de (with Portainer native auth)

All services use Let's Encrypt SSL certificates via Traefik.
2025-11-05 12:48:25 +01:00

81 lines
3.2 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use App\Framework\QrCode\QrCodeGenerator;
use App\Framework\QrCode\Masking\MaskEvaluator;
use App\Framework\QrCode\ValueObjects\ErrorCorrectionLevel;
use App\Framework\QrCode\ValueObjects\QrCodeConfig;
use App\Framework\QrCode\ValueObjects\QrCodeVersion;
use App\Framework\QrCode\ValueObjects\EncodingMode;
echo "=== Testing Mask Application ===\n\n";
$testData = 'HELLO WORLD';
$config = new QrCodeConfig(
version: QrCodeVersion::fromNumber(1),
errorCorrectionLevel: ErrorCorrectionLevel::M,
encodingMode: EncodingMode::BYTE
);
// Use reflection to get matrix before masking
$generator = new \App\Framework\QrCode\QrCodeGenerator(new \App\Framework\QrCode\QrCodeRenderer());
$reflection = new \ReflectionClass($generator);
$generateMatrixMethod = $reflection->getMethod('generateMatrix');
$generateMatrixMethod->setAccessible(true);
// Create matrix step by step to see what happens before/after masking
$matrix = \App\Framework\QrCode\ValueObjects\QrCodeMatrix::create($config->version);
$matrix = \App\Framework\QrCode\Structure\FinderPattern::apply($matrix);
$matrix = \App\Framework\QrCode\Structure\FinderPattern::applySeparators($matrix);
$matrix = \App\Framework\QrCode\Structure\AlignmentPattern::apply($matrix);
$matrix = \App\Framework\QrCode\Structure\TimingPattern::apply($matrix);
$darkModuleRow = 4 * $config->version->getVersionNumber() + 9;
$matrix = $matrix->setModuleAt($darkModuleRow, 8, \App\Framework\QrCode\ValueObjects\Module::dark());
// Encode data
$encodeDataMethod = $reflection->getMethod('encodeData');
$encodeDataMethod->setAccessible(true);
$dataCodewords = $encodeDataMethod->invoke($generator, $testData, $config);
// Generate EC
$reedSolomon = new \App\Framework\QrCode\ErrorCorrection\ReedSolomonEncoder();
$ecInfo = \App\Framework\QrCode\ErrorCorrection\ReedSolomonEncoder::getECInfo(1, 'M');
$ecCodewords = $reedSolomon->encode($dataCodewords, $ecInfo['ecCodewords']);
// Place data
$placeDataMethod = $reflection->getMethod('placeDataCodewords');
$placeDataMethod->setAccessible(true);
$matrixBeforeMask = $placeDataMethod->invoke($generator, $matrix, array_merge($dataCodewords, $ecCodewords));
// Select and apply mask
$maskEvaluator = new MaskEvaluator();
$bestMask = $maskEvaluator->selectBestMask($matrixBeforeMask);
echo "Selected mask pattern: {$bestMask->value}\n\n";
// Check first data position before masking
$testRow = 20;
$testCol = 20;
$beforeMask = $matrixBeforeMask->getModuleAt($testRow, $testCol)->isDark() ? 1 : 0;
echo "Position ({$testRow}, {$testCol}) before mask: {$beforeMask}\n";
// Apply mask
$matrixAfterMask = $maskEvaluator->applyMask($matrixBeforeMask, $bestMask);
$afterMask = $matrixAfterMask->getModuleAt($testRow, $testCol)->isDark() ? 1 : 0;
echo "Position ({$testRow}, {$testCol}) after mask: {$afterMask}\n";
$shouldInvert = $bestMask->shouldInvert($testRow, $testCol);
$expectedAfter = $shouldInvert ? (1 - $beforeMask) : $beforeMask;
echo "Expected after mask: {$expectedAfter} (shouldInvert: " . ($shouldInvert ? 'YES' : 'NO') . ")\n";
if ($afterMask === $expectedAfter) {
echo "✅ Mask application is CORRECT!\n";
} else {
echo "❌ Mask application is WRONG!\n";
}