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 2020/12/07 22:11:38 UTC

[maven-surefire] branch master updated: [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 master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


The following commit(s) were added to refs/heads/master by this push:
     new 1da3462  [SUREFIRE-1865] ChecksumCalculator getSha1 does not compute checksums correctly
1da3462 is described below

commit 1da3462303afe17c030cb884953f11133b8b4796
Author: Gian Merlino <gi...@gmail.com>
AuthorDate: Sat Dec 5 17:09:44 2020 -0800

    [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.
---
 .../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 5f19f7f..2e87a4d 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 java.nio.charset.StandardCharsets.ISO_8859_1;
+import static java.nio.charset.StandardCharsets.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 7692a04..da476a7 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
@@ -32,6 +32,7 @@ import org.apache.maven.plugin.surefire.SurefireHelperTest;
 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.ForkStarterTest;
@@ -116,6 +117,7 @@ public class JUnit4SuiteTest extends TestCase
         suite.addTest( new JUnit4TestAdapter( E2ETest.class ) );
         suite.addTest( new JUnit4TestAdapter( ThreadedStreamConsumerTest.class ) );
         suite.addTest( new JUnit4TestAdapter( EventConsumerThreadTest.class ) );
+        suite.addTest( new JUnit4TestAdapter( ChecksumCalculatorTest.class ) );
         return suite;
     }
 }