You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2022/01/24 00:45:53 UTC
[maven-surefire] 01/05: [SUREFIRE-1865] ChecksumCalculator getSha1 does not compute checksums correctly
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch release/2.22.3
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit d44dd1d6bf6c49abd73f6fcb52d7e62b5904540f
Author: Gian Merlino <gi...@gmail.com>
AuthorDate: Sun Dec 6 02:09:44 2020 +0100
[SUREFIRE-1865] ChecksumCalculator getSha1 does not compute checksums correctly
Two changes:
1) Fix length computation to use bytes, not characters.
2) Use UTF_8 instead of ISO_8859_1 for encoding, because configs can contain
characters that fall outside the ISO_8859_1 character set.
(cherry picked from commit 1da3462303afe17c030cb884953f11133b8b4796)
---
.../surefire/booterclient/ChecksumCalculator.java | 5 +--
.../booterclient/ChecksumCalculatorTest.java | 38 ++++++++++++++++++++++
.../org/apache/maven/surefire/JUnit4SuiteTest.java | 2 ++
3 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ChecksumCalculator.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ChecksumCalculator.java
index 5931f9e..5f32be1 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ChecksumCalculator.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ChecksumCalculator.java
@@ -29,7 +29,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import static org.apache.maven.surefire.util.internal.StringUtils.ISO_8859_1;
+import static org.apache.maven.surefire.util.internal.StringUtils.UTF_8;
/**
* @author Kristian Rosenvold
@@ -155,7 +155,8 @@ public class ChecksumCalculator
{
MessageDigest md = MessageDigest.getInstance( "SHA-1" );
String configValue = getConfig();
- md.update( configValue.getBytes( ISO_8859_1 ), 0, configValue.length() );
+ byte[] configBytes = configValue.getBytes( UTF_8 );
+ md.update( configBytes );
byte[] sha1hash = md.digest();
return asHexString( sha1hash );
}
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ChecksumCalculatorTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ChecksumCalculatorTest.java
new file mode 100644
index 0000000..e5b91d3
--- /dev/null
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ChecksumCalculatorTest.java
@@ -0,0 +1,38 @@
+package org.apache.maven.plugin.surefire.booterclient;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for {@link ChecksumCalculator}.
+ */
+public class ChecksumCalculatorTest
+{
+ @Test
+ public void testGetSha1()
+ {
+ final ChecksumCalculator calculator = new ChecksumCalculator();
+ calculator.add( "foö 🔥 Россия 한국 中国" );
+ assertEquals( "3421557EBE66A4741CA51C8D610AB1AB41D1693B", calculator.getSha1() );
+ }
+}
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/surefire/JUnit4SuiteTest.java b/maven-surefire-common/src/test/java/org/apache/maven/surefire/JUnit4SuiteTest.java
index 728cef3..faf04b1 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/surefire/JUnit4SuiteTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/surefire/JUnit4SuiteTest.java
@@ -31,6 +31,7 @@ import org.apache.maven.plugin.surefire.SurefireReflectorTest;
import org.apache.maven.plugin.surefire.SurefirePropertiesTest;
import org.apache.maven.plugin.surefire.booterclient.BooterDeserializerProviderConfigurationTest;
import org.apache.maven.plugin.surefire.booterclient.BooterDeserializerStartupConfigurationTest;
+import org.apache.maven.plugin.surefire.booterclient.ChecksumCalculatorTest;
import org.apache.maven.plugin.surefire.booterclient.DefaultForkConfigurationTest;
import org.apache.maven.plugin.surefire.booterclient.ForkConfigurationTest;
import org.apache.maven.plugin.surefire.booterclient.ForkingRunListenerTest;
@@ -95,6 +96,7 @@ public class JUnit4SuiteTest extends TestCase
}
suite.addTest( new JUnit4TestAdapter( ScannerUtilTest.class ) );
suite.addTest( new JUnit4TestAdapter( MojoMocklessTest.class ) );
+ suite.addTest( new JUnit4TestAdapter( ChecksumCalculatorTest.class ) );
return suite;
}
}