fix: keep stored secrets when an older UI sends them empty

Firmware and UI files update separately, so an old index.js can run
against firmware that no longer returns secrets. It sends "" for the
field it can't fill in, which cleared the WiFi passphrase (reboot into
AP mode) or the MQTT password.

The firmware now decides: "" keeps the stored secret, unless the same
request changes the SSID or MQTT username, then it clears it (open
network). /setNetwork compares the settings after applying them, so a
kept passphrase no longer triggers a reboot. The UI cache-buster moves
to 3.0.14d.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cjkas 2026-10-18 20:07:31 +02:00
parent 1fb4c4cfcd
commit 9383ebec2e
6 changed files with 77 additions and 34 deletions

View file

@ -44,12 +44,33 @@ static void test_applySecret_prefix_of_stored_is_a_change() {
TEST_ASSERT_TRUE(applySecret("sto", dest, sizeof(dest)));
TEST_ASSERT_EQUAL_STRING("sto", dest);
}
// Sending an empty value explicitly clears it, e.g. an open WiFi network.
static void test_applySecret_empty_value_clears_stored() {
// An older UI sends "" for a field the device no longer fills in.
static void test_applySecret_empty_value_keeps_stored() {
char dest[16] = "stored";
TEST_ASSERT_TRUE(applySecret("", dest, sizeof(dest)));
TEST_ASSERT_FALSE(applySecret("", dest, sizeof(dest)));
TEST_ASSERT_EQUAL_STRING("stored", dest);
}
// A new SSID or username with an empty secret, e.g. an open WiFi network.
static void test_applySecret_empty_value_with_new_identity_clears_stored() {
char dest[16] = "stored";
TEST_ASSERT_TRUE(applySecret("", dest, sizeof(dest), true));
TEST_ASSERT_EQUAL_STRING("", dest);
}
static void test_applySecret_empty_value_with_new_identity_and_nothing_stored() {
char dest[16] = "";
TEST_ASSERT_FALSE(applySecret("", dest, sizeof(dest), true));
TEST_ASSERT_EQUAL_STRING("", dest);
}
static void test_applySecret_new_identity_still_takes_a_value() {
char dest[16] = "stored";
TEST_ASSERT_TRUE(applySecret("fresh", dest, sizeof(dest), true));
TEST_ASSERT_EQUAL_STRING("fresh", dest);
}
static void test_applySecret_absent_keeps_stored_even_with_new_identity() {
char dest[16] = "stored";
TEST_ASSERT_FALSE(applySecret(nullptr, dest, sizeof(dest), true));
TEST_ASSERT_EQUAL_STRING("stored", dest);
}
static void test_applySecret_truncates_and_terminates() {
char storage[8];
memset(storage, 'X', sizeof(storage));
@ -74,7 +95,11 @@ int main(int argc, char **argv) {
RUN_TEST(test_applySecret_new_value_replaces_stored);
RUN_TEST(test_applySecret_same_value_is_no_change);
RUN_TEST(test_applySecret_prefix_of_stored_is_a_change);
RUN_TEST(test_applySecret_empty_value_clears_stored);
RUN_TEST(test_applySecret_empty_value_keeps_stored);
RUN_TEST(test_applySecret_empty_value_with_new_identity_clears_stored);
RUN_TEST(test_applySecret_empty_value_with_new_identity_and_nothing_stored);
RUN_TEST(test_applySecret_new_identity_still_takes_a_value);
RUN_TEST(test_applySecret_absent_keeps_stored_even_with_new_identity);
RUN_TEST(test_applySecret_truncates_and_terminates);
RUN_TEST(test_applySecret_truncated_same_value_is_no_change);
return UNITY_END();