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

nordisk/edda

xtask/tests/one_partition_rule.rs

//! ★ **RA5-34: the client partition rule is spelled ONCE in edda.** IPv4 by its address, IPv6
//! by its /64, an IPv4-mapped address as its IPv4: nornir-auth-webauthn's `ClientKey`, the SCIM
//! bearer's `client_key` and estate-front's `caller_key` each spelled it out, and a fix to one
//! (A34-8's /64) would miss the others. The one copy is `nornir_auth_webauthn::client_key`.

use std::path::{Path, PathBuf};

fn rust_files(dir: &Path, out: &mut Vec<PathBuf>) {
    for e in std::fs::read_dir(dir).into_iter().flatten().flatten() {
        let p = e.path();
        if p.is_dir() {
            rust_files(&p, out);
        } else if p.extension().is_some_and(|x| x == "rs") {
            out.push(p);
        }
    }
}

#[test]
fn the_client_partition_rule_is_spelled_once() {
    let root = Path::new(env!("CARGO_MANIFEST_DIR"))
        .parent()
        .unwrap()
        .to_path_buf();
    let mut files = Vec::new();
    for e in std::fs::read_dir(root.join("crates")).unwrap().flatten() {
        rust_files(&e.path().join("src"), &mut files);
    }
    let rule = concat!("{:x}:{:x}:{:x}:{:x}", "::/64");
    let mut spelled: Vec<String> = files
        .iter()
        .filter(|f| std::fs::read_to_string(f).is_ok_and(|t| t.contains(rule)))
        .map(|f| f.strip_prefix(&root).unwrap().display().to_string())
        .collect();
    spelled.sort();
    assert_eq!(
        spelled,
        ["crates/nornir-auth-webauthn/src/client_key.rs"],
        "the /64 partition rule is spelled out more than once"
    );
}