Expand post-merge regressions and document qualification gaps
This commit is contained in:
1 parent
80023f79e0
commit
a4a0b97c3f
20 files changed
+536
-74
No files matched your search
+19
@@ -333,6 +333,25 @@ static void passwordLimitCases() {
|
||||
ticks = 31000; assert(result(m, request("status", "admin-secret"), sequence++, 25)["role"] == PERM_ACL_ADMIN);
|
||||
ticks = later;
|
||||
}
|
||||
{
|
||||
// A window beginning before UINT32_MAX stays locked through rollover,
|
||||
// expires at its original boundary, and permits a full new failure window.
|
||||
const uint32_t later = ticks, start = UINT32_MAX - 1000u; ticks = start;
|
||||
MyMesh m; enable(m); m._prefs.allow_read_only = false;
|
||||
const unsigned checks = password_checks + 5;
|
||||
for (uint8_t owner = 20; owner < 25; ++owner) error(m, request("status", guess("wrap-", owner).c_str()), sequence++, "incorrect", owner);
|
||||
assert(password_checks == checks);
|
||||
ticks = UINT32_MAX; error(m, request("status", "admin-secret"), sequence++, "too many", 25);
|
||||
ticks = 0; error(m, request("status", "admin-secret"), sequence++, "too many", 25);
|
||||
ticks = start + 29999u; error(m, request("status", "admin-secret"), sequence++, "too many", 25);
|
||||
assert(password_checks == checks);
|
||||
ticks = start + 30000u;
|
||||
assert(result(m, request("status", "admin-secret"), sequence++, 25)["role"] == PERM_ACL_ADMIN);
|
||||
for (uint8_t owner = 30; owner < 35; ++owner) error(m, request("status", guess("after-wrap-", owner).c_str()), sequence++, "incorrect", owner);
|
||||
assert(password_checks == checks + 6);
|
||||
error(m, request("status", "admin-secret"), sequence++, "too many", 25);
|
||||
ticks = later;
|
||||
}
|
||||
{
|
||||
MyMesh m; enable(m); m._prefs.allow_read_only = false;
|
||||
// Neither the guest nor the admin password refunds failed guesses.
|
||||
|
||||
+21
@@ -96,6 +96,27 @@ int main() {
|
||||
assert(login(portal, owner, "existing-secret")==200);
|
||||
assert(login(portal, attacker, "existing-secret")==200);
|
||||
}
|
||||
// Real handler responses retain their exact boundaries when millis wraps.
|
||||
{
|
||||
WebConfigServer portal; const uint32_t start=UINT32_MAX-1000u; now_ms=start;
|
||||
for (int i = 0; i < 5; i++) assert(login(portal, attacker, "guess")==401);
|
||||
now_ms=0;
|
||||
assert(login(portal, attacker, "existing-secret")==429 && last_reply==kLocked);
|
||||
now_ms=start+29999u;
|
||||
assert(login(portal, attacker, "existing-secret")==429 && last_reply==kLocked);
|
||||
now_ms=start+30000u;
|
||||
assert(login(portal, attacker, "existing-secret")==200);
|
||||
}
|
||||
{
|
||||
WebConfigServer portal; const uint32_t start=UINT32_MAX-3000u; now_ms=start;
|
||||
for (uint32_t address = 10; address < 16; address++) assert(login(portal, address, "guess")==401);
|
||||
now_ms=0;
|
||||
assert(login(portal, owner, "existing-secret")==429 && last_reply==kShared);
|
||||
now_ms=start+5999u;
|
||||
assert(login(portal, owner, "existing-secret")==429 && last_reply==kShared);
|
||||
now_ms=start+6000u;
|
||||
assert(login(portal, owner, "existing-secret")==200);
|
||||
}
|
||||
// LAN requests without a client object share one key and do not crash.
|
||||
{
|
||||
WebConfigServer portal; portal._mode=WebConfigServer::MODE_LAN;
|
||||
|
||||
+25
@@ -84,6 +84,31 @@ int main() {
|
||||
assert(t.check(A, now) == ALLOW);
|
||||
assert(t.check(B, now) == ALLOW);
|
||||
}
|
||||
// A lock started just before UINT32_MAX remains active across rollover and
|
||||
// expires at exactly thirty seconds, then gives the client a fresh count.
|
||||
{
|
||||
Tracker t; const uint32_t start = UINT32_MAX - 1000u;
|
||||
fail(t, A, start, kClientFails);
|
||||
assert(t.check(A, UINT32_MAX) == CLIENT_LOCKED);
|
||||
assert(t.check(A, 0) == CLIENT_LOCKED);
|
||||
assert(t.check(B, 0) == ALLOW);
|
||||
assert(t.check(A, start + kClientLockMs - 1) == CLIENT_LOCKED);
|
||||
fail(t, A, start + kClientLockMs, kClientFails);
|
||||
assert(t.check(A, start + kClientLockMs) == CLIENT_LOCKED);
|
||||
}
|
||||
// The shared allowance also refills across rollover, once per six seconds.
|
||||
{
|
||||
Tracker t; const uint32_t start = UINT32_MAX - 3000u;
|
||||
uint32_t ip = 1;
|
||||
for (int i = 0; i < kSharedBudget; i++) fail(t, ip++, start);
|
||||
assert(t.check(ip, UINT32_MAX) == SHARED_LOCKED);
|
||||
assert(t.check(ip, 0) == SHARED_LOCKED);
|
||||
assert(t.check(ip, start + kSharedRefillMs - 1) == SHARED_LOCKED);
|
||||
fail(t, ip++, start + kSharedRefillMs);
|
||||
assert(t.check(ip, start + 2 * kSharedRefillMs - 1) == SHARED_LOCKED);
|
||||
fail(t, ip++, start + 2 * kSharedRefillMs);
|
||||
assert(t.check(ip, start + 2 * kSharedRefillMs) == SHARED_LOCKED);
|
||||
}
|
||||
// Failures recorded without a check saturate instead of wrapping.
|
||||
{
|
||||
Tracker t; uint32_t now = 100000;
|
||||
|
||||
+25
-1
@@ -22,7 +22,11 @@ struct Callback {
|
||||
};
|
||||
struct WCLock { explicit WCLock(int) {} };
|
||||
struct WiFiMock { int softAPIP() const { return 4; } } WiFi;
|
||||
struct Client { int local_ip=4; int localIP() const { return local_ip; } uint32_t getRemoteAddress() const { return 0; } };
|
||||
struct Client {
|
||||
int local_ip=4; uint32_t remote=0;
|
||||
int localIP() const { return local_ip; }
|
||||
uint32_t getRemoteAddress() const { return remote; }
|
||||
};
|
||||
struct Header { String cookies; const String& value() const { return cookies; } };
|
||||
struct AsyncWebServerResponse {
|
||||
int status; std::map<std::string, std::string> headers;
|
||||
@@ -106,5 +110,25 @@ int main() {
|
||||
// password management. Keep that explicit no-password deployment policy.
|
||||
portal._initial_setup=false; portal.callback.node.admin_password[0]=0;
|
||||
assert(portal.checkAuth(&attacker)); portal.handleLogin(&attacker); assert(attacker.status==200);
|
||||
// A spent login budget blocks new logins without revoking an existing
|
||||
// authenticated session, on either the saved-network AP or the LAN.
|
||||
for (int mode : {WebConfigServer::MODE_SETUP, WebConfigServer::MODE_LAN}) {
|
||||
WebConfigServer active; active._mode=mode;
|
||||
AsyncWebServerRequest owner; owner.socket.remote=100;
|
||||
owner.password("existing-secret"); active.handleLogin(&owner);
|
||||
assert(owner.status==200);
|
||||
const std::string token=active._session_token;
|
||||
owner.header.cookies=std::string("wcs=")+token;
|
||||
for (uint32_t address = 1; address <= 6; address++) {
|
||||
AsyncWebServerRequest wrong; wrong.socket.remote=address;
|
||||
wrong.password("wrong"); active.handleLogin(&wrong); assert(wrong.status==401);
|
||||
}
|
||||
AsyncWebServerRequest login; login.socket.remote=200;
|
||||
login.password("existing-secret"); active.handleLogin(&login);
|
||||
assert(login.status==429 && token==active._session_token);
|
||||
assert(active.checkAuth(&owner));
|
||||
active.checkConfigPost(&owner); assert(active.config_accepted);
|
||||
assert(token==active._session_token);
|
||||
}
|
||||
puts("WebConfig recovery authentication regression checks passed");
|
||||
}
|
||||
@@ -125,6 +125,9 @@ static void whole_record_read_errors_keep_bounded_recovery() {
|
||||
static void a_complete_backup_still_wins() {
|
||||
const auto image = tailImage();
|
||||
for (unsigned fault = 0; fault < 3; ++fault) {
|
||||
#if defined(RP2040_PLATFORM)
|
||||
if (fault == 2) continue; // Arduino-Pico exists() hides metadata errors.
|
||||
#endif
|
||||
tailFs() = FakeFilesystem();
|
||||
tailFs().files["/contacts3"] = partial(image, 1);
|
||||
tailFs().files["/contacts3.bak"] = records(image, 2);
|
||||
@@ -143,32 +146,77 @@ static void a_complete_backup_still_wins() {
|
||||
assert(!tailFs().files.count("/contacts3.bak"));
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(ESP32_PLATFORM)
|
||||
static void unknown_backup_presence_preserves_sources() {
|
||||
const auto image = tailImage();
|
||||
tailFs() = FakeFilesystem();
|
||||
tailFs().files["/contacts3"] = partial(image, 1);
|
||||
tailFs().files["/contacts3.bak"] = records(image, 2);
|
||||
tailFs().files["/channels2"] = {3, 4, 5};
|
||||
tailFs().files["/identity/_main.id"] = {7, 8, 9};
|
||||
const auto durable = tailFs().files;
|
||||
{
|
||||
failMetadata(true);
|
||||
TailBoot b;
|
||||
b.store.loadContacts(&b.host);
|
||||
assert(b.store.contactRecoveryPending() && b.host.contacts.empty());
|
||||
assert(!tailSave(b) && tailFs().files == durable);
|
||||
b.store.recoverContacts(&b.host); // Presence remains unknown on the retry.
|
||||
assert(!b.store.contactRecoveryPending() && b.store.contactsAreVolatile());
|
||||
assert(b.host.contacts.empty() && tailFs().files == durable);
|
||||
failMetadata(false);
|
||||
assert(!tailSave(b) && tailFs().files == durable); // Volatile for this boot.
|
||||
}
|
||||
TailBoot rebooted;
|
||||
boot(rebooted);
|
||||
assert(!rebooted.store.hasIncompleteContactLoad() && !rebooted.store.contactsAreVolatile());
|
||||
checkLoaded(rebooted.host, image, 2); // The complete backup still wins.
|
||||
assert(tailFs().files.at("/contacts3") == records(image, 2));
|
||||
assert(!tailFs().files.count("/contacts3.bak"));
|
||||
assert(tailFs().files.at("/channels2") == durable.at("/channels2"));
|
||||
assert(tailFs().files.at("/identity/_main.id") == durable.at("/identity/_main.id"));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !MESH_CONTACT_CACHE
|
||||
static void salvaged_primary_open_failure_is_not_absence() {
|
||||
const auto image = tailImage();
|
||||
filesystem = FakeFilesystem();
|
||||
filesystem.files["/contacts3"] = partial(image, 1);
|
||||
tailFs() = FakeFilesystem();
|
||||
tailFs().files["/contacts3"] = partial(image, 1);
|
||||
{
|
||||
TailBoot dry; // The last read open of a healthy load opens the image to load.
|
||||
dry.store.loadContacts(&dry.host);
|
||||
assert(dry.host.contacts.size() == 3);
|
||||
}
|
||||
const unsigned load_open = filesystem.read_opens;
|
||||
filesystem = FakeFilesystem();
|
||||
filesystem.files["/contacts3"] = partial(image, 1);
|
||||
filesystem.fail_read_open = load_open;
|
||||
TailBoot b;
|
||||
b.store.loadContacts(&b.host);
|
||||
assert(b.store.hasIncompleteContactLoad() && b.store.contactRecoveryPending());
|
||||
const auto unchanged = filesystem.files;
|
||||
assert(!tailSave(b) && filesystem.files == unchanged);
|
||||
b.store.recoverContacts(&b.host);
|
||||
assert(!b.store.hasIncompleteContactLoad() && !b.store.contactRecoveryPending());
|
||||
checkLoaded(b.host, image, 3);
|
||||
}
|
||||
const unsigned load_open = tailFs().read_opens;
|
||||
for (bool add_backup : {false, true}) {
|
||||
#if defined(STM32_PLATFORM)
|
||||
if (add_backup) continue; // STM32 does not select a contact backup.
|
||||
#endif
|
||||
tailFs() = FakeFilesystem();
|
||||
tailFs().files["/contacts3"] = partial(image, 1);
|
||||
tailFs().fail_read_open = load_open;
|
||||
TailBoot b;
|
||||
b.store.loadContacts(&b.host);
|
||||
assert(tailFs().read_opens == load_open);
|
||||
assert(b.store.hasIncompleteContactLoad() && b.store.contactRecoveryPending());
|
||||
assert(b.host.contacts.empty());
|
||||
const auto unchanged = tailFs().files;
|
||||
const auto writes = tailFs().writes;
|
||||
assert(!tailSave(b) && tailFs().files == unchanged && tailFs().writes == writes);
|
||||
// A backup available at the recovery boundary takes precedence over the
|
||||
// salvaged prefix, even though the first selection had admitted it.
|
||||
if (add_backup) tailFs().files["/contacts3.bak"] = records(image, 2);
|
||||
b.store.recoverContacts(&b.host);
|
||||
assert(!b.store.hasIncompleteContactLoad() && !b.store.contactRecoveryPending());
|
||||
checkLoaded(b.host, image, add_backup ? 2 : 3);
|
||||
if (add_backup) {
|
||||
assert(tailFs().files.at("/contacts3") == records(image, 2));
|
||||
assert(!tailFs().files.count("/contacts3.bak"));
|
||||
} else assert(tailFs().files == unchanged);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
partial_tail_keeps_whole_records();
|
||||
@@ -176,10 +224,11 @@ int main() {
|
||||
whole_record_read_errors_keep_bounded_recovery();
|
||||
#if !defined(STM32_PLATFORM)
|
||||
a_complete_backup_still_wins();
|
||||
#if defined(ESP32_PLATFORM)
|
||||
unknown_backup_presence_preserves_sources();
|
||||
#endif
|
||||
#endif
|
||||
#if !MESH_CONTACT_CACHE
|
||||
salvaged_primary_open_failure_is_not_absence();
|
||||
#endif
|
||||
printf("''' + MARKER + r'''\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -206,7 +255,18 @@ def uncached_fixture(work):
|
||||
|
||||
def cached_fixture(work):
|
||||
fixtures = ROOT / "test/fixtures/contact_cache"
|
||||
(work / "FakeFilesystem.h").write_text((fixtures / "FakeFilesystem.h").read_text())
|
||||
filesystem = (fixtures / "FakeFilesystem.h").read_text()
|
||||
# Match the uncached fixture's one-shot final-load-open failure without
|
||||
# changing the shared filesystem adapter used by unrelated cache tests.
|
||||
for old, new in ((" unsigned false_success_rename = 0, late_rename_error = 0;\n",
|
||||
" unsigned false_success_rename = 0, late_rename_error = 0;\n"
|
||||
" unsigned read_opens = 0, fail_read_open = 0;\n"),
|
||||
(" auto failure = read_open_failures.find(path);\n",
|
||||
" if (++read_opens == fail_read_open) return File();\n"
|
||||
" auto failure = read_open_failures.find(path);\n")):
|
||||
assert filesystem.count(old) == 1, old
|
||||
filesystem = filesystem.replace(old, new)
|
||||
(work / "FakeFilesystem.h").write_text(filesystem)
|
||||
source = (fixtures / "test_contact_cache.cpp").read_text()
|
||||
generated = work / "partial_tail.cpp"
|
||||
generated.write_text("#include <cstdio>\n" + source[:source.index("int main() {")] + CHECKS)
|
||||
|
||||
@@ -147,6 +147,30 @@ class Esp32MigrationRecipeTest(unittest.TestCase):
|
||||
self.assertEqual("esp32_s3_8mb_partition_migrator_usb", steps[3][0][3])
|
||||
self.assertEqual("esp32_s3_8mb_partition_migrator_lora", steps[4][0][3])
|
||||
|
||||
def test_generated_guides_explain_credentials_for_each_recovery_route(self):
|
||||
for board in ("heltec-v2-room-server", "heltec-v4",
|
||||
"waveshare-s3-lr1121-observer-repeater"):
|
||||
with self.subTest(board=board):
|
||||
guide = readme(board, BOARDS[board], "v1.18.0-test", "01234567")
|
||||
credentials = " ".join(guide.split("## Bridge Wi-Fi credentials\n", 1)[1]
|
||||
.split("## Wi-Fi route\n", 1)[0].split())
|
||||
for rule in ("saved admin password", "8 to 15 printable ASCII characters",
|
||||
"shorter than 8", "nonprintable or non-ASCII", "cannot be read",
|
||||
"Missing saved preferences", "meshcore-migrate",
|
||||
"verify it survives a normal reboot"):
|
||||
self.assertIn(rule, credentials)
|
||||
lora = " ".join(guide.split("## LoRa route", 1)[1].split())
|
||||
if BOARDS[board].get("expander_bridge") == BOARDS[board]["lora_bridge"]:
|
||||
self.assertIn("uses the restored saved admin password", lora)
|
||||
self.assertNotIn("post-expansion Wi-Fi recovery AP normally uses", lora)
|
||||
else:
|
||||
self.assertIn("post-expansion Wi-Fi recovery AP normally uses `meshcore-migrate`",
|
||||
lora)
|
||||
if BOARDS[board].get("expander_bridge"):
|
||||
expander = " ".join(guide.split("## Partition Expander route", 1)[1]
|
||||
.split("## LoRa route", 1)[0].split())
|
||||
self.assertIn("uses the restored saved admin password", expander)
|
||||
|
||||
def test_all_six_usb_chip_capacity_profiles_are_built_once_and_wifi_retained(self):
|
||||
steps = build_steps(list(BOARDS), "v1.17.1.7-test", "usa-cascadia", "cascade", 4)
|
||||
utilities = [command[3] for command, full in steps if not full]
|
||||
|
||||
@@ -111,8 +111,9 @@ esp_err_t esp_wifi_get_max_tx_power(int8_t* power) { *power = 78; return ESP_OK;
|
||||
void delay(unsigned) {}
|
||||
|
||||
struct AsyncWebServerRequest {
|
||||
void send(int, const char*, const String&) {}
|
||||
void send(int, const char*, const char*) {}
|
||||
std::string body;
|
||||
void send(int, const char*, const String& text) { body = text.s; }
|
||||
void send(int, const char*, const char* text) { body = text; }
|
||||
};
|
||||
struct AsyncWebServer {
|
||||
std::vector<std::string> routes;
|
||||
@@ -136,6 +137,7 @@ struct File {
|
||||
struct Filesystem {
|
||||
std::map<std::string, std::vector<uint8_t>> files;
|
||||
bool mountable = true, mounted = false, seek_fails = false, short_read = false;
|
||||
std::string fail_open;
|
||||
unsigned begins = 0, ends = 0, opens = 0, closes = 0;
|
||||
// Before migration this is the legacy filesystem: it must never be formatted.
|
||||
bool begin(bool format) { assert(!format); ++begins; mounted = mountable; return mounted; }
|
||||
@@ -145,7 +147,9 @@ struct Filesystem {
|
||||
assert(!strcmp(mode, "r"));
|
||||
File file;
|
||||
auto entry = files.find(path);
|
||||
if (mounted && entry != files.end()) { file.data = &entry->second; ++opens; }
|
||||
if (mounted && fail_open != path && entry != files.end()) {
|
||||
file.data = &entry->second; ++opens;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
} SPIFFS;
|
||||
@@ -235,6 +239,18 @@ void expectFallback() {
|
||||
balancedMount();
|
||||
}
|
||||
|
||||
void expectUploadDisabled(const char* expected_password) {
|
||||
startServer();
|
||||
assert(WiFi.ap_calls == 1 && !WiFi.open && WiFi.password == expected_password);
|
||||
assert(AsyncElegantOTA.begins == 0);
|
||||
AsyncWebServerRequest request;
|
||||
sendHome(&request);
|
||||
assert(request.body.find("Private identity recovery did not complete") != std::string::npos);
|
||||
assert(request.body.find("Firmware upload is disabled") != std::string::npos);
|
||||
assert(request.body.find("href='/update'") == std::string::npos);
|
||||
balancedMount();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
assert(argc == 2);
|
||||
const int scenario = atoi(argv[1]);
|
||||
@@ -288,6 +304,19 @@ int main(int argc, char** argv) {
|
||||
reset(); SPIFFS.short_read = true;
|
||||
SPIFFS.files["/com_prefs"] = prefs(290, "Correct-Horse9");
|
||||
expectFallback();
|
||||
} else if (scenario == 7) {
|
||||
reset(true); identity_ready = false;
|
||||
SPIFFS.files["/com_prefs"] = prefs(290, "Correct-Horse9");
|
||||
expectUploadDisabled("Correct-Horse9");
|
||||
reset(true); identity_ready = false;
|
||||
expectUploadDisabled(kFallback);
|
||||
} else if (scenario == 8) {
|
||||
// Existing /com_prefs wins even when it cannot be opened. Never use a
|
||||
// potentially stale /node_prefs password to bypass that file precedence.
|
||||
reset(); SPIFFS.fail_open = "/com_prefs";
|
||||
SPIFFS.files["/com_prefs"] = prefs(290, "Com-prefs-pass");
|
||||
SPIFFS.files["/node_prefs"] = prefs(290, "Node-prefs-pass");
|
||||
expectFallback();
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
@@ -361,6 +390,12 @@ class MigrationBridgeApPasswordTests(unittest.TestCase):
|
||||
def test_failed_seek_or_partial_read_falls_back(self):
|
||||
self.run_scenario(6)
|
||||
|
||||
def test_failed_identity_restore_disables_upload_with_either_ap_credential(self):
|
||||
self.run_scenario(7)
|
||||
|
||||
def test_unopenable_common_prefs_does_not_use_legacy_password(self):
|
||||
self.run_scenario(8)
|
||||
|
||||
def test_operator_instructions_name_the_admin_password(self):
|
||||
# Extra guard only: the instructions must not present the published
|
||||
# fallback as the bridge's normal Wi-Fi password.
|
||||
|
||||
@@ -120,6 +120,18 @@ static void guestChurnCannotLockOutNewIdentities() {
|
||||
CHECK(!login(room, guest, "published", 1000 + i));
|
||||
CHECK(login(room, guest, "published", 2000 + i));
|
||||
}
|
||||
// A guest without a durable record loses its exact live floor on eviction.
|
||||
// Re-admission starts another transient writer session, whose immediate
|
||||
// replay is rejected without allocating a permanent replay-store slot.
|
||||
const auto evicted_guest = member(0, 0x6E);
|
||||
CHECK(!room.acl.getClient(evicted_guest.pub_key, PUB_KEY_SIZE));
|
||||
CHECK(storedIdentities(fs) == 0);
|
||||
CHECK(login(room, evicted_guest, "published", 1000));
|
||||
const auto* readmitted = room.acl.getClient(evicted_guest.pub_key, PUB_KEY_SIZE);
|
||||
CHECK(readmitted && readmitted->permissions == PERM_ACL_READ_WRITE
|
||||
&& !readmitted->permissions_are_explicit);
|
||||
CHECK(!login(room, evicted_guest, "published", 1000));
|
||||
CHECK(storedIdentities(fs) == 0);
|
||||
// A new Admin device and an assigned writer's first login are still admitted.
|
||||
CHECK(login(room, admin, "admin-secret", 3000));
|
||||
CHECK(login(room, writer, "", 3000));
|
||||
|
||||
Reference in new issue
Block a user