@Test(expected = GeneralSecurityException.class) public void testLoadEncryptedPrivateKeyFromKeyStoreWithWrongPassword() throws GeneralSecurityException, IOException { if (!x509TestContext.isKeyStoreEncrypted()) { throw new GeneralSecurityException(); // this case is not tested so throw the expected exception } PemReader.loadPrivateKey( x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM), Optional.of("wrong password")); }
@Test(expected = GeneralSecurityException.class) public void testLoadEncryptedPrivateKeyFromKeyStoreWithoutPassword() throws GeneralSecurityException, IOException { if (!x509TestContext.isKeyStoreEncrypted()) { throw new GeneralSecurityException(); // this case is not tested so throw the expected exception } PemReader.loadPrivateKey(x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM), Optional.empty()); }
@Test(expected = IOException.class) public void testLoadUnencryptedPrivateKeyFromKeyStoreWithWrongPassword() throws GeneralSecurityException, IOException { if (x509TestContext.isKeyStoreEncrypted()) { throw new IOException(); } PemReader.loadPrivateKey( x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM), Optional.of("wrong password")); }
@Test(timeout = 5000, expected = X509Exception.SSLContextException.class) public void testCreateSSLContextWithoutKeyStorePassword() throws Exception { if (!x509TestContext.isKeyStoreEncrypted()) { throw new X509Exception.SSLContextException(""); } System.clearProperty(x509Util.getSslKeystorePasswdProperty()); x509Util.getDefaultSSLContext(); }