2026-03-10 21:20:08 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MintyPHP\Tests\Architecture;
|
|
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-14 07:54:02 +02:00
|
|
|
* GR-SEC-005: All encryption/decryption MUST use core/Support/Crypto.php.
|
2026-03-10 21:20:08 +01:00
|
|
|
* No raw openssl_encrypt/decrypt calls outside that single file.
|
|
|
|
|
*/
|
|
|
|
|
class SecurityCryptoContractTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
use ProjectFileAssertionSupport;
|
|
|
|
|
|
2026-04-13 23:20:05 +02:00
|
|
|
private const CRYPTO_FILE = 'core/Support/Crypto.php';
|
2026-03-10 21:20:08 +01:00
|
|
|
|
|
|
|
|
public function testNoRawOpensslEncryptOutsideCrypto(): void
|
|
|
|
|
{
|
|
|
|
|
$violations = array_merge(
|
2026-04-13 23:20:05 +02:00
|
|
|
$this->findPatternMatchesInPhpFiles('core', '/\bopenssl_encrypt\s*\(/'),
|
2026-03-10 21:20:08 +01:00
|
|
|
$this->findPatternMatchesInPhpFiles('pages', '/\bopenssl_encrypt\s*\(/')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$violations = array_values(array_filter(
|
|
|
|
|
$violations,
|
|
|
|
|
static fn (string $path): bool => $path !== self::CRYPTO_FILE
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[],
|
|
|
|
|
$violations,
|
|
|
|
|
"Raw openssl_encrypt() found outside Crypto.php (GR-SEC-005):\n" . implode("\n", $violations)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testNoRawOpensslDecryptOutsideCrypto(): void
|
|
|
|
|
{
|
|
|
|
|
$violations = array_merge(
|
2026-04-13 23:20:05 +02:00
|
|
|
$this->findPatternMatchesInPhpFiles('core', '/\bopenssl_decrypt\s*\(/'),
|
2026-03-10 21:20:08 +01:00
|
|
|
$this->findPatternMatchesInPhpFiles('pages', '/\bopenssl_decrypt\s*\(/')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$violations = array_values(array_filter(
|
|
|
|
|
$violations,
|
|
|
|
|
static fn (string $path): bool => $path !== self::CRYPTO_FILE
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
[],
|
|
|
|
|
$violations,
|
|
|
|
|
"Raw openssl_decrypt() found outside Crypto.php (GR-SEC-005):\n" . implode("\n", $violations)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|