Repos
C++
1.2 KB32 lines Opens in site
Directory
Raw
Download
// SEC-01 / SEC-02: secret values never appear in dumps or warnings.
#include "tttest.hpp"
#include "mologram/Config.hpp"
using mologram::Config;
static const char* kJson = R"({"api_id":1234567,"api_hash":"SECRETHASHVALUE","phone":"+31600SECRET"})";
TEST_CASE("dumpRedacted hides every secret value", "[secrets][unit]") {
Config c = Config::fromText(kJson);
std::string d = c.dumpRedacted();
CHECK(d.find("SECRETHASHVALUE") == std::string::npos);
CHECK(d.find("+31600SECRET") == std::string::npos);
CHECK(d.find("1234567") == std::string::npos);
CHECK(d.find("<redacted>") != std::string::npos);
}
TEST_CASE("warnings never echo a secret value", "[secrets][unit]") {
Config c = Config::fromText(R"({"api_id":"SECRETIDSTRING","api_hash":99887766,"phone":true})");
for (const auto& w : c.warnings()) {
CHECK(w.find("SECRETIDSTRING") == std::string::npos);
CHECK(w.find("99887766") == std::string::npos);
}
CHECK_EQ((int)c.warnings().size(), 3);
CHECK(c.dumpRedacted().find("SECRETIDSTRING") == std::string::npos);
}
TEST_CASE("missing required keys are reported by name only", "[secrets][unit]") {
Config c = Config::fromText(R"({"api_id":5})");
auto m = c.missingRequired();
CHECK_EQ((int)m.size(), 2);
}