summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2012-02-04 16:25:28 (EST)
committerSteffen Pingel2012-02-04 16:25:28 (EST)
commit8cc5ee9742b9897946a391bc85e77bf31768d6ed (patch)
treea0487edc5e0a266a249b94551b1634caa7750aa3
parent663e37ac20da5aa3b1e4834a44faa8cbe5988fdb (diff)
downloadorg.eclipse.mylyn.commons-8cc5ee9742b9897946a391bc85e77bf31768d6ed.zip
org.eclipse.mylyn.commons-8cc5ee9742b9897946a391bc85e77bf31768d6ed.tar.gz
org.eclipse.mylyn.commons-8cc5ee9742b9897946a391bc85e77bf31768d6ed.tar.bz2
REOPENED - bug 369697: skip certificate authentication test in broken
environments https://bugs.eclipse.org/bugs/show_bug.cgi?id=369697 Change-Id: Ia61c2c58d5d933f633771c213279077d1eb475f3
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java55
-rw-r--r--org.eclipse.mylyn.commons.notifications.core/src/org/eclipse/mylyn/commons/notifications/core/NotificationEnvironment.java41
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/CommonHttpClientTest.java24
-rw-r--r--org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/CommonTestUtil.java7
-rw-r--r--org.eclipse.mylyn.commons.tests/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/CoreUtilTest.java79
-rw-r--r--org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java8
7 files changed, 168 insertions, 47 deletions
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java
index 6175eb4..c3861d9 100644
--- a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java
@@ -153,4 +153,59 @@ public class CoreUtil {
}
}
+ /**
+ * Returns the version of the Java runtime.
+ *
+ * @since 3.7
+ * @return {@link Version#emptyVersion} if the version can not be determined
+ */
+ public static Version getRuntimeVersion() {
+ Version result = parseRuntimeVersion(System.getProperty("java.runtime.version")); //$NON-NLS-1$
+ if (result == Version.emptyVersion) {
+ result = parseRuntimeVersion(System.getProperty("java.version")); //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ private static Version parseRuntimeVersion(String versionString) {
+ if (versionString != null) {
+ int firstSeparator = versionString.indexOf('.');
+ if (firstSeparator != -1) {
+ try {
+ int secondSeparator = versionString.indexOf('.', firstSeparator + 1);
+ if (secondSeparator != -1) {
+ int index = findLastNumberIndex(versionString, secondSeparator);
+ String qualifier = versionString.substring(index + 1);
+ if (qualifier.startsWith("_") && qualifier.length() > 1) { //$NON-NLS-1$
+ versionString = versionString.substring(0, index + 1) + "." + qualifier.substring(1); //$NON-NLS-1$
+ } else {
+ versionString = versionString.substring(0, index + 1);
+ }
+ return new Version(versionString);
+ }
+ return new Version(versionString.substring(0,
+ findLastNumberIndex(versionString, firstSeparator) + 1));
+ } catch (IllegalArgumentException e) {
+ // ignore
+ }
+ }
+ }
+ return Version.emptyVersion;
+ }
+
+ private static int findLastNumberIndex(String versionString, int secondSeparator) {
+ int lastDigit = secondSeparator;
+ for (int i = secondSeparator + 1; i < versionString.length(); i++) {
+ if (Character.isDigit(versionString.charAt(i))) {
+ lastDigit++;
+ } else {
+ break;
+ }
+ }
+ if (lastDigit == secondSeparator) {
+ return secondSeparator - 1;
+ }
+ return lastDigit;
+ }
+
}
diff --git a/org.eclipse.mylyn.commons.notifications.core/src/org/eclipse/mylyn/commons/notifications/core/NotificationEnvironment.java b/org.eclipse.mylyn.commons.notifications.core/src/org/eclipse/mylyn/commons/notifications/core/NotificationEnvironment.java
index e0eaeb8..f6b53d3 100644
--- a/org.eclipse.mylyn.commons.notifications.core/src/org/eclipse/mylyn/commons/notifications/core/NotificationEnvironment.java
+++ b/org.eclipse.mylyn.commons.notifications.core/src/org/eclipse/mylyn/commons/notifications/core/NotificationEnvironment.java
@@ -65,11 +65,7 @@ public class NotificationEnvironment {
}
public Version getRuntimeVersion() {
- Version result = parseRuntimeVersion(System.getProperty("java.runtime.version")); //$NON-NLS-1$
- if (result == Version.emptyVersion) {
- result = parseRuntimeVersion(System.getProperty("java.version")); //$NON-NLS-1$
- }
- return result;
+ return CoreUtil.getRuntimeVersion();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -114,21 +110,6 @@ public class NotificationEnvironment {
return true;
}
- private int findLastNumberIndex(String versionString, int secondSeparator) {
- int lastDigit = secondSeparator;
- for (int i = secondSeparator + 1; i < versionString.length(); i++) {
- if (Character.isDigit(versionString.charAt(i))) {
- lastDigit++;
- } else {
- break;
- }
- }
- if (lastDigit == secondSeparator) {
- return secondSeparator - 1;
- }
- return lastDigit;
- }
-
public Set<String> getInstalledFeatures(IProgressMonitor monitor) {
return Collections.emptySet();
}
@@ -155,24 +136,4 @@ public class NotificationEnvironment {
return requiredFeature;
}
- private Version parseRuntimeVersion(String versionString) {
- if (versionString != null) {
- int firstSeparator = versionString.indexOf('.');
- if (firstSeparator != -1) {
- try {
- int secondSeparator = versionString.indexOf('.', firstSeparator + 1);
- if (secondSeparator != -1) {
- return new Version(versionString.substring(0,
- findLastNumberIndex(versionString, secondSeparator) + 1));
- }
- return new Version(versionString.substring(0,
- findLastNumberIndex(versionString, firstSeparator) + 1));
- } catch (IllegalArgumentException e) {
- // ignore
- }
- }
- }
- return Version.emptyVersion;
- }
-
}
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/CommonHttpClientTest.java b/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/CommonHttpClientTest.java
index 52e0c41..97da121 100644
--- a/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/CommonHttpClientTest.java
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/CommonHttpClientTest.java
@@ -47,6 +47,11 @@ public class CommonHttpClientTest {
@Test
public void testCertificateAuthenticationCertificate() throws Exception {
+ if (CommonTestUtil.isCertificateAuthBroken()) {
+ System.err.println("Skipped CommonHttpClientTest.testCertificateAuthenticationCertificate");
+ return; // skip test
+ }
+
RepositoryLocation location = new RepositoryLocation();
location.setUrl("https://mylyn.org/secure/index.txt");
location.setCredentials(AuthenticationType.CERTIFICATE, CommonTestUtil.getCertificateCredentials());
@@ -64,6 +69,11 @@ public class CommonHttpClientTest {
@Test(expected = SSLException.class)
public void testCertificateAuthenticationCertificateReset() throws Exception {
+ if (CommonTestUtil.isCertificateAuthBroken()) {
+ System.err.println("Skipped CommonHttpClientTest.testCertificateAuthenticationCertificateReset");
+ throw new SSLException(""); // skip test
+ }
+
RepositoryLocation location = new RepositoryLocation();
location.setUrl("https://mylyn.org/secure/index.txt");
location.setCredentials(AuthenticationType.CERTIFICATE, CommonTestUtil.getCertificateCredentials());
@@ -73,17 +83,21 @@ public class CommonHttpClientTest {
// work-around for bug 369805
Scheme oldScheme = setUpDefaultFactory(client);
try {
- HttpResponse response = client.execute(request, null);
try {
- assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
- } finally {
- HttpUtil.release(request, response, null);
+ HttpResponse response = client.execute(request, null);
+ try {
+ assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
+ } finally {
+ HttpUtil.release(request, response, null);
+ }
+ } catch (SSLException e) {
+ throw new IllegalStateException("Unexpected exception", e);
}
location.setCredentials(AuthenticationType.CERTIFICATE, null);
// the request should now fail
request = new HttpGet(location.getUrl());
- response = client.execute(request, null);
+ HttpResponse response = client.execute(request, null);
HttpUtil.release(request, response, null);
} finally {
tearDownDefaultFactory(client, oldScheme);
diff --git a/org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/CommonTestUtil.java b/org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/CommonTestUtil.java
index 5848557..41e1086 100644
--- a/org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/CommonTestUtil.java
+++ b/org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/CommonTestUtil.java
@@ -34,9 +34,11 @@ import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
+import org.eclipse.mylyn.commons.core.CoreUtil;
import org.eclipse.mylyn.commons.repositories.core.auth.CertificateCredentials;
import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials;
import org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader;
+import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.osgi.util.NLS;
/**
@@ -420,4 +422,9 @@ public class CommonTestUtil {
}
}
+ public static boolean isCertificateAuthBroken() {
+ // not entirely correct since 1.6.0_3 would also satisfy this check but it should be sufficient in reality
+ return new VersionRange("[0.0.0,1.6.0.25]").isIncluded(CoreUtil.getRuntimeVersion());
+ }
+
}
diff --git a/org.eclipse.mylyn.commons.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.commons.tests/META-INF/MANIFEST.MF
index a0d8546..e06d141 100644
--- a/org.eclipse.mylyn.commons.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.commons.tests/META-INF/MANIFEST.MF
@@ -15,6 +15,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.mylyn.commons.ui,
org.eclipse.mylyn.commons.workbench,
org.eclipse.mylyn.commons.xmlrpc,
+ org.eclipse.mylyn.commons.sdk.util;bundle-version="3.7.0",
org.apache.xmlrpc
Export-Package: org.eclipse.mylyn.commons.core;x-internal:=true,
org.eclipse.mylyn.commons.tests;x-internal:=true,
diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/CoreUtilTest.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/CoreUtilTest.java
index f010915..a729f9b 100644
--- a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/CoreUtilTest.java
+++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/CoreUtilTest.java
@@ -14,6 +14,8 @@ package org.eclipse.mylyn.commons.tests.core;
import junit.framework.TestCase;
import org.eclipse.mylyn.commons.core.CoreUtil;
+import org.eclipse.osgi.service.resolver.VersionRange;
+import org.osgi.framework.Version;
/**
* @author Steffen Pingel
@@ -105,4 +107,81 @@ public class CoreUtilTest extends TestCase {
assertFalse(CoreUtil.areEqual("a", "b"));
}
+ public void testGetRuntimeVersion() {
+ String oldValue = System.setProperty("java.runtime.version", "1.5.0_2");
+ try {
+ assertEquals(new Version(1, 5, 0, "2"), CoreUtil.getRuntimeVersion());
+ } finally {
+ System.setProperty("java.runtime.version", oldValue);
+ }
+ }
+
+ public void testGetRuntimeVersionShort() {
+ String oldValue = System.setProperty("java.runtime.version", "1.7");
+ try {
+ assertEquals(new Version(1, 7, 0), CoreUtil.getRuntimeVersion());
+ } finally {
+ System.setProperty("java.runtime.version", oldValue);
+ }
+ }
+
+ public void testGetRuntimeVersionLetters() {
+ String oldValue = System.setProperty("java.runtime.version", "1.7-CUSTOM");
+ try {
+ assertEquals(new Version(1, 7, 0), CoreUtil.getRuntimeVersion());
+ } finally {
+ System.setProperty("java.runtime.version", oldValue);
+ }
+ }
+
+ public void testGetRuntimeVersionTrailingUnderscore() {
+ String oldValue = System.setProperty("java.runtime.version", "1.5.0_");
+ try {
+ assertEquals(new Version(1, 5, 0), CoreUtil.getRuntimeVersion());
+ } finally {
+ System.setProperty("java.runtime.version", oldValue);
+ }
+ }
+
+ public void testGetRuntimeVersionNoQualifier() {
+ String oldValue = System.setProperty("java.runtime.version", "1.2.0");
+ try {
+ assertEquals(new Version(1, 2, 0), CoreUtil.getRuntimeVersion());
+ } finally {
+ System.setProperty("java.runtime.version", oldValue);
+ }
+ }
+
+ public void testGetRuntimeVersionProperty() {
+ String oldValue1 = System.setProperty("java.runtime.version", "1.2.0");
+ String oldValue2 = System.setProperty("java.version", "1.3.0");
+ try {
+ assertEquals(new Version(1, 2, 0), CoreUtil.getRuntimeVersion());
+ } finally {
+ System.setProperty("java.runtime.version", oldValue1);
+ System.setProperty("java.version", oldValue2);
+ }
+ }
+
+ public void testGetRuntimeVersionPropertyNull() {
+ String oldValue1 = System.clearProperty("java.runtime.version");
+ String oldValue2 = System.setProperty("java.version", "1.3.0");
+ try {
+ assertEquals(new Version(1, 3, 0), CoreUtil.getRuntimeVersion());
+ } finally {
+ System.setProperty("java.runtime.version", oldValue1);
+ System.setProperty("java.version", oldValue2);
+ }
+ }
+
+ public void testGetRuntimeVersionMatch() {
+ String oldValue = System.setProperty("java.runtime.version", "1.6.0_26");
+ try {
+ assertFalse(new VersionRange("[0.0.0,1.6.0.25]").isIncluded(CoreUtil.getRuntimeVersion()));
+ assertTrue(new VersionRange("[0.0.0,1.6.0.26]").isIncluded(CoreUtil.getRuntimeVersion()));
+ } finally {
+ System.setProperty("java.runtime.version", oldValue);
+ }
+ }
+
}
diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java
index d3e31de..2e196e2 100644
--- a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java
+++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java
@@ -40,6 +40,7 @@ import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.commons.net.IProxyProvider;
import org.eclipse.mylyn.commons.net.WebLocation;
import org.eclipse.mylyn.commons.net.WebUtil;
+import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;
import org.eclipse.mylyn.commons.tests.support.TestProxy;
import org.eclipse.mylyn.commons.tests.support.TestProxy.Message;
import org.eclipse.mylyn.internal.commons.net.AuthenticatedProxy;
@@ -517,13 +518,16 @@ public class WebUtilTest extends TestCase {
}
public void testLocationConnectSslClientCert() throws Exception {
+ if (CommonTestUtil.isCertificateAuthBroken()) {
+ return; // skip test
+ }
+
String url = "https://mylyn.org/secure/";
AbstractWebLocation location = new WebLocation(url);
HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(client, location, null);
if (!((PollingSslProtocolSocketFactory) hostConfiguration.getProtocol().getSocketFactory()).hasKeyManager()) {
- // skip test if keystore property is not set
- return;
+ return; // skip test if keystore property is not set
}
GetMethod method = new GetMethod(WebUtil.getRequestPath(url));