Skip to content

Commit db39730

Browse files
committed
[SYNCOPE-1937] Fixing test case
1 parent 6266099 commit db39730

File tree

1 file changed

+14
-18
lines changed
  • core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner

1 file changed

+14
-18
lines changed

core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/UserTest.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,18 @@
1818
*/
1919
package org.apache.syncope.core.persistence.jpa.inner;
2020

21-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2221
import static org.junit.jupiter.api.Assertions.assertEquals;
2322
import static org.junit.jupiter.api.Assertions.assertFalse;
2423
import static org.junit.jupiter.api.Assertions.assertNotNull;
2524
import static org.junit.jupiter.api.Assertions.assertNull;
2625
import static org.junit.jupiter.api.Assertions.assertThrows;
2726
import 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;
3129
import java.time.OffsetDateTime;
3230
import java.time.temporal.ChronoUnit;
3331
import java.util.List;
3432
import java.util.Optional;
35-
import javax.crypto.BadPaddingException;
36-
import javax.crypto.IllegalBlockSizeException;
37-
import javax.crypto.NoSuchPaddingException;
3833
import org.apache.syncope.common.lib.types.CipherAlgorithm;
3934
import org.apache.syncope.core.persistence.api.dao.DerSchemaDAO;
4035
import 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

Comments
 (0)