laurentgo commented on code in PR #44565:
URL: https://github.com/apache/arrow/pull/44565#discussion_r1821818148


##########
java/flight/flight-sql-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/ITDriverJarValidation.java:
##########
@@ -48,52 +54,92 @@ public class ITDriverJarValidation {
 
   /** List of allowed prefixes a jar entry may match. */
   public static final Set<String> ALLOWED_PREFIXES =
-      ImmutableSet.of("org/apache/arrow/driver/jdbc/", "META-INF/");
+      ImmutableSet.of(
+          "org/apache/arrow/driver/jdbc/", // Driver code
+          "META-INF/maven/", // Maven metadata (useful for security scanner
+          "META-INF/services/", // ServiceLoader implementations
+          "META-INF/license/",
+          "META-INF/licenses/",
+          // Prefixes for native libraries
+          "META-INF/native/liborg_apache_arrow_driver_jdbc_shaded_",
+          "META-INF/native/org_apache_arrow_driver_jdbc_shaded_");
 
   /** List of allowed files a jar entry may match. */
   public static final Set<String> ALLOWED_FILES =
-      ImmutableSet.of("arrow-git.properties", "properties/flight.properties");
+      ImmutableSet.of(
+          "arrow-git.properties",
+          "properties/flight.properties",
+          "META-INF/io.netty.versions.properties",
+          "META-INF/MANIFEST.MF",
+          "META-INF/DEPENDENCIES",
+          "META-INF/FastDoubleParser-LICENSE",
+          "META-INF/FastDoubleParser-NOTICE",
+          "META-INF/LICENSE",
+          "META-INF/LICENSE.txt",
+          "META-INF/NOTICE",
+          "META-INF/NOTICE.txt",
+          "META-INF/thirdparty-LICENSE",
+          "META-INF/bigint-LICENSE");
 
   // This method is designed to work with Maven failsafe plugin and expects the
   // JDBC driver jar to be present in the test classpath (instead of the 
individual classes)
-  private static JarFile getJdbcJarFile() throws IOException {
+  private static File getJdbcJarFile() throws IOException {
     // Check if an override has been set
     if (JDBC_DRIVER_PATH_OVERRIDE != null) {
-      return new JarFile(new File(JDBC_DRIVER_PATH_OVERRIDE));
+      return new File(JDBC_DRIVER_PATH_OVERRIDE);
     }
 
-    // Check classpath to find the driver jar
+    // Check classpath to find the driver jar (without loading the class)
     URL driverClassURL =
         ITDriverJarValidation.class
             .getClassLoader()
             
.getResource("org/apache/arrow/driver/jdbc/ArrowFlightJdbcDriver.class");
 
-    assertNotNull(driverClassURL, "Driver jar was not detected in the 
classpath");
+    assertNotNull(driverClassURL, "Driver class was not detected in the 
classpath");
     assertEquals(
-        "jar", driverClassURL.getProtocol(), "Driver jar was not detected in 
the classpath");
+        "jar", driverClassURL.getProtocol(), "Driver class was not found 
inside a jar file");
 
+    // Return the enclosing jar file
     JarURLConnection connection = (JarURLConnection) 
driverClassURL.openConnection();
-    return connection.getJarFile();
+    try {
+      return new File(connection.getJarFileURL().toURI());
+    } catch (URISyntaxException e) {
+      throw new IOException(e);
+    }
   }
 
+  /** Validate the content of the jar to enforce all 3rd party dependencies 
have been shaded. */
   @Test
   @Timeout(value = 2, unit = TimeUnit.MINUTES)
   public void validateShadedJar() throws IOException {
-    // Validate the content of the jar to enforce all 3rd party dependencies 
have
-    // been shaded
-    try (JarFile jar = getJdbcJarFile()) {
-      for (Enumeration<JarEntry> entries = jar.entries(); 
entries.hasMoreElements(); ) {
-        final JarEntry entry = entries.nextElement();
-        if (entry.isDirectory()) {
-          // Directories are ignored
-          continue;
-        }
-
-        try {
-          checkEntryAllowed(entry.getName());
-        } catch (AssertionError e) {
-          fail(e.getMessage());
-        }
+
+    try (JarFile jar = new JarFile(getJdbcJarFile())) {
+      Stream<Executable> executables =
+          jar.stream()
+              .filter(Predicate.not(JarEntry::isDirectory))
+              .map(
+                  entry -> {
+                    return () -> checkEntryAllowed(entry.getName());
+                  });
+
+      Assertions.assertAll(executables);
+    }
+  }
+
+  /** Check that relocated netty code can also load matching native library. */
+  @Test
+  @Timeout(value = 2, unit = TimeUnit.MINUTES)

Review Comment:
   Not really, I copied the pattern from the other test method (which also does 
not really need a test timeout as well)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to