1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-11-14 17:35:35 +01:00

Merge branch 'fix-wifi-password-maxlength' into 'dev'

Fix WiFi password max length check

Closes #25

See merge request turris/reforis/foris-js!178
This commit is contained in:
Aleksandr Gumroian 2022-01-20 10:11:12 +01:00
commit dd383ef1b2
2 changed files with 30 additions and 1 deletions

View File

@ -82,6 +82,10 @@ export function validator(formData) {
if (device.password.length < 8) if (device.password.length < 8)
errors.password = _("Password must contain at least 8 symbols"); 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; if (!device.guest_wifi.enabled) return errors;
@ -97,6 +101,10 @@ export function validator(formData) {
guest_wifi_errors.password = _( guest_wifi_errors.password = _(
"Password must contain at least 8 symbols" "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) { if (guest_wifi_errors.SSID || guest_wifi_errors.password) {
errors.guest_wifi = guest_wifi_errors; errors.guest_wifi = guest_wifi_errors;

View File

@ -26,6 +26,7 @@ describe("<WiFiSettings/>", () => {
let getAllByText; let getAllByText;
let getAllByLabelText; let getAllByLabelText;
let getByText; let getByText;
let getByLabelText;
let asFragment; let asFragment;
const endpoint = "/reforis/api/wifi"; const endpoint = "/reforis/api/wifi";
@ -41,6 +42,7 @@ describe("<WiFiSettings/>", () => {
asFragment = renderRes.asFragment; asFragment = renderRes.asFragment;
getAllByText = renderRes.getAllByText; getAllByText = renderRes.getAllByText;
getAllByLabelText = renderRes.getAllByLabelText; getAllByLabelText = renderRes.getAllByLabelText;
getByLabelText = renderRes.getByLabelText;
getByText = renderRes.getByText; getByText = renderRes.getByText;
mockAxios.mockResponse({ data: wifiSettingsFixture() }); mockAxios.mockResponse({ data: wifiSettingsFixture() });
await wait(() => renderRes.getByText("Wi-Fi 1")); await wait(() => renderRes.getByText("Wi-Fi 1"));
@ -51,7 +53,6 @@ describe("<WiFiSettings/>", () => {
const webSockets = new WebSockets(); const webSockets = new WebSockets();
const { getByText } = render( const { getByText } = render(
<WiFiSettings <WiFiSettings
ws={webSockets}
ws={webSockets} ws={webSockets}
endpoint={endpoint} endpoint={endpoint}
resetEndpoint="foo" resetEndpoint="foo"
@ -220,4 +221,24 @@ describe("<WiFiSettings/>", () => {
it("ByteCount function", () => { it("ByteCount function", () => {
expect(byteCount("abc")).toEqual(3); 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();
});
}); });