public JavaPortTest(String password) { this.password = password; zxcvbn = new Zxcvbn(); }
public static int judgePasswordStrengthUsingZxcvbnAlgorithm( final Configuration configuration, final String password ) { final Zxcvbn zxcvbn = new Zxcvbn(); final Strength strength = zxcvbn.measure( password ); final int zxcvbnScore = strength.getScore(); // zxcvbn returns a score of 0-4 (see: https://github.com/dropbox/zxcvbn) switch ( zxcvbnScore ) { case 4: return Integer.parseInt( configuration.readAppProperty( AppProperty.PASSWORD_STRENGTH_THRESHOLD_VERY_STRONG ) ); case 3: return Integer.parseInt( configuration.readAppProperty( AppProperty.PASSWORD_STRENGTH_THRESHOLD_STRONG ) ); case 2: return Integer.parseInt( configuration.readAppProperty( AppProperty.PASSWORD_STRENGTH_THRESHOLD_GOOD ) ); case 1: return Integer.parseInt( configuration.readAppProperty( AppProperty.PASSWORD_STRENGTH_THRESHOLD_WEAK ) ); default: return Integer.parseInt( configuration.readAppProperty( AppProperty.PASSWORD_STRENGTH_THRESHOLD_VERY_WEAK ) ); } }
@Test public void testJapaneseWarning() { Zxcvbn zxcvbn = new Zxcvbn(); Strength strength = zxcvbn.measure(password); Feedback feedback = strength.getFeedback(); ResourceBundle resourceBundle = ResourceBundle.getBundle("com/nulabinc/zxcvbn/messages", Locale.JAPANESE); String expectedWarningL10n = expectedWarning.length() > 0 ? resourceBundle.getString(expectedWarning) : ""; Assert.assertEquals("Unexpected warning", expectedWarningL10n, feedback.getWarning(Locale.JAPANESE)); }
@Test public void testWarning() { Zxcvbn zxcvbn = new Zxcvbn(); Strength strength = zxcvbn.measure(password); Feedback feedback = strength.getFeedback(); ResourceBundle resourceBundle = ResourceBundle.getBundle("com/nulabinc/zxcvbn/messages", Locale.ROOT); String expectedWarningL10n = expectedWarning.length() > 0 ? resourceBundle.getString(expectedWarning) : ""; Assert.assertEquals("Unexpected warning", expectedWarningL10n, feedback.getWarning(Locale.ENGLISH)); }
@Test public void testSuggestions() { Zxcvbn zxcvbn = new Zxcvbn(); Strength strength = zxcvbn.measure(password); Feedback feedback = strength.getFeedback(); ResourceBundle resourceBundle = ResourceBundle.getBundle("com/nulabinc/zxcvbn/messages", Locale.ROOT); String[] expectedSuggestionsL10n = new String[expectedSuggestions.length]; for (int i = 0; i < expectedSuggestions.length; i++) { String expectedSuggestion = expectedSuggestions[i]; expectedSuggestionsL10n[i] = resourceBundle.getString(expectedSuggestion); } Assert.assertArrayEquals("Unexpected suggestions", expectedSuggestionsL10n, feedback.getSuggestions(Locale.ENGLISH).toArray()); }
@Test public void testJapaneseSuggestions() { Zxcvbn zxcvbn = new Zxcvbn(); Strength strength = zxcvbn.measure(password); Feedback feedback = strength.getFeedback(); ResourceBundle resourceBundle = ResourceBundle.getBundle("com/nulabinc/zxcvbn/messages", Locale.JAPANESE); String[] expectedSuggestionsL10n = new String[expectedSuggestions.length]; for (int i = 0; i < expectedSuggestions.length; i++) { String expectedSuggestion = expectedSuggestions[i]; expectedSuggestionsL10n[i] = resourceBundle.getString(expectedSuggestion); } Assert.assertArrayEquals("Unexpected suggestions", expectedSuggestionsL10n, feedback.getSuggestions(Locale.JAPANESE).toArray()); }
@Test public void testMeasure() throws Exception { Zxcvbn zxcvbn = new Zxcvbn(); Strength strength = zxcvbn.measure(password); assertEquals("Unexpected error. Password is " + password, password, strength.getPassword()); }
@Test public void testUnknownSuggestions() { Zxcvbn zxcvbn = new Zxcvbn(); Strength strength = zxcvbn.measure(password); Feedback feedback = strength.getFeedback().withResourceBundle(null); Assert.assertArrayEquals("Unexpected suggestions", expectedSuggestions, feedback.getSuggestions().toArray()); }
@Test public void testUnknownWarning() { Zxcvbn zxcvbn = new Zxcvbn(); Strength strength = zxcvbn.measure(password); Feedback feedback = strength.getFeedback().withResourceBundle(null); Assert.assertEquals("Unexpected warning", expectedWarning, feedback.getWarning()); }