mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-21 18:22:37 +10:00
test: cover custom parameter portal regressions
This commit is contained in:
@@ -13,6 +13,49 @@ constexpr char kPortalPassword[] = "default1";
|
||||
WiFiManager wifi;
|
||||
WiFiManagerParameter kInstallationLabel(
|
||||
"installation_label", "Installation label", "Contract fixture", 32);
|
||||
// Keep the characters from upstream issue #1863 in the portal fixture. The
|
||||
// browser contract verifies this value through JSON, DOM rendering, save, and
|
||||
// a subsequent reload rather than relying on a string-only serializer check.
|
||||
WiFiManagerParameter kEscapedValue(
|
||||
"escaped_value", "Escaped value", "7(f+4]2y3fsYTQt'Uhxc\"d\\<>&", 64);
|
||||
WiFiManagerParameter kMqttHost(
|
||||
"mqtt_host", "MQTT host", "broker.example.local", 64);
|
||||
WiFiManagerParameter kMqttPort(
|
||||
"mqtt_port", "MQTT port", "1883", 8);
|
||||
WiFiManagerParameter kDeviceRoom(
|
||||
"device_room", "Device room", "Workshop", 32);
|
||||
WiFiManagerParameter kSensorName(
|
||||
"sensor_name", "Sensor name", "Ambient temperature", 48);
|
||||
WiFiManagerParameter kTelemetryTopic(
|
||||
"telemetry_topic", "Telemetry topic", "sensors/ambient/temperature", 64);
|
||||
WiFiManagerParameter kTimezone(
|
||||
"timezone", "Timezone", "Australia/Brisbane", 48);
|
||||
WiFiManagerParameter kLatitude(
|
||||
"latitude", "Latitude", "-27.4698", 16);
|
||||
WiFiManagerParameter kLongitude(
|
||||
"longitude", "Longitude", "153.0251", 16);
|
||||
WiFiManagerParameter kFirmwareChannel(
|
||||
"firmware_channel", "Firmware channel", "stable", 16);
|
||||
WiFiManagerParameter kOwnerName(
|
||||
"owner_name", "Owner name", "Portal contract", 48);
|
||||
WiFiManagerParameter kNotes(
|
||||
"notes", "Notes", "Thirteen-field rendering fixture", 64);
|
||||
|
||||
WiFiManagerParameter* const kPortalParameters[] = {
|
||||
&kInstallationLabel,
|
||||
&kEscapedValue,
|
||||
&kMqttHost,
|
||||
&kMqttPort,
|
||||
&kDeviceRoom,
|
||||
&kSensorName,
|
||||
&kTelemetryTopic,
|
||||
&kTimezone,
|
||||
&kLatitude,
|
||||
&kLongitude,
|
||||
&kFirmwareChannel,
|
||||
&kOwnerName,
|
||||
&kNotes,
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -32,7 +75,13 @@ void setup() {
|
||||
IPAddress(192, 168, 4, 1),
|
||||
IPAddress(192, 168, 4, 1),
|
||||
IPAddress(255, 255, 255, 0));
|
||||
wifi.portalAddParameter(&kInstallationLabel);
|
||||
// Keep custom parameters on their own native Save parameters page. This
|
||||
// lets the browser contract exercise a parameter-only submit without
|
||||
// starting a station connection as part of the regression test.
|
||||
wifi.portalSetLayoutParamsLocation(PortalParamsLocation::SetupPage);
|
||||
for (auto* parameter : kPortalParameters) {
|
||||
wifi.portalAddParameter(parameter);
|
||||
}
|
||||
wifi.startConfigPortal(kPortalSsid, kPortalPassword);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ TestCase tests[] = {
|
||||
TEST_ENTRY(test_profile_portal_candidate_does_not_take_legacy_empty_ssid_path),
|
||||
TEST_ENTRY(test_api_info_json_shape),
|
||||
TEST_ENTRY(test_api_params_json_shape),
|
||||
TEST_ENTRY(test_api_params_json_escapes_custom_parameter_value),
|
||||
TEST_ENTRY(test_api_status_json_shape),
|
||||
|
||||
// Configuration tests
|
||||
|
||||
@@ -123,6 +123,7 @@ void test_profile_portal_success_keeps_handoff_alive();
|
||||
void test_profile_portal_candidate_does_not_take_legacy_empty_ssid_path();
|
||||
void test_api_info_json_shape();
|
||||
void test_api_params_json_shape();
|
||||
void test_api_params_json_escapes_custom_parameter_value();
|
||||
void test_api_status_json_shape();
|
||||
|
||||
// State transition tests
|
||||
|
||||
@@ -167,6 +167,24 @@ void test_api_params_json_shape() {
|
||||
Serial.println("[TEST] API params JSON shape test completed successfully");
|
||||
}
|
||||
|
||||
void test_api_params_json_escapes_custom_parameter_value() {
|
||||
Serial.println("[TEST] Testing escaped custom parameter JSON value...");
|
||||
|
||||
constexpr char value[] = "7(f+4]2y3fsYTQt'Uhxc\"d\\<>&";
|
||||
WiFiManager wm;
|
||||
WiFiManagerHandlers handlers(&wm);
|
||||
WiFiManagerParameter field("escaped_value", "Escaped value", value,
|
||||
static_cast<int>(sizeof(value) - 1));
|
||||
wm.portalAddParameter(&field);
|
||||
|
||||
const String json = handlers.buildApiParamsGetJson();
|
||||
// JSON must retain apostrophes, angle brackets and ampersands as data,
|
||||
// while escaping the quote and backslash that delimit a JSON string.
|
||||
TEST_ASSERT_NOT_NULL(strstr(json.c_str(), "7(f+4]2y3fsYTQt'Uhxc\\\"d\\\\<>&"));
|
||||
|
||||
Serial.println("[TEST] Escaped custom parameter JSON value test completed successfully");
|
||||
}
|
||||
|
||||
void test_api_status_json_shape() {
|
||||
Serial.println("[TEST] Testing /api/status JSON shape...");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user