Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMykola Nikishov2018-03-11 12:40:03 -0400
committerMykola Nikishov2018-12-21 03:53:17 -0500
commite4b77e59e038d101733b37be47941c899a88d7d3 (patch)
treef29c67eafc13e6e0f2eef7ad2f39641207d9596f
parentb8b794603e2cc67f4b2d7e5c392b6f1f8b534d86 (diff)
downloadrt.equinox.p2-e4b77e59e038d101733b37be47941c899a88d7d3.tar.gz
rt.equinox.p2-e4b77e59e038d101733b37be47941c899a88d7d3.tar.xz
rt.equinox.p2-e4b77e59e038d101733b37be47941c899a88d7d3.zip
Contribute MD5 via artifactChecksums extension point instead of MD5Verifier processing step
Since now, artifact checksums are verified exclusively by the combination of ChecksumVerifier processing step + contributions to artifactChecksums extension point. There are no more internal usages of MD5Verifier and it can be removed. But let it sit here for some time. ChecksumUtilitiesTest ensures that MD5 checksums from IArtifactDescriptor.ARTIFACT_MD5 and IArtifactDescriptor.DOWNLOAD_MD5 properties are still honored. Change-Id: Ib4bec48504c3b2f4296425f6d2e930e402b5b984 Signed-off-by: Mykola Nikishov <mn@mn.com.ua>
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/plugin.xml12
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumUtilities.java15
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumVerifier.java12
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/AllTests.java1
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/ChecksumUtilitiesTest.java79
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java18
6 files changed, 115 insertions, 22 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/plugin.xml b/bundles/org.eclipse.equinox.p2.artifact.repository/plugin.xml
index 6abe0c6f5..bf5778333 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/plugin.xml
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/plugin.xml
@@ -35,17 +35,19 @@
<extension
point="org.eclipse.equinox.p2.artifact.repository.processingSteps"
- id="org.eclipse.equinox.p2.processing.MD5Verifier">
- <step class="org.eclipse.equinox.internal.p2.artifact.processors.md5.MD5Verifier"/>
- </extension>
- <extension
- point="org.eclipse.equinox.p2.artifact.repository.processingSteps"
id="org.eclipse.equinox.p2.processing.ChecksumVerifier">
<step class="org.eclipse.equinox.internal.p2.artifact.processors.checksum.ChecksumVerifier"/>
</extension>
<extension
point="org.eclipse.equinox.p2.artifact.repository.artifactChecksums">
<artifactChecksum
+ algorithm="MD5"
+ id="md5">
+ </artifactChecksum>
+ </extension>
+ <extension
+ point="org.eclipse.equinox.p2.artifact.repository.artifactChecksums">
+ <artifactChecksum
algorithm="SHA-256"
id="sha-256">
</artifactChecksum>
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumUtilities.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumUtilities.java
index 9a478c069..317778e28 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumUtilities.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumUtilities.java
@@ -19,7 +19,6 @@ import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.Map.Entry;
import org.eclipse.core.runtime.*;
-import org.eclipse.equinox.internal.p2.artifact.processors.md5.MD5Verifier;
import org.eclipse.equinox.internal.p2.artifact.repository.Messages;
import org.eclipse.equinox.internal.p2.repository.Activator;
import org.eclipse.equinox.internal.p2.repository.helpers.ChecksumHelper;
@@ -67,9 +66,6 @@ public class ChecksumUtilities {
}
}
- Optional<MD5Verifier> legacyMd5Verifier = getLegacyMd5Verifier(checksums.get(ChecksumHelper.MD5));
- legacyMd5Verifier.ifPresent(verifier -> steps.add(verifier));
-
return steps;
}
@@ -138,17 +134,6 @@ public class ChecksumUtilities {
return properties;
}
- private static Optional<MD5Verifier> getLegacyMd5Verifier(String md5) {
- if (md5 != null) {
- @SuppressWarnings("resource") //It's used later so shouldn't be closed
- MD5Verifier checksumVerifier = new MD5Verifier(md5);
- if (checksumVerifier.getStatus().isOK())
- return Optional.of(checksumVerifier);
- }
-
- return Optional.empty();
- }
-
private static void putLegacyMd5Property(String propertyNamespace, Map<String, String> checksums, HashMap<String, String> result) {
String md5 = checksums.get(ChecksumHelper.MD5);
if (md5 != null) {
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumVerifier.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumVerifier.java
index 1e1d4fe55..3335fdb48 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumVerifier.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/checksum/ChecksumVerifier.java
@@ -73,4 +73,16 @@ final public class ChecksumVerifier extends MessageDigestProcessingStep {
setStatus(new Status(IStatus.ERROR, Activator.ID, ProvisionException.ARTIFACT_MD5_NOT_MATCH, NLS.bind(Messages.Error_unexpected_checksum, new Object[] {algorithmName, expectedChecksum, digestString}), null));
}
+ public String getExpectedChecksum() {
+ return expectedChecksum;
+ }
+
+ public String getAlgorithmName() {
+ return algorithmName;
+ }
+
+ public String getAlgorithmId() {
+ return algorithmId;
+ }
+
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/AllTests.java
index 6ed240d2d..d862e6c49 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/AllTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/AllTests.java
@@ -25,6 +25,7 @@ public class AllTests extends TestCase {
suite.addTestSuite(Pack200ProcessorTest.class);
suite.addTestSuite(ZipVerifierProcessorTest.class);
suite.addTest(new JUnit4TestAdapter(ChecksumVerifierTest.class));
+ suite.addTest(new JUnit4TestAdapter(ChecksumUtilitiesTest.class));
return suite;
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/ChecksumUtilitiesTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/ChecksumUtilitiesTest.java
new file mode 100644
index 000000000..d16ed44bc
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/ChecksumUtilitiesTest.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Mykola Nikishov
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Mykola Nikishov - initial implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.processors;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptySet;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collection;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.artifact.processors.checksum.ChecksumUtilities;
+import org.eclipse.equinox.internal.p2.artifact.processors.checksum.ChecksumVerifier;
+import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
+import org.eclipse.equinox.internal.p2.metadata.OSGiVersion;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
+import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
+import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class ChecksumUtilitiesTest {
+ @Parameter(0)
+ public String propertyType;
+ @Parameter(1)
+ public String property;
+ @Parameter(2)
+ public String value;
+ @Parameter(3)
+ public String digestAlgorithm;
+ @Parameter(4)
+ public String algorithmId;
+
+ @Parameters
+ public static Collection<Object[]> generateData() {
+ return asList(new Object[][] {{IArtifactDescriptor.ARTIFACT_CHECKSUM, IArtifactDescriptor.ARTIFACT_MD5, "123456789_123456789_123456789_12", "MD5", "md5"},
+ {IArtifactDescriptor.ARTIFACT_CHECKSUM, IArtifactDescriptor.ARTIFACT_CHECKSUM.concat(".md5"), "123456789_123456789_123456789_12", "MD5", "md5"},
+ {IArtifactDescriptor.ARTIFACT_CHECKSUM, IArtifactDescriptor.ARTIFACT_CHECKSUM.concat(".sha-256"), "123456789_123456789_123456789_123456789_123456789_123456789_1234", "SHA-256", "sha-256"},
+ {IArtifactDescriptor.DOWNLOAD_CHECKSUM, IArtifactDescriptor.DOWNLOAD_MD5, "123456789_123456789_123456789_12", "MD5", "md5"},
+ {IArtifactDescriptor.DOWNLOAD_CHECKSUM, IArtifactDescriptor.DOWNLOAD_CHECKSUM.concat(".md5"), "123456789_123456789_123456789_12", "MD5", "md5"},
+ {IArtifactDescriptor.DOWNLOAD_CHECKSUM, IArtifactDescriptor.DOWNLOAD_CHECKSUM.concat(".sha-256"), "123456789_123456789_123456789_123456789_123456789_123456789_1234", "SHA-256", "sha-256"}});
+ }
+
+ private ArtifactDescriptor artifactDescriptor;
+
+ @Before
+ public void buildArtifactDescriptor() {
+ artifactDescriptor = new ArtifactDescriptor(new ArtifactKey("", "", new OSGiVersion(1, 1, 1, "")));
+ artifactDescriptor.setProperty(property, value);
+ }
+
+ @Test
+ public void testChecksumProperty() {
+ Collection<ProcessingStep> checksumVerifiers = ChecksumUtilities.getChecksumVerifiers(artifactDescriptor, propertyType, emptySet());
+ ChecksumVerifier verifier = (ChecksumVerifier) checksumVerifiers.iterator().next();
+
+ assertEquals(1, checksumVerifiers.size());
+ assertEquals(digestAlgorithm, verifier.getAlgorithmName());
+ assertEquals(algorithmId, verifier.getAlgorithmId());
+ assertEquals(value, verifier.getExpectedChecksum());
+ assertEquals(Status.OK_STATUS, verifier.getStatus());
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java
index c8df6b48d..5179dc98e 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java
@@ -15,6 +15,8 @@
*******************************************************************************/
package org.eclipse.equinox.p2.tests.artifact.repository.processing;
+import static org.junit.Assert.assertNotEquals;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -202,12 +204,24 @@ public class ProcessingStepHandlerTest extends AbstractProvisioningTest {
assertEquals(ByteShifter.class, steps[0].getClass());
}
+ @SuppressWarnings("deprecation")
public void testCreateMD5VerifierPS() {
- ProcessingStepDescriptor[] descriptors = new ProcessingStepDescriptor[] {new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.MD5Verifier", "1", true)};
+ String processorId = "org.eclipse.equinox.p2.processing.MD5Verifier";
+ ProcessingStepDescriptor[] descriptors = new ProcessingStepDescriptor[] {new ProcessingStepDescriptor(processorId, "1", true)};
+ ProcessingStep[] steps = handler.create(getAgent(), descriptors, null);
+ assertNotNull(steps);
+ assertEquals(1, steps.length);
+ assertNotEquals(String.format("Step '%s' is not available anymore", processorId), MD5Verifier.class, steps[0].getClass());
+ assertEquals(IStatus.ERROR, steps[0].getStatus().getSeverity());
+ }
+
+ public void testCreateChecksumVerifierPS() {
+ ProcessingStepDescriptor processingStepDescriptor = new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.ChecksumVerifier", "1", true);
+ ProcessingStepDescriptor[] descriptors = new ProcessingStepDescriptor[] {processingStepDescriptor};
ProcessingStep[] steps = handler.create(getAgent(), descriptors, null);
assertNotNull(steps);
assertEquals(1, steps.length);
- assertEquals(MD5Verifier.class, steps[0].getClass());
+ assertEquals(IStatus.ERROR, steps[0].getStatus().getSeverity());
}
public void testCreateAdderPS() {

Back to the top