|
| 1 | +/** |
| 2 | +Open Bank Project - API |
| 3 | +Copyright (C) 2011-2019, TESOBE GmbH. |
| 4 | +
|
| 5 | +This program is free software: you can redistribute it and/or modify |
| 6 | +it under the terms of the GNU Affero General Public License as published by |
| 7 | +the Free Software Foundation, either version 3 of the License, or |
| 8 | +(at your option) any later version. |
| 9 | +
|
| 10 | +This program is distributed in the hope that it will be useful, |
| 11 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +GNU Affero General Public License for more details. |
| 14 | +
|
| 15 | +You should have received a copy of the GNU Affero General Public License |
| 16 | +along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | +
|
| 18 | +Email: contact@tesobe.com |
| 19 | +TESOBE GmbH. |
| 20 | +Osloer Strasse 16/17 |
| 21 | +Berlin 13359, Germany |
| 22 | +
|
| 23 | +This product includes software developed at |
| 24 | +TESOBE (http://www.tesobe.com/) |
| 25 | + */ |
| 26 | + |
| 27 | +package code.api.util |
| 28 | + |
| 29 | +import code.util.Helper.MdcLoggable |
| 30 | +import org.scalatest.{FeatureSpec, GivenWhenThen, Matchers} |
| 31 | + |
| 32 | +class PasswordUtilTest extends FeatureSpec with Matchers with GivenWhenThen with MdcLoggable { |
| 33 | + |
| 34 | + feature("Evaluate password strength using Zxcvbn") { |
| 35 | + |
| 36 | + scenario("Very weak password should return low score and be unacceptable") { |
| 37 | + Given("a common password '12345678'") |
| 38 | + val password = "12345678" |
| 39 | + |
| 40 | + When("measured with zxcvbn") |
| 41 | + val strength = PasswordUtil.getStrength(password) |
| 42 | + |
| 43 | + Then("the score should be 0 and it should be unacceptable") |
| 44 | + strength.getScore should be <= 1 |
| 45 | + PasswordUtil.isAcceptable(password) should be (false) |
| 46 | + } |
| 47 | + |
| 48 | + scenario("Moderate password should be acceptable") { |
| 49 | + Given("a moderately strong password 'OpenBank2025$'") |
| 50 | + val password = "OpenBank2025$" |
| 51 | + |
| 52 | + When("measured with zxcvbn") |
| 53 | + val strength = PasswordUtil.getStrength(password) |
| 54 | + |
| 55 | + Then("the score should be >= 3 and it should be acceptable") |
| 56 | + strength.getScore should be >= 3 |
| 57 | + PasswordUtil.isAcceptable(password) should be (true) |
| 58 | + } |
| 59 | + |
| 60 | + scenario("Strong password with emoji and unicode should be acceptable") { |
| 61 | + Given("a complex password '🔥MySecurę密码2025!'") |
| 62 | + val password = "🔥MySecurę密码2025!" |
| 63 | + |
| 64 | + When("measured with zxcvbn") |
| 65 | + val strength = PasswordUtil.getStrength(password) |
| 66 | + |
| 67 | + Then("the score should be >= 3 and it should be acceptable") |
| 68 | + strength.getScore should be >= 3 |
| 69 | + PasswordUtil.isAcceptable(password) should be (true) |
| 70 | + } |
| 71 | + |
| 72 | + scenario("Very strong password should be clearly acceptable") { |
| 73 | + Given("a very strong password 'G@lacticSafe#AlphaZebra99!!'") |
| 74 | + val password = "G@lacticSafe#AlphaZebra99!!" |
| 75 | + |
| 76 | + When("measured with zxcvbn") |
| 77 | + val strength = PasswordUtil.getStrength(password) |
| 78 | + |
| 79 | + Then("the score should be 4 and it should be acceptable") |
| 80 | + strength.getScore should be (4) |
| 81 | + PasswordUtil.isAcceptable(password) should be (true) |
| 82 | + } |
| 83 | + |
| 84 | + } |
| 85 | +} |
0 commit comments