This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-crypto.git


The following commit(s) were added to refs/heads/master by this push:
     new dee781bc Allow for OpenSSL version checks
dee781bc is described below

commit dee781bca7f69cd54f4b6ae1fcc349b8727200a4
Author: Sebb <s...@apache.org>
AuthorDate: Sat Dec 2 13:58:59 2023 +0000

    Allow for OpenSSL version checks
    
    [skip ci]
---
 src/test/java/org/apache/commons/crypto/CryptoTest.java    | 11 +++++++++++
 .../java/org/apache/commons/crypto/jna/OpenSslJnaTest.java | 14 +++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/commons/crypto/CryptoTest.java 
b/src/test/java/org/apache/commons/crypto/CryptoTest.java
index 9c1a532e..92fda87e 100644
--- a/src/test/java/org/apache/commons/crypto/CryptoTest.java
+++ b/src/test/java/org/apache/commons/crypto/CryptoTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.crypto;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -23,6 +24,9 @@ import org.junit.jupiter.api.Test;
 
 public class CryptoTest {
 
+    // If defined, then fail if the version does not match major/minor bits
+    private static final String EXPECTED_VERSION_PROPERTY = 
"CryptoTest.expectedVersion";
+
     /**
      * This test may fail unless the code was built by Maven, as it relies on 
the VERSION file being set up correctly
      */
@@ -58,6 +62,13 @@ public class CryptoTest {
         assertTrue(Crypto.isNativeCodeLoaded(), "Native code loaded OK");
         Crypto.main(new String[] { }); // show the JNI library details
         assertTrue(Crypto.isNativeCodeLoaded(), "Completed OK");
+        final String expectedVersion = 
System.getProperty(EXPECTED_VERSION_PROPERTY, "");
+        if (expectedVersion.isEmpty()) {
+            System.out.println("OpenSSL version was not checked");
+        } else {
+            assertEquals(expectedVersion, 
Long.toHexString(OpenSslInfoNative.OpenSSL() & 0xFFFF0000));
+            System.out.println("OpenSSL version is as expected");
+        }
     }
 
 }
diff --git a/src/test/java/org/apache/commons/crypto/jna/OpenSslJnaTest.java 
b/src/test/java/org/apache/commons/crypto/jna/OpenSslJnaTest.java
index 96911e58..42f24abc 100644
--- a/src/test/java/org/apache/commons/crypto/jna/OpenSslJnaTest.java
+++ b/src/test/java/org/apache/commons/crypto/jna/OpenSslJnaTest.java
@@ -17,12 +17,24 @@
  */
 package org.apache.commons.crypto.jna;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import org.junit.jupiter.api.Test;
 
 public class OpenSslJnaTest {
 
+    // If defined, then fail if the version does not match major/minor bits
+    private static final String EXPECTED_VERSION_PROPERTY = 
"OpenSslJnaTest.expectedVersion";
+
     @Test
     public void testMain() throws Throwable {
         OpenSslJna.main(new String[0]);
-    }
+        final String expectedVersion = 
System.getProperty(EXPECTED_VERSION_PROPERTY, "");
+        if (expectedVersion.isEmpty()) {
+            System.out.println("OpenSSL version was not checked");
+        } else {
+            assertEquals(expectedVersion, 
Long.toHexString(OpenSslNativeJna.OpenSSL_version_num() & 0xFFFF0000));
+            System.out.println("OpenSSL version is as expected");
+        }
+   }
 }

Reply via email to