Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/holger

holger-estate-front/tests/a_private_holgers_signup_says_it_is_private.rs

//! ★ LOW-PRIV (owner 2026-10-27): **a private Holger's /signup says it is private and to ask its
//! admin.** A front that sells nothing (no shop in its feed: a sold private instance) merges no
//! buy relay, so the sign-up page's every door would answer "Nothing is sold by this site.";
//! the console says this Holger is private instead. A front that sells keeps its sign-up page.

#![cfg(all(feature = "console", feature = "metered"))]

use std::collections::BTreeMap;

use axum::http::StatusCode;
use holger_estate_front::console::Wiring;
use tower::ServiceExt as _;

fn wiring(shop: Option<holger_estate_front::buy::ShopFeed>) -> Wiring {
    Wiring {
        appliance: Some("127.0.0.1:1".into()),
        door: Some("127.0.0.1:1".into()),
        token: Some("console-token-for-tests".into()),
        shop_bearer: None,
        shop,
        refused: Vec::new(),
    }
}

async fn signup(w: &Wiring, dir: &std::path::Path) -> (StatusCode, String) {
    let app = holger_estate_front::console::router(w, Some(dir.to_path_buf()))
        .expect("the console's router");
    let res = app
        .oneshot(
            axum::http::Request::get("/signup?plan=private")
                .body(axum::body::Body::empty())
                .unwrap(),
        )
        .await
        .unwrap();
    let status = res.status();
    let bytes = axum::body::to_bytes(res.into_body(), 1 << 20)
        .await
        .unwrap();
    (status, String::from_utf8_lossy(&bytes).into_owned())
}

#[tokio::test]
async fn a_front_that_sells_nothing_says_this_holger_is_private_at_signup() {
    let dir = tempfile::tempdir().unwrap();
    for (f, body) in [
        ("index.html", "console"),
        ("login.html", "passkey page"),
        ("signup.html", "sign-up page"),
    ] {
        std::fs::write(dir.path().join(f), body).unwrap();
    }
    let (status, body) = signup(&wiring(None), dir.path()).await;
    assert_eq!(
        (status, body.as_str()),
        (StatusCode::NOT_FOUND, holger_ui_server::PRIVATE_SIGNUP),
        "a private Holger's /signup"
    );

    let feed: BTreeMap<String, String> = [
        (
            holger_estate_front::buy::FEED_MONETIZE_BEARER,
            "holger-site-bearer-for-tests",
        ),
        (holger_estate_front::buy::FEED_CONSOLE_PRODUCT, "holger"),
        (holger_estate_front::buy::FEED_FLEET, "http://127.0.0.1:1"),
        (
            holger_estate_front::buy::FEED_PASSKEY_RP,
            "holger.mock.invalid",
        ),
    ]
    .into_iter()
    .map(|(k, v)| (k.to_string(), v.to_string()))
    .collect();
    let shop = holger_estate_front::buy::shop_feed_of(&feed)
        .expect("the feed sells here")
        .expect("a usable feed");
    assert_eq!(
        signup(&wiring(Some(shop)), dir.path()).await,
        (StatusCode::OK, "sign-up page".to_string()),
        "a selling site keeps its sign-up page"
    );
}