1818 */
1919package org .apache .syncope .core .persistence .jpa .inner ;
2020
21- import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
2221import static org .junit .jupiter .api .Assertions .assertEquals ;
2322import static org .junit .jupiter .api .Assertions .assertFalse ;
2423import static org .junit .jupiter .api .Assertions .assertNotNull ;
2524import static org .junit .jupiter .api .Assertions .assertNull ;
2625import static org .junit .jupiter .api .Assertions .assertThrows ;
2726import static org .junit .jupiter .api .Assertions .assertTrue ;
27+ import static org .junit .jupiter .api .Assertions .fail ;
2828
29- import java .security .InvalidKeyException ;
30- import java .security .NoSuchAlgorithmException ;
3129import java .time .OffsetDateTime ;
3230import java .time .temporal .ChronoUnit ;
3331import java .util .List ;
3432import java .util .Optional ;
35- import javax .crypto .BadPaddingException ;
36- import javax .crypto .IllegalBlockSizeException ;
37- import javax .crypto .NoSuchPaddingException ;
3833import org .apache .syncope .common .lib .types .CipherAlgorithm ;
3934import org .apache .syncope .core .persistence .api .dao .DerSchemaDAO ;
4035import org .apache .syncope .core .persistence .api .dao .ExternalResourceDAO ;
@@ -309,9 +304,7 @@ public void issueSYNCOPE1666() {
309304 }
310305
311306 @ Test
312- public void issueSYNCOPE1937 ()
313- throws NoSuchPaddingException , IllegalBlockSizeException , NoSuchAlgorithmException , BadPaddingException ,
314- InvalidKeyException {
307+ public void issueSYNCOPE1937 () throws Exception {
315308 User user = entityFactory .newEntity (User .class );
316309 user .setUsername ("username" );
317310 user .setRealm (realmDAO .getRoot ());
@@ -321,16 +314,17 @@ public void issueSYNCOPE1937()
321314 user .setCipherAlgorithm (CipherAlgorithm .SHA1 );
322315 user .setPassword ("password123" );
323316
324- User actual = userDAO .save (user );
317+ user = userDAO .save (user );
318+ assertNotNull (user );
325319
326320 assertEquals (0 , user .getPasswordHistory ().size ());
327321
328322 // add some other password to history
329- user .addToPasswordHistory (encryptorManager .getInstance ().encode ("Password123!" , CipherAlgorithm .SHA1 ));
330- user .addToPasswordHistory (encryptorManager .getInstance ().encode ("Password124!" , CipherAlgorithm .SHA1 ));
331- user .addToPasswordHistory (encryptorManager .getInstance ().encode ("Password125!" , CipherAlgorithm .SHA1 ));
332- user .addToPasswordHistory (encryptorManager .getInstance ().encode ("Password126!" , CipherAlgorithm .SHA1 ));
333- user .addToPasswordHistory (encryptorManager .getInstance ().encode ("Password127!" , CipherAlgorithm .SHA1 ));
323+ user .addToPasswordHistory (Encryptor .getInstance ().encode ("Password123!" , CipherAlgorithm .SHA1 ));
324+ user .addToPasswordHistory (Encryptor .getInstance ().encode ("Password124!" , CipherAlgorithm .SHA1 ));
325+ user .addToPasswordHistory (Encryptor .getInstance ().encode ("Password125!" , CipherAlgorithm .SHA1 ));
326+ user .addToPasswordHistory (Encryptor .getInstance ().encode ("Password126!" , CipherAlgorithm .SHA1 ));
327+ user .addToPasswordHistory (Encryptor .getInstance ().encode ("Password127!" , CipherAlgorithm .SHA1 ));
334328
335329 assertEquals (5 , user .getPasswordHistory ().size ());
336330
@@ -340,8 +334,10 @@ public void issueSYNCOPE1937()
340334 assertEquals (3 , user .getPasswordHistory ().size ());
341335
342336 // try with an exceeding number
343- assertDoesNotThrow (() -> user .removeOldestEntriesFromPasswordHistory (user .getPasswordHistory ().size () + 5 ));
344-
345- assertNotNull (actual );
337+ try {
338+ user .removeOldestEntriesFromPasswordHistory (user .getPasswordHistory ().size () + 5 );
339+ } catch (Exception e ) {
340+ fail (e );
341+ }
346342 }
347343}
0 commit comments