Skip to content

Commit

Permalink
Add BouncyCastle provider to UrlUtil tests to solve problem with URL …
Browse files Browse the repository at this point in the history
…connection on Android

DEVSIX-6579
  • Loading branch information
introfog committed Feb 16, 2023
1 parent 8b2824b commit ae0037f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions io/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
<artifactId>xercesImpl</artifactId>
<version>2.12.2</version>
</dependency>
<!-- Android as an implementation of HTTP URL connection uses OkHttp library which requires some
Cryptographic Service Provider (CSP). So add dependency to BouncyCastle provider. -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
<optional>true</optional>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
6 changes: 3 additions & 3 deletions io/src/test/java/com/itextpdf/io/util/UrlUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ This file is part of the iText (R) project.
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.security.Security;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -66,6 +68,7 @@ public class UrlUtilTest extends ExtendedITextTest {

@BeforeClass
public static void beforeClass() {
Security.addProvider(new BouncyCastleProvider());
createDestinationFolder(destinationFolder);
}

Expand All @@ -84,7 +87,6 @@ public void getFinalURLDoesNotLockFileTest() throws IOException {
// Tests, that getFinalConnection will be redirected some times for other urls, and initialUrl will be different
// from final url.
@Test
// Android-Ignore (TODO DEVSIX-6551 fix problem with getFinalConnection method related to SSL)
public void getFinalConnectionWhileRedirectingTest() throws IOException {
URL initialUrl = new URL("http://itextpdf.com");
URL expectedURL = new URL("https://itextpdf.com/");
Expand All @@ -104,7 +106,6 @@ public void getFinalConnectionWhileRedirectingTest() throws IOException {
// This test checks that when we pass invalid url and trying get stream related to final redirected url,exception
// would be thrown.
@Test
// Android-Ignore (TODO DEVSIX-6551 fix problem with getFinalConnection method related to SSL)
public void getInputStreamOfFinalConnectionThrowExceptionTest() throws IOException {
URL invalidUrl = new URL("http://itextpdf");

Expand All @@ -114,7 +115,6 @@ public void getInputStreamOfFinalConnectionThrowExceptionTest() throws IOExcepti
// This test checks that when we pass valid url and trying get stream related to final redirected url, it would
// not be null.
@Test
// Android-Ignore (TODO DEVSIX-6551 fix problem with getFinalConnection method related to SSL)
public void getInputStreamOfFinalConnectionTest() throws IOException {
URL initialUrl = new URL("http://itextpdf.com");
InputStream streamOfFinalConnectionOfInvalidUrl = UrlUtil.getInputStreamOfFinalConnection(initialUrl);
Expand Down

0 comments on commit ae0037f

Please sign in to comment.