Kiosk: System Name storage, validation, sync, and sent on license validation

Adds local System Name persistence (trimmed, 1-40) in system_kv, an
injectable sync module with conflict/invalid revert and a pending-sync
flag, a background SystemNameSync worker (retries on boot and on a timer),
and api_client support for PUT /licenses/{key}/system-name plus the
additive systemName field/systemNameStatus on license validation. The
license service sends the stored name and applies the status. Covers
validation, pending retry, and conflict revert with a faked HTTP layer.
This commit is contained in:
NeilClack
2026-09-29 09:57:52 -05:00
parent 003a90d810
commit e7df02344b
16 changed files with 812 additions and 13 deletions
+75
View File
@@ -1,5 +1,6 @@
#include "network/license_service.h"
#include "db/db_keys.h"
#include "network/system_name.h"
#include <gtest/gtest.h>
#include <cstdlib>
@@ -9,6 +10,7 @@
using namespace radiantwave::license;
using namespace radiantwave::db;
using namespace radiantwave::systemname;
namespace {
@@ -103,6 +105,79 @@ TEST(LicenseServiceTest, GracePeriodIgnoresCorruptStamp) {
EXPECT_FALSE(isLicenseWithinGracePeriod(tmp.db));
}
// ─── Offline: System Name status handling (faked validation) ────────────
namespace {
radiantwave::api::LicenseResult licenseResult(const std::string& systemNameStatus) {
radiantwave::api::LicenseResult result;
result.status = 200;
result.info.key = "ABCD-EFGH-IJKL-MNOP";
result.info.email_address = "user@example.com";
result.info.system_name_status = systemNameStatus;
return result;
}
} // namespace
TEST(LicenseServiceTest, SendsStoredSystemNameAndMarksSyncedOnOk) {
TempDb tmp;
tmp.db.setKV(KV_LICENSE_KEY, "ABCD-EFGH-IJKL-MNOP");
tmp.db.setKV(KV_EMAIL_ADDRESS, "user@example.com");
tmp.db.setKV(KV_SYSTEM_NAME, "Den");
tmp.db.setKV(KV_SYSTEM_NAME_PENDING, "1");
std::string sentName = "<none>";
const Result result = validateStoredLicenseWith(
tmp.db,
[&](const std::string&, const std::string&, const std::string& systemName) {
sentName = systemName;
return licenseResult("ok");
});
EXPECT_EQ(result, Result::Ok);
EXPECT_EQ(sentName, "Den");
EXPECT_FALSE(pendingSync(tmp.db));
EXPECT_EQ(tmp.db.getKV(KV_SYSTEM_NAME_SYNCED), "Den");
}
TEST(LicenseServiceTest, RevertsLocalNameOnConflictStatus) {
TempDb tmp;
tmp.db.setKV(KV_LICENSE_KEY, "ABCD-EFGH-IJKL-MNOP");
tmp.db.setKV(KV_EMAIL_ADDRESS, "user@example.com");
tmp.db.setKV(KV_SYSTEM_NAME_SYNCED, "Living Room");
tmp.db.setKV(KV_SYSTEM_NAME, "Den");
tmp.db.setKV(KV_SYSTEM_NAME_PENDING, "1");
const Result result = validateStoredLicenseWith(
tmp.db,
[](const std::string&, const std::string&, const std::string&) {
return licenseResult("conflict");
});
EXPECT_EQ(result, Result::Ok);
EXPECT_EQ(storedName(tmp.db), "Living Room");
EXPECT_EQ(tmp.db.getKV(KV_SYSTEM_NAME_MESSAGE), CONFLICT_MESSAGE);
}
TEST(LicenseServiceTest, LeavesPendingWhenServerReportsNoNameStatus) {
TempDb tmp;
tmp.db.setKV(KV_LICENSE_KEY, "ABCD-EFGH-IJKL-MNOP");
tmp.db.setKV(KV_EMAIL_ADDRESS, "user@example.com");
tmp.db.setKV(KV_SYSTEM_NAME, "Den");
tmp.db.setKV(KV_SYSTEM_NAME_PENDING, "1");
const Result result = validateStoredLicenseWith(
tmp.db,
[](const std::string&, const std::string&, const std::string&) {
return licenseResult("");
});
EXPECT_EQ(result, Result::Ok);
EXPECT_TRUE(pendingSync(tmp.db));
EXPECT_EQ(storedName(tmp.db), "Den");
}
// ─── Live: full validation + persistence (requires env credentials) ─────
TEST(LicenseServiceLiveTest, ValidatesAndGrantsSubscribedState) {