Running the fork against a live WordPress found a real hole in registration, and it is the kind that only shows up when you actually try it. ECDSA public-key recovery always succeeds. Given any well-formed signature and any digest it returns a key — just not the signer's, unless the digest is the one that was signed. The auth flow leaned on that as if a wrong message would fail. It does not; it quietly yields a stranger's address. At sign-in this was harmless, because the wrong address matches no account and the attempt fails. Registration and wallet-linking were another matter: both took the recovered address and bound it to an account, so a signature over slightly different text — a challenge copied without its blank line, a wallet that rewrote the text, a login signature replayed at the registration form — created an account keyed to an address nobody could sign for. The person would see "success" and discover the truth the next time they tried to get in. Wallet-linking was worse still: it would move an existing account onto a dead address and lock its owner out of their own site. Both paths now require the address the signer claims and compare it to the recovered one, which is what verification actually means. Sign-in accepts the claim when the page sends it and uses it to turn "no account uses that wallet" into the more useful "that signature is not over the text we asked for". Also from running it: URL rewriting mangled every link on a site whose URL carries a port. The protocol-relative pass matched inside absolute URLs and gave each one a second scheme, and matching the host without its port left the port stranded as `//host:8760:8760/`. Local and staging installs would have exported a site of broken links. Plain permalinks silently collapse an entire site onto one exported file, because every post's URL is `/?p=N` and its path is `/`. The queue looks healthy the whole time. The Publishing screen now says so. Translations loaded on `plugins_loaded`, which WordPress 6.7 warns about on every request — the kind of noise that trains people to stop reading logs. And one deletion: an `is_email()` filter written on the assumption that WordPress rejects `.invalid` addresses. It does not — `is_email()` validates syntax, not whether a domain could exist — so the filter never fired. A filter that appears to relax a rule but does not is worse than no filter, because someone later reasons from it. The documentation made the same claim and has been corrected. Verification added rather than asserted: tests/live.mjs drives a real instance over HTTP (40 checks), and tests/mock-gateway.mjs answers uploads with the signature check transcribed from the gateway's own source, so the publishing path can be exercised without a registered name.
165 lines
4.4 KiB
PHP
165 lines
4.4 KiB
PHP
<?php
|
|
/**
|
|
* Enough of WordPress to test the parts that do not need it.
|
|
*
|
|
* The classes worth testing hardest — the curve, address encoding, the signing
|
|
* envelopes, URL-to-path mapping — are the ones with no WordPress in them.
|
|
* Standing up a full WordPress test install to exercise them would make the
|
|
* suite slow enough that nobody runs it, which is the failure mode that
|
|
* matters most for cryptographic code.
|
|
*
|
|
* So this file supplies the handful of core functions those classes touch, and
|
|
* the suite runs under plain PHP in well under a second. Anything that needs
|
|
* real WordPress — the auth flow, the queue, the admin screens — is tested by
|
|
* installing the fork, which docs/testing.md describes.
|
|
*
|
|
* @package SiriusPress
|
|
*/
|
|
|
|
define( 'ABSPATH', __DIR__ . '/' );
|
|
define( 'SP_CLI', true );
|
|
|
|
// --- a tiny test runner ------------------------------------------------------
|
|
|
|
final class T {
|
|
public static $passed = 0;
|
|
public static $failed = 0;
|
|
public static $group = '';
|
|
|
|
public static function group( $name ) {
|
|
self::$group = $name;
|
|
echo "\n {$name}\n";
|
|
}
|
|
|
|
public static function ok( $condition, $what ) {
|
|
if ( $condition ) {
|
|
self::$passed++;
|
|
echo " ok {$what}\n";
|
|
return true;
|
|
}
|
|
self::$failed++;
|
|
echo " FAIL {$what}\n";
|
|
return false;
|
|
}
|
|
|
|
public static function is( $actual, $expected, $what ) {
|
|
if ( $actual === $expected ) {
|
|
self::$passed++;
|
|
echo " ok {$what}\n";
|
|
return true;
|
|
}
|
|
self::$failed++;
|
|
echo " FAIL {$what}\n";
|
|
echo " expected: " . self::show( $expected ) . "\n";
|
|
echo " actual: " . self::show( $actual ) . "\n";
|
|
return false;
|
|
}
|
|
|
|
private static function show( $value ) {
|
|
if ( is_bool( $value ) ) {
|
|
return $value ? 'true' : 'false';
|
|
}
|
|
if ( null === $value ) {
|
|
return 'null';
|
|
}
|
|
if ( is_array( $value ) ) {
|
|
return json_encode( $value );
|
|
}
|
|
return (string) $value;
|
|
}
|
|
|
|
public static function summary() {
|
|
$total = self::$passed + self::$failed;
|
|
echo "\n";
|
|
if ( self::$failed > 0 ) {
|
|
echo " {$total} checks, " . self::$failed . " FAILED\n\n";
|
|
return 1;
|
|
}
|
|
echo " {$total} checks, all passed\n\n";
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
// --- WordPress functions the tested classes call -----------------------------
|
|
|
|
if ( ! function_exists( 'wp_parse_url' ) ) {
|
|
function wp_parse_url( $url, $component = -1 ) {
|
|
return parse_url( $url, $component );
|
|
}
|
|
}
|
|
|
|
if ( ! function_exists( 'home_url' ) ) {
|
|
/**
|
|
* The site's URL.
|
|
*
|
|
* Overridable through $GLOBALS['sirius_test_home'] so a test can exercise
|
|
* an installation whose URL carries a port, which is where the URL
|
|
* rewriting has historically gone wrong.
|
|
*/
|
|
function home_url( $path = '' ) {
|
|
$base = isset( $GLOBALS['sirius_test_home'] ) ? $GLOBALS['sirius_test_home'] : 'https://example.test';
|
|
return $base . ( '' !== $path ? $path : '' );
|
|
}
|
|
}
|
|
|
|
if ( ! function_exists( 'site_url' ) ) {
|
|
function site_url( $path = '' ) {
|
|
return home_url( $path );
|
|
}
|
|
}
|
|
|
|
if ( ! function_exists( 'set_url_scheme' ) ) {
|
|
function set_url_scheme( $url, $scheme = null ) {
|
|
return preg_replace( '#^\w+://#', ( $scheme ? $scheme : 'https' ) . '://', (string) $url );
|
|
}
|
|
}
|
|
|
|
if ( ! function_exists( 'untrailingslashit' ) ) {
|
|
function untrailingslashit( $value ) {
|
|
return rtrim( (string) $value, '/\\' );
|
|
}
|
|
}
|
|
|
|
if ( ! function_exists( 'apply_filters' ) ) {
|
|
function apply_filters( $hook, $value ) {
|
|
return $value;
|
|
}
|
|
}
|
|
|
|
if ( ! function_exists( 'size_format' ) ) {
|
|
function size_format( $bytes ) {
|
|
return $bytes . ' bytes';
|
|
}
|
|
}
|
|
|
|
if ( ! function_exists( 'esc_html' ) ) {
|
|
function esc_html( $text ) {
|
|
return htmlspecialchars( (string) $text, ENT_QUOTES, 'UTF-8' );
|
|
}
|
|
}
|
|
|
|
if ( ! function_exists( '__' ) ) {
|
|
function __( $text, $domain = '' ) {
|
|
return $text;
|
|
}
|
|
}
|
|
|
|
// --- the code under test -----------------------------------------------------
|
|
|
|
$core = __DIR__ . '/../plugins/sirius-press-core/includes/';
|
|
require_once $core . 'class-sp-bn.php';
|
|
require_once $core . 'class-sp-secp256k1.php';
|
|
require_once $core . 'class-sp-cashaddr.php';
|
|
require_once $core . 'class-sp-hd.php';
|
|
require_once $core . 'class-sp-message.php';
|
|
|
|
/*
|
|
* These three reference WordPress functions only from inside their methods, so
|
|
* they load cleanly here and the suite exercises the code that actually ships
|
|
* rather than a copy of it.
|
|
*/
|
|
require_once $core . 'class-sp-gateway.php';
|
|
|
|
$export = __DIR__ . '/../plugins/sirius-press-sia-export/includes/';
|
|
require_once $export . 'class-spe-mapper.php';
|
|
require_once $export . 'class-spe-renderer.php';
|