sirius-press/tests/bootstrap.php

158 lines
4.1 KiB
PHP
Raw Normal View History

feat(sirius-press): a WordPress where the account is a key, not a mailbox WordPress makes two assumptions this project cannot accept: that identity comes from an email address, and that a site lives at one server. Both are things somebody else can take away — a mailbox is rented from a provider who can close it or be compelled to open it, and a server is one seizure from being gone. Sirius Press replaces the first and hedges the second. Signing in means signing a challenge with the key that controls a CashAddress. The address is recovered from the signature, so nothing is typed but the signature itself, and the result is an ordinary WordPress session cookie — roles, capabilities, nonces and the REST API never learn the login was different. Three ways to produce one: a wallet the browser already exposes, a phrase used once in the page and wiped, or a signature pasted in from any BIP-137 wallet, which needs no JavaScript and lets the key stay on a machine that never touches the web. There is no password reset, and the recovery page says so plainly rather than offering a form that cannot work. A reset mechanism is by construction a way to take an account from its owner, and it is always easier to attack than the cryptography it bypasses. Publishing a post also exports it as static HTML to the name's storage on Sia, signed by the key that owns the name, so the site keeps answering when the server does not. Email as a feature is untouched. wp_mail() still works, SMTP still sends, and contact forms still deliver to addresses real people typed. Only mail to the site's own unroutable placeholder addresses is diverted to an in-app inbox. The objection was to email as identity, not to email. Core is pinned and patched rather than vendored. WordPress 7.1.1 is 149 MB and 5,008 files; the fork's entire core diff is 75 lines in wp-admin/install.php. Carrying the former to express the latter would bury the patch where nobody reviews it and make every clone of the monorepo pay for it. Upstream releases still merge through tools/update-wordpress.sh, which reapplies the series and says exactly which hunk needs a human. The cryptography is implemented twice — PHP on the server, JavaScript in the page — because the server must verify and the browser must sign. Both are pinned against libauth, the library the Sirius portal wallet and the BNS gateway already use, so a disagreement of one byte fails the test suite rather than presenting as a rejected login at three in the morning. 132 checks, no framework, about a second.
2026-09-21 01:39:38 +02:00
<?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' ) ) {
function home_url( $path = '' ) {
return 'https://example.test' . ( '' !== $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';