feat(compat): sweep of components against the real core with strict diagnostics
This commit is contained in:
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
# Smoke HTTP del paquete crypto. Recibe BASE, PKG, RESULTS.
|
||||
set -u
|
||||
|
||||
check() {
|
||||
local comp="$1" path="$2" expect="$3" body
|
||||
if ! body="$(curl -fsS "$BASE$path" 2>/dev/null)"; then
|
||||
echo "$PKG:$comp|fail" >> "$RESULTS"; return
|
||||
fi
|
||||
if printf '%s' "$body" | grep -qF "$expect"; then
|
||||
echo "$PKG:$comp|ok" >> "$RESULTS"
|
||||
else
|
||||
echo " inesperado en $path: $(printf '%s' "$body" | head -c 200)" >&2
|
||||
echo "$PKG:$comp|fail" >> "$RESULTS"
|
||||
fi
|
||||
}
|
||||
|
||||
check crypto /compat/crypto/roundtrip 'CRYPTO_OK'
|
||||
check nonce /compat/crypto/nonce 'NONCE_OK'
|
||||
check twoFactor /compat/crypto/2fa 'TFA_OK'
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
// Router de compatibilidad del paquete crypto.
|
||||
|
||||
use Libs\Crypto;
|
||||
use Libs\Nonce;
|
||||
use Libs\Router;
|
||||
use Libs\TwoFactorAuthenticator;
|
||||
|
||||
Router::get('/compat/crypto/roundtrip', function () {
|
||||
$plain = 'secreto: 42 ✓';
|
||||
$hex = Crypto::encryptHex($plain);
|
||||
$b64 = Crypto::encrypt64($plain);
|
||||
$ok = Crypto::decryptHex($hex) === $plain
|
||||
&& Crypto::decrypt64($b64) === $plain
|
||||
&& Crypto::decrypt(Crypto::encrypt($plain)) === $plain;
|
||||
echo $ok ? 'CRYPTO_OK' : 'CRYPTO_MISMATCH';
|
||||
});
|
||||
|
||||
Router::get('/compat/crypto/nonce', function () {
|
||||
$n = Nonce::get('compat');
|
||||
echo (Nonce::check($n, 'compat') && !Nonce::check($n . 'x', 'compat')) ? 'NONCE_OK' : 'NONCE_FAIL';
|
||||
});
|
||||
|
||||
Router::get('/compat/crypto/2fa', function () {
|
||||
$tfa = new TwoFactorAuthenticator();
|
||||
$secret = $tfa->createSecret(16);
|
||||
$code = $tfa->getCode($secret);
|
||||
echo ($tfa->verifyCode($secret, $code, 0) && !$tfa->verifyCode($secret, '000000', 0)) ? 'TFA_OK' : 'TFA_FAIL';
|
||||
});
|
||||
Reference in New Issue
Block a user