BAEL-4388 Test reading keyStore without trustAnchor (#11785)

This commit is contained in:
polomos 2022-02-15 22:14:36 +01:00 committed by GitHub
parent 864b139aa4
commit 7966e98d90
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
package com.baeldung.truststore;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.PKIXParameters;
public class TrustStoreUnitTest {
@Test
public void whenOpeningTrustStore_thenExceptionIsThrown() throws Exception {
KeyStore keyStore = getKeyStore();
InvalidAlgorithmParameterException invalidAlgorithmParameterException =
Assertions.assertThrows(InvalidAlgorithmParameterException.class, () -> new PKIXParameters(keyStore));
Assertions.assertEquals("the trustAnchors parameter must be non-empty", invalidAlgorithmParameterException.getMessage());
}
private KeyStore getKeyStore() throws CertificateException, NoSuchAlgorithmException, IOException, KeyStoreException {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, "changeIt".toCharArray());
return ks;
}
}