open-standards/eoc/eoc-rs/crates/eoc-safety/tests/pii_redaction.rs
Transaction Science 5ae7e4ef86 ingest wave E: 3 crates · op-bin + smart-byte-tendermint + eoc-safety
OpenPay (1 crate, 1801 LOC, 57 tests)
  op-bin              BIN/IIN database + range matching + card-network
                      classification. 8-digit normalized prefix Bin +
                      BinRange. Sorted-vec interval tree with O(log N) point
                      lookup + overlap rejection. CardNetwork classify()
                      with structural rules (Visa 4, MC 51-55/2221-2720,
                      Amex 34/37, Discover, JCB, Diners, UnionPay, RuPay,
                      Mir, Troy, Maestro, Elo). Static prefix tables +
                      build_default_tree(). ISO/IEC 7812-1 Annex B Luhn
                      (validate / is_valid / check_digit). Card-type +
                      issuer-country + Durbin regulated-debit. PCI-safe:
                      8-digit cap, no full-PAN APIs.

Smart Byte (1 crate, ~1500 LOC, 20 tests)
  smart-byte-tendermint  BFT consensus. Step enum + Round + propose/prevote/
                         precommit/commit FSM with voting-power tallies.
                         ValidatorSet with 2/3+1 quorum, 1/3+1 trust
                         threshold, round-robin proposer. Block / Header /
                         Commit / CommitSig with Blake3 hashing. Light client
                         (sequential + skipping). ABCI Application trait +
                         EchoApp. DuplicateVoteEvidence + LightClientAttackEvidence.
                         IBC ClientState + ConsensusState + light-client
                         update.

EOC (1 crate, 2084 LOC, 23 tests)
  eoc-safety          AI safety primitives. RegexSet over 16 prompt-injection
                      signatures. 13-family jailbreak detector (DAN/DUDE/
                      Grandma/STAN/AIM/dev-mode/etc.). Presidio-style PII
                      redactor with Luhn-validated CC. Toxicity / bias /
                      NSFW classifier traits + heuristic baselines (5-axis
                      bias, 4-category NSFW with hard-reject for minors).
                      Constitutional AI critique→revise loop. Composable
                      InputGuard / OutputGuard pipelines. JSON-Schema-subset
                      output validator. Token-bucket rate limiter +
                      abuse-window detection. Red-team replay harness.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-24 16:52:07 -04:00

64 lines
1.8 KiB
Rust

//! PII redactor tests.
use eoc_safety::pii::PiiRedactor;
#[test]
fn redacts_email() {
let r = PiiRedactor::new().expect("build redactor");
let rep = r.redact("contact me at [email protected] please");
assert!(rep.has_pii());
assert!(rep.redacted.contains("<EMAIL>"));
assert!(!rep.redacted.contains("[email protected]"));
}
#[test]
fn redacts_ssn() {
let r = PiiRedactor::new().expect("build redactor");
let rep = r.redact("my ssn is 123-45-6789 ok");
assert!(rep.has_pii());
assert!(rep.redacted.contains("<SSN>"));
}
#[test]
fn redacts_phone() {
let r = PiiRedactor::new().expect("build redactor");
let rep = r.redact("call (415) 555-1234 tomorrow");
assert!(rep.has_pii());
assert!(rep.redacted.contains("<PHONE>"));
}
#[test]
fn redacts_luhn_valid_credit_card() {
let r = PiiRedactor::new().expect("build redactor");
// Visa test number, Luhn-valid.
let rep = r.redact("card 4111 1111 1111 1111 expires soon");
assert!(rep.has_pii());
assert!(rep.redacted.contains("<CREDIT_CARD>"));
}
#[test]
fn skips_luhn_invalid_number() {
let r = PiiRedactor::new().expect("build redactor");
let rep = r.redact("card 1234 5678 9012 3456 expires soon");
assert!(
!rep.spans.iter().any(|s| s.category == "CREDIT_CARD"),
"Luhn-invalid number must not be flagged as a credit card"
);
}
#[test]
fn redacts_ipv4() {
let r = PiiRedactor::new().expect("build redactor");
let rep = r.redact("the server is at 10.10.10.3 today");
assert!(rep.has_pii());
assert!(rep.redacted.contains("<IPV4>"));
}
#[test]
fn benign_text_unchanged() {
let r = PiiRedactor::new().expect("build redactor");
let s = "the cat sat on the mat";
let rep = r.redact(s);
assert!(!rep.has_pii());
assert_eq!(rep.redacted, s);
}