From 048e68618546c5bf2d4bdd17d9029d92d4e6e7ca Mon Sep 17 00:00:00 2001 From: Gabriel GRONDIN Date: Wed, 19 Jan 2022 14:29:48 +0100 Subject: [PATCH 1/2] Fix WiFi password max length check The WiFi password cannot be longer than 63 symbols. --- src/common/WiFiSettings/WiFiSettings.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/common/WiFiSettings/WiFiSettings.js b/src/common/WiFiSettings/WiFiSettings.js index 00388d2..d97ba7a 100644 --- a/src/common/WiFiSettings/WiFiSettings.js +++ b/src/common/WiFiSettings/WiFiSettings.js @@ -82,6 +82,10 @@ export function validator(formData) { if (device.password.length < 8) errors.password = _("Password must contain at least 8 symbols"); + if (device.password.length >= 64) + errors.password = _( + "Password must not contain more than 63 symbols" + ); if (!device.guest_wifi.enabled) return errors; @@ -97,6 +101,10 @@ export function validator(formData) { guest_wifi_errors.password = _( "Password must contain at least 8 symbols" ); + if (device.guest_wifi.password.length >= 64) + guest_wifi_errors.password = _( + "Password must not contain more than 63 symbols" + ); if (guest_wifi_errors.SSID || guest_wifi_errors.password) { errors.guest_wifi = guest_wifi_errors; From b6e2cb71bbc235496fd3c050d79b3e59232aa0fb Mon Sep 17 00:00:00 2001 From: Aleksandr Gumroian Date: Thu, 20 Jan 2022 00:47:00 +0300 Subject: [PATCH 2/2] Add tests for password length validation --- .../__tests__/WiFiSettings.test.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/common/WiFiSettings/__tests__/WiFiSettings.test.js b/src/common/WiFiSettings/__tests__/WiFiSettings.test.js index 53c32ee..72d99ae 100644 --- a/src/common/WiFiSettings/__tests__/WiFiSettings.test.js +++ b/src/common/WiFiSettings/__tests__/WiFiSettings.test.js @@ -26,6 +26,7 @@ describe("", () => { let getAllByText; let getAllByLabelText; let getByText; + let getByLabelText; let asFragment; const endpoint = "/reforis/api/wifi"; @@ -41,6 +42,7 @@ describe("", () => { asFragment = renderRes.asFragment; getAllByText = renderRes.getAllByText; getAllByLabelText = renderRes.getAllByLabelText; + getByLabelText = renderRes.getByLabelText; getByText = renderRes.getByText; mockAxios.mockResponse({ data: wifiSettingsFixture() }); await wait(() => renderRes.getByText("Wi-Fi 1")); @@ -51,7 +53,6 @@ describe("", () => { const webSockets = new WebSockets(); const { getByText } = render( ", () => { it("ByteCount function", () => { expect(byteCount("abc")).toEqual(3); }); + + it("Should validate password length", () => { + const shortErrorFeedback = /Password must contain/i; + const longErrorFeedback = /Password must not contain/i; + + fireEvent.click(getByText("Wi-Fi 1")); + + const passwordInput = getByLabelText("Password"); + + const changePassword = (value) => + fireEvent.change(passwordInput, { target: { value } }); + + changePassword("12"); + expect(getByText(shortErrorFeedback)).toBeDefined(); + + changePassword( + "longpasswordlongpasswordlongpasswordlongpasswordlongpasswordlong" + ); + expect(getByText(longErrorFeedback)).toBeDefined(); + }); });