feat: GET system/settings zeigt Herkunft der WLAN-Zugangsdaten
Die Antwort gab bisher nur die gespeicherte SSID aus. Wurde eine Lampe nie per REST onboardet, ist die leer, und die Lampe laeuft in Wirklichkeit auf den einkompilierten NINLIGHT_WIFI_SSID/-PASSWORD (siehe app_main.c) - GET system/settings suggerierte damit "kein WLAN konfiguriert", obwohl die Lampe zuverlaessig verbunden ist, und widersprach scheinbar system/info. Additiv, ohne die Bedeutung von "ssid" zu aendern: wifi.source ist jetzt "stored" oder "compiled". Spec (§7.2) und bruno/ninlight.yml dokumentieren das Feld, ein neuer Hosttest deckt den compiled-Fall ab. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
d464bb167e
commit
2dfb1fd1c2
@@ -225,6 +225,11 @@ items:
|
|||||||
timeout: 0
|
timeout: 0
|
||||||
followRedirects: true
|
followRedirects: true
|
||||||
maxRedirects: 5
|
maxRedirects: 5
|
||||||
|
docs: |-
|
||||||
|
`wifi.source` ist `"stored"`, solange ein per PUT onboardetes WLAN gespeichert ist,
|
||||||
|
sonst `"compiled"` - dann laeuft die Lampe auf den einkompilierten
|
||||||
|
NINLIGHT_WIFI_SSID/-PASSWORD, `wifi.ssid` ist leer, und `GET system/info` kann trotzdem
|
||||||
|
eine verbundene SSID zeigen.
|
||||||
- info:
|
- info:
|
||||||
name: Set WiFi
|
name: Set WiFi
|
||||||
type: http
|
type: http
|
||||||
|
|||||||
@@ -262,6 +262,13 @@ static void handle_get_settings(const nl_api_ctx_t *ctx, nl_api_response_t *resp
|
|||||||
cJSON_AddStringToObject(o, "name", s.name);
|
cJSON_AddStringToObject(o, "name", s.name);
|
||||||
w = cJSON_AddObjectToObject(o, "wifi");
|
w = cJSON_AddObjectToObject(o, "wifi");
|
||||||
cJSON_AddStringToObject(w, "ssid", s.wifi_ssid);
|
cJSON_AddStringToObject(w, "ssid", s.wifi_ssid);
|
||||||
|
/* "ssid" alone can't be told apart from "kein WLAN konfiguriert": ein leerer
|
||||||
|
* gespeicherter Datensatz laesst app_main.c beim Boot auf die einkompilierten
|
||||||
|
* NINLIGHT_WIFI_SSID/-PASSWORD zurueckfallen (siehe dort), und die Lampe kommt
|
||||||
|
* trotzdem zuverlaessig ins WLAN. Wer nur "ssid" sieht, kann das nicht
|
||||||
|
* unterscheiden - "source" macht additiv sichtbar, woher die Zugangsdaten
|
||||||
|
* kommen, ohne die Bedeutung von "ssid" zu aendern. */
|
||||||
|
cJSON_AddStringToObject(w, "source", s.wifi_ssid[0] ? "stored" : "compiled");
|
||||||
cJSON_AddBoolToObject(o, "auth_all", s.auth_all != 0);
|
cJSON_AddBoolToObject(o, "auth_all", s.auth_all != 0);
|
||||||
reply_json(resp, 200, o);
|
reply_json(resp, 200, o);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,6 +233,7 @@ static void test_settings_auth(void)
|
|||||||
TEST_ASSERT_EQUAL_INT(200, resp.status);
|
TEST_ASSERT_EQUAL_INT(200, resp.status);
|
||||||
TEST_ASSERT_EQUAL_STRING("Wohnzimmer", cJSON_GetStringValue(field("name")));
|
TEST_ASSERT_EQUAL_STRING("Wohnzimmer", cJSON_GetStringValue(field("name")));
|
||||||
TEST_ASSERT_EQUAL_STRING("ninHome", cJSON_GetStringValue(cJSON_GetObjectItem(field("wifi"), "ssid")));
|
TEST_ASSERT_EQUAL_STRING("ninHome", cJSON_GetStringValue(cJSON_GetObjectItem(field("wifi"), "ssid")));
|
||||||
|
TEST_ASSERT_EQUAL_STRING("stored", cJSON_GetStringValue(cJSON_GetObjectItem(field("wifi"), "source")));
|
||||||
TEST_ASSERT_TRUE(cJSON_IsFalse(field("auth_all")));
|
TEST_ASSERT_TRUE(cJSON_IsFalse(field("auth_all")));
|
||||||
TEST_ASSERT_NULL(cJSON_GetObjectItem(field("wifi"), "password")); /* never exposed */
|
TEST_ASSERT_NULL(cJSON_GetObjectItem(field("wifi"), "password")); /* never exposed */
|
||||||
fake_open = true;
|
fake_open = true;
|
||||||
@@ -240,6 +241,19 @@ static void test_settings_auth(void)
|
|||||||
TEST_ASSERT_EQUAL_INT(200, resp.status);
|
TEST_ASSERT_EQUAL_INT(200, resp.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* F1: nie onboardet -> gespeicherte ssid ist leer, die Lampe laeuft auf den
|
||||||
|
* einkompilierten Zugangsdaten (siehe app_main.c). "source" muss das additiv
|
||||||
|
* sichtbar machen, ohne "ssid" umzudeuten - sonst widerspricht die Antwort
|
||||||
|
* scheinbar system/info, das die tatsaechlich verbundene SSID zeigt. */
|
||||||
|
static void test_settings_wifi_source_reflects_compiled_fallback(void)
|
||||||
|
{
|
||||||
|
fake_settings.wifi_ssid[0] = '\0';
|
||||||
|
call(NL_HTTP_GET, "/api/v1/system/settings", TOKEN, NULL);
|
||||||
|
TEST_ASSERT_EQUAL_INT(200, resp.status);
|
||||||
|
TEST_ASSERT_EQUAL_STRING("", cJSON_GetStringValue(cJSON_GetObjectItem(field("wifi"), "ssid")));
|
||||||
|
TEST_ASSERT_EQUAL_STRING("compiled", cJSON_GetStringValue(cJSON_GetObjectItem(field("wifi"), "source")));
|
||||||
|
}
|
||||||
|
|
||||||
static void test_settings_wifi(void)
|
static void test_settings_wifi(void)
|
||||||
{
|
{
|
||||||
call(NL_HTTP_PUT, "/api/v1/system/settings", TOKEN, "{\"type\":\"wifi\",\"ssid\":\"ninIOT\",\"password\":\"secret12\"}");
|
call(NL_HTTP_PUT, "/api/v1/system/settings", TOKEN, "{\"type\":\"wifi\",\"ssid\":\"ninIOT\",\"password\":\"secret12\"}");
|
||||||
@@ -356,6 +370,7 @@ int main(void)
|
|||||||
RUN_TEST(test_info_is_open);
|
RUN_TEST(test_info_is_open);
|
||||||
RUN_TEST(test_info_with_sta_ip_and_error);
|
RUN_TEST(test_info_with_sta_ip_and_error);
|
||||||
RUN_TEST(test_settings_auth);
|
RUN_TEST(test_settings_auth);
|
||||||
|
RUN_TEST(test_settings_wifi_source_reflects_compiled_fallback);
|
||||||
RUN_TEST(test_settings_wifi);
|
RUN_TEST(test_settings_wifi);
|
||||||
RUN_TEST(test_settings_name_token_auth);
|
RUN_TEST(test_settings_name_token_auth);
|
||||||
RUN_TEST(test_commands);
|
RUN_TEST(test_commands);
|
||||||
|
|||||||
Reference in New Issue
Block a user