From ec96e03f66bb650d131b33dd9db31868a726ffe9 Mon Sep 17 00:00:00 2001 From: JoAnna578 Date: Mon, 13 Oct 2025 15:46:54 +0200 Subject: [PATCH 1/5] =?UTF-8?q?QA:=20Sprawdzenie=20poprawno=C5=9Bci=20has?= =?UTF-8?q?=C5=82a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Funkcja checkPassword weryfikuje, czy hasło jest poprawne według zasad: długość 8–16 znaków, zawiera co najmniej jedną cyfrę, wielką literę i znak specjalny, oraz nie używa liter spoza alfabetu łacińskiego. Testy sprawdzają zarówno poprawne, jak i błędne hasła, w tym przypadki graniczne. --- src/checkPassword.test.js | 51 +++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/src/checkPassword.test.js b/src/checkPassword.test.js index 1e77e16..3e17e9e 100644 --- a/src/checkPassword.test.js +++ b/src/checkPassword.test.js @@ -1,19 +1,60 @@ 'use strict'; -describe(`Function 'checkPassword':`, () => { - const checkPassword = require('./checkPassword'); +const checkPassword = require('./checkPassword'); +describe(`Function 'checkPassword':`, () => { it(`should be declared`, () => { expect(checkPassword).toBeInstanceOf(Function); }); - it(`should return boolean`, () => { + it(`should return a boolean`, () => { + const result = checkPassword('Password1!'); + expect(typeof result).toBe('boolean'); + }); + + it(`should return true for valid password with 8 characters`, () => { + const result = checkPassword('Abcdef1!'); + expect(result).toBe(true); + }); + + it(`should return true for valid password with 16 characters`, () => { + const result = checkPassword('Abcdefgh1234!XYZ'); + expect(result).toBe(true); + }); + + it(`should return false for password shorter than 8 characters`, () => { + const result = checkPassword('Ab1!'); + expect(result).toBe(false); + }); + + it(`should return false for password longer than 16 characters`, () => { + const result = checkPassword('Abcdefghijklmnop1!'); + expect(result).toBe(false); + }); + + it(`should return false for password without uppercase letter`, () => { + const result = checkPassword('abcdef1!'); + expect(result).toBe(false); + }); + it(`should return false for password without digit`, () => { + const result = checkPassword('Abcdefgh!'); + expect(result).toBe(false); }); - it(`should return 'true' for the valid password with 8 characters`, () => { + it(`should return false for password without special character`, () => { + const result = checkPassword('Abcdefg1'); + expect(result).toBe(false); + }); + it(`should return false for password with non-Latin characters`, () => { + const result = checkPassword('Пароль1!'); + expect(result).toBe(false); }); - // write more tests here + it(`should return true for password with mix of allowed symbols`, () => { + const result = checkPassword('XyZ123@#'); + expect(result).toBe(true); + }); }); + From f34aa28fdac3e532b0477eea0dd7f693b282f173 Mon Sep 17 00:00:00 2001 From: JoAnna578 Date: Mon, 13 Oct 2025 15:53:42 +0200 Subject: [PATCH 2/5] =?UTF-8?q?QA:=20Walidacja=20has=C5=82a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/checkPassword.test.js | 68 +++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/src/checkPassword.test.js b/src/checkPassword.test.js index 3e17e9e..ec0814a 100644 --- a/src/checkPassword.test.js +++ b/src/checkPassword.test.js @@ -12,49 +12,63 @@ describe(`Function 'checkPassword':`, () => { expect(typeof result).toBe('boolean'); }); - it(`should return true for valid password with 8 characters`, () => { - const result = checkPassword('Abcdef1!'); - expect(result).toBe(true); + // README examples + it(`should return true for checkPassword('Password1!')`, () => { + expect(checkPassword('Password1!')).toBe(true); }); - it(`should return true for valid password with 16 characters`, () => { - const result = checkPassword('Abcdefgh1234!XYZ'); - expect(result).toBe(true); + it(`should return false for checkPassword('qwerty')`, () => { + expect(checkPassword('qwerty')).toBe(false); }); - it(`should return false for password shorter than 8 characters`, () => { - const result = checkPassword('Ab1!'); - expect(result).toBe(false); + it(`should return false for checkPassword('Str@ng')`, () => { + expect(checkPassword('Str@ng')).toBe(false); }); - it(`should return false for password longer than 16 characters`, () => { - const result = checkPassword('Abcdefghijklmnop1!'); - expect(result).toBe(false); + // Length boundaries + it(`should return false for 7-character password`, () => { + expect(checkPassword('Abcde1!')).toBe(false); }); - it(`should return false for password without uppercase letter`, () => { - const result = checkPassword('abcdef1!'); - expect(result).toBe(false); + it(`should return true for 8-character valid password`, () => { + expect(checkPassword('Abcdef1!')).toBe(true); + }); + + it(`should return true for 16-character valid password`, () => { + expect(checkPassword('Abcdefgh1234!XYZ')).toBe(true); + }); + + it(`should return false for 17-character password`, () => { + expect(checkPassword('Abcdefghijklmnop1!')).toBe(false); + }); + + // Character class coverage + it(`should return false for password without uppercase`, () => { + expect(checkPassword('abcdef1!')).toBe(false); }); it(`should return false for password without digit`, () => { - const result = checkPassword('Abcdefgh!'); - expect(result).toBe(false); + expect(checkPassword('Abcdefgh!')).toBe(false); }); - it(`should return false for password without special character`, () => { - const result = checkPassword('Abcdefg1'); - expect(result).toBe(false); + it(`should return false for password without special char`, () => { + expect(checkPassword('Abcdefg1')).toBe(false); }); - it(`should return false for password with non-Latin characters`, () => { - const result = checkPassword('Пароль1!'); - expect(result).toBe(false); + it(`should return true for uppercase-only valid password`, () => { + expect(checkPassword('ABCDEF12!')).toBe(true); }); - it(`should return true for password with mix of allowed symbols`, () => { - const result = checkPassword('XyZ123@#'); - expect(result).toBe(true); + it(`should return false for password with Cyrillic letters`, () => { + expect(checkPassword('Пароль1!')).toBe(false); + }); + + it(`should return false for password with accented Latin letters`, () => { + expect(checkPassword('Pässword1!')).toBe(false); }); -}); + // Whitespace check + it(`should return false for password containing whitespace`, () => { + expect(checkPassword('Abc def1!')).toBe(false); + }); +}); From 39f96a5ebf1c55f81a60718e0228d7866298673f Mon Sep 17 00:00:00 2001 From: JoAnna578 Date: Mon, 13 Oct 2025 15:56:36 +0200 Subject: [PATCH 3/5] =?UTF-8?q?QA:=20Walidacja=20has=C5=82a=20=E2=80=93=20?= =?UTF-8?q?poprawne=20ASCII=20i=20wymagania=20znakowe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/checkPassword.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/checkPassword.js b/src/checkPassword.js index 1a6fc05..7f54b46 100644 --- a/src/checkPassword.js +++ b/src/checkPassword.js @@ -6,12 +6,19 @@ * @returns {boolean} */ function checkPassword(password) { - // eslint-disable-next-line - const validPasswordRegex = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,16}$/; - const cyrillicValidation = /^((?![А-Яа-я]).)*$/; + // regex sprawdzający: + // - co najmniej 1 wielką literę + // - co najmniej 1 cyfrę + // - co najmniej 1 znak specjalny + // - brak spacji + // - długość 8-16 + const validPasswordRegex = + /^(?=.*\d)(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,16}$/; - // eslint-disable-next-line - if (password.match(validPasswordRegex) && password.match(cyrillicValidation)) { + // regex sprawdzający tylko znaki ASCII + const asciiValidation = /^[\x20-\x7E]*$/; + + if (password.match(validPasswordRegex) && password.match(asciiValidation)) { return true; } @@ -19,3 +26,4 @@ function checkPassword(password) { } module.exports = checkPassword; + From 79f0b09d9f7909235e0c08755b97ec8033cb04a5 Mon Sep 17 00:00:00 2001 From: JoAnna578 Date: Mon, 13 Oct 2025 16:05:43 +0200 Subject: [PATCH 4/5] =?UTF-8?q?QA:=20Walidacja=20has=C5=82a=20=E2=80=93=20?= =?UTF-8?q?ASCII,=20d=C5=82ugo=C5=9B=C4=87=20i=20klasy=20znak=C3=B3w?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/checkPassword.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/checkPassword.js b/src/checkPassword.js index 7f54b46..d167503 100644 --- a/src/checkPassword.js +++ b/src/checkPassword.js @@ -6,6 +6,8 @@ * @returns {boolean} */ function checkPassword(password) { + if (typeof password !== 'string') return false; + // regex sprawdzający: // - co najmniej 1 wielką literę // - co najmniej 1 cyfrę @@ -15,10 +17,10 @@ function checkPassword(password) { const validPasswordRegex = /^(?=.*\d)(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,16}$/; - // regex sprawdzający tylko znaki ASCII - const asciiValidation = /^[\x20-\x7E]*$/; + // regex sprawdzający tylko znaki ASCII od ! do ~ (bez spacji) + const asciiValidation = /^[\x21-\x7E]*$/; - if (password.match(validPasswordRegex) && password.match(asciiValidation)) { + if (validPasswordRegex.test(password) && asciiValidation.test(password)) { return true; } @@ -27,3 +29,4 @@ function checkPassword(password) { module.exports = checkPassword; + From 05670aaddb258d51197a0437a5d0c053d93030bd Mon Sep 17 00:00:00 2001 From: JoAnna578 Date: Mon, 13 Oct 2025 16:06:28 +0200 Subject: [PATCH 5/5] =?UTF-8?q?QA:=20Walidacja=20has=C5=82a=20=E2=80=93=20?= =?UTF-8?q?ASCII,=20d=C5=82ugo=C5=9B=C4=87=20i=20klasy=20znak=C3=B3w=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/checkPassword.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/checkPassword.test.js b/src/checkPassword.test.js index ec0814a..8d4e112 100644 --- a/src/checkPassword.test.js +++ b/src/checkPassword.test.js @@ -39,7 +39,8 @@ describe(`Function 'checkPassword':`, () => { }); it(`should return false for 17-character password`, () => { - expect(checkPassword('Abcdefghijklmnop1!')).toBe(false); + // 15 liter + 1 cyfra + 1 znak specjalny = 17 znaków + expect(checkPassword('Abcdefghijklmno1!')).toBe(false); }); // Character class coverage