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

nordisk/holger-ui

tests/the_console_authorizes_a_first_import.rs

//! ★ **The admin authorizes a first import from the console** (lanes HOL-CDS, HOL-NCSC, NCSC
//! P1): a Holger with no anti-rollback floor refuses every bundle until an admin on the secure
//! side names the one that sets it (`holger-import-9`). The console asks holger's own door,
//! `POST /-/bundle/first-import?vendor=&product=&sequence=` (the same act as `holger bundle
//! allow-first-import` and `holger-cli bundle allow-first-import`), and says holger's answer;
//! holger checks the admin, audits and keeps the grant. Held over the source: one pure module
//! builds the path and reads the answer (unit-tested beside it), and the Sync pane mounts the
//! form that posts it through `session::door`.

const ROOT: &str = env!("CARGO_MANIFEST_DIR");

fn code(path: &str) -> String {
    let text = std::fs::read_to_string(format!("{ROOT}/{path}")).unwrap_or_else(|e| panic!("{path}: {e}"));
    text.lines().filter(|l| !l.trim_start().starts_with("//")).collect::<Vec<_>>().join("\n")
}

#[test]
fn one_pure_module_builds_the_door_and_reads_holgers_answer() {
    let m = code("src/first_import.rs");
    assert!(m.contains("pub fn path(vendor: &str, product: &str, sequence: &str) -> Result<String, String>"), "no first_import::path");
    assert!(m.contains("/-/bundle/first-import?vendor="), "the path is not holger's door");
    assert!(m.contains("pub fn granted(status: u16, body: &str) -> Result<String, String>"), "no first_import::granted");
    assert!(m.contains("#[cfg(test)]"), "the module has no unit tests");
    assert!(code("src/main.rs").contains("mod first_import;"), "the module is not part of the console");
}

#[test]
fn the_sync_pane_mounts_the_first_import_form() {
    let admin = code("src/pages/admin.rs");
    let sync = &admin[admin.find(r#""sync" =>"#).expect("the sync pane")..];
    let sync = &sync[..sync.find('\n').unwrap()];
    assert!(sync.contains("<FirstImportForm"), "the Sync pane does not mount the first-import form: {sync}");
    let form = &admin[admin.find("fn FirstImportForm").expect("the form component")..];
    assert!(form.contains("crate::first_import::path(") && form.contains("crate::session::door(") && form.contains("crate::first_import::granted("), "the form does not post holger's door and say its answer");
}