// pii_boot: registry builds when every field is marked, boot-fails naming // the unmarked fields otherwise. #include #include #include #include #include "audit/pii/registry.h" #define CHECK(c, msg) \ if (!(c)) { \ std::cerr << "FAIL pii_boot: " << msg << "\n"; \ return 1; \ } int main() { using namespace molo::audit::pii; std::map> schema = { {"users", {"id", "email", "name"}}, {"orders", {"id", "user_id", "total"}}}; std::map marks = { {"users.id", {PiiClass::kNone, true, ErasureRule::kKeep, "pk"}}, {"users.email", {PiiClass::kEmail, true, ErasureRule::kDelete, "consent"}}, {"users.name", {PiiClass::kName, true, ErasureRule::kDelete, "consent"}}, {"orders.id", {PiiClass::kNone, true, ErasureRule::kKeep, "pk"}}, {"orders.user_id", {PiiClass::kNationalId, false, ErasureRule::kMask, "contract"}}, {"orders.total", {PiiClass::kFinancial, true, ErasureRule::kDelete, "contract"}}, }; Registry r = Registry::Build(schema, marks); CHECK(r.size() == 6, "registry size"); CHECK(r.Lookup("users", "email").cls == PiiClass::kEmail, "lookup class"); CHECK(!r.Lookup("orders", "user_id").exportable, "lookup exportable"); CHECK(r.Lookup("nope", "nope").cls == PiiClass::kNone, "lookup default none"); marks.erase("orders.total"); bool threw = false; try { Registry::Build(schema, marks); } catch (const std::runtime_error& e) { threw = true; CHECK(std::string(e.what()).find("orders.total") != std::string::npos, "names missing field"); } CHECK(threw, "unmarked field must boot-fail"); std::cout << "PASS pii_boot\n"; return 0; }