Browse Source

Avoid UnknownHostException in WalkEncryptionTest

Prevent that WalkEncryptionTest fails when it can't determine the public
IP address using http://checkip.amazonws.com. Also set timeouts when
determining IP address in order to prevent long wait times during tests.

Change-Id: I1d2fe09f99df2a5f75f8077811a72fb2271cdddb
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.3
Matthias Sohn 9 years ago
parent
commit
fe85311b3a
  1. 41
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java

41
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java

@ -43,6 +43,20 @@
package org.eclipse.jgit.transport;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.UTF_8;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListPBE;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListTrans;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.folderDelete;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.permitLongTests;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.policySetup;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.product;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.proxySetup;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.publicAddress;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.reportPolicy;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.securityProviderName;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.textWrite;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.transferStream;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.verifyFileContent;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@ -59,7 +73,10 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.security.GeneralSecurityException;
@ -94,8 +111,6 @@ import org.junit.runners.Suite;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.*;
/**
* Amazon S3 encryption pipeline test.
*
@ -401,14 +416,22 @@ public class WalkEncryptionTest {
* @throws Exception
*/
static String publicAddress() throws Exception {
String service = "http://checkip.amazonaws.com";
URL url = new URL(service);
BufferedReader reader = new BufferedReader(
new InputStreamReader(url.openStream()));
try {
return reader.readLine();
} finally {
reader.close();
String service = "http://checkip.amazonaws.com";
URL url = new URL(service);
URLConnection c = url.openConnection();
c.setConnectTimeout(500);
c.setReadTimeout(500);
BufferedReader reader = new BufferedReader(
new InputStreamReader(c.getInputStream()));
try {
return reader.readLine();
} finally {
reader.close();
}
} catch (UnknownHostException | SocketTimeoutException e) {
return "Can't reach http://checkip.amazonaws.com to"
+ " determine public address";
}
}

Loading…
Cancel
Save