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

dsoumis pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 7a26a7d5f4 Add tests for StandardJarScanner scanManifest option to 
verify Class-Path manifest entries are followed when enabled and ignored when 
disabled.
7a26a7d5f4 is described below

commit 7a26a7d5f44fcbdaa0b0923da2fb4926883be3a6
Author: Dimitris Soumis <[email protected]>
AuthorDate: Tue Mar 31 14:46:45 2026 +0300

    Add tests for StandardJarScanner scanManifest option to verify Class-Path 
manifest entries are followed when enabled and ignored when disabled.
---
 .../tomcat/util/scan/TestStandardJarScanner.java   | 57 ++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/test/org/apache/tomcat/util/scan/TestStandardJarScanner.java 
b/test/org/apache/tomcat/util/scan/TestStandardJarScanner.java
index cabfebc3d3..853bde141f 100644
--- a/test/org/apache/tomcat/util/scan/TestStandardJarScanner.java
+++ b/test/org/apache/tomcat/util/scan/TestStandardJarScanner.java
@@ -17,14 +17,20 @@
 package org.apache.tomcat.util.scan;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
+import java.util.Deque;
 import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
 
+import org.junit.Assert;
 import org.junit.Test;
 
 import org.apache.tomcat.Jar;
@@ -57,6 +63,57 @@ public class TestStandardJarScanner {
         scanner.scan(JarScanType.PLUGGABILITY, context, callback);
     }
 
+    @Test
+    public void testScanManifestDefault() throws Exception {
+        Assert.assertTrue("Referenced JAR from manifest Class-Path should be 
scanned",
+                doTestScanManifest(true));
+    }
+
+    @Test
+    public void testScanManifestDisabled() throws Exception {
+        Assert.assertFalse("Referenced JAR from manifest Class-Path should not 
be scanned",
+                doTestScanManifest(false));
+    }
+
+    private boolean doTestScanManifest(boolean scanManifest) throws Exception {
+        File referencedJar = new File(System.getProperty("java.io.tmpdir"), 
"referenced.jar");
+        referencedJar.deleteOnExit();
+        JarOutputStream jarOutputStream = new JarOutputStream(new 
FileOutputStream(referencedJar), new Manifest());
+        jarOutputStream.close();
+
+        File testJar = new File(System.getProperty("java.io.tmpdir"), 
"manifest-test.jar");
+        testJar.deleteOnExit();
+
+        Manifest manifest = new Manifest();
+        manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, 
"1.0");
+        manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, 
"referenced.jar");
+
+        jarOutputStream = new JarOutputStream(new FileOutputStream(testJar), 
manifest);
+        jarOutputStream.close();
+
+        StandardJarScanner scanner = new StandardJarScanner() {
+            @Override
+            protected void addClassPath(Deque<URL> classPathUrlsToProcess) {
+                super.addClassPath(classPathUrlsToProcess);
+                try {
+                    classPathUrlsToProcess.add(testJar.toURI().toURL());
+                } catch (MalformedURLException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        };
+        scanner.setScanManifest(scanManifest);
+
+        LoggingCallback callback = new LoggingCallback();
+        scanner.scan(JarScanType.PLUGGABILITY, new TesterServletContext(), 
callback);
+
+        for (String cb : callback.callbacks) {
+            if (cb.contains("referenced.jar")) {
+                return true;
+            }
+        }
+        return false;
+    }
 
     private static class LoggingCallback implements JarScannerCallback {
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to