Copilot commented on code in PR #634:
URL: https://github.com/apache/maven-war-plugin/pull/634#discussion_r3646086747


##########
src/test/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTaskTest.java:
##########
@@ -0,0 +1,287 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugins.war.packaging;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugins.war.util.WebappStructure;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.filtering.FilterWrapper;
+import org.apache.maven.shared.filtering.MavenFileFilter;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class AbstractWarPackagingTaskTest {
+
+    @TempDir
+    File tempDir;
+
+    @Test
+    void testCopyFileRemovesExecutablePermissions() throws IOException {
+        File source = new File(tempDir, "source.jar");
+        assertTrue(source.createNewFile());
+        source.setExecutable(true, false);
+        source.setReadable(true, false);
+        source.setWritable(true, true);
+        assertTrue(source.canExecute());

Review Comment:
   This test assumes POSIX-style executable bits can be reliably set/cleared 
via java.io.File. On non-POSIX file systems (notably Windows), 
File#setExecutable/canExecute semantics differ and this can fail or become 
flaky. Consider guarding the test with a JUnit assumption that the underlying 
filesystem supports the "posix" attribute view.
   
   This issue also appears on line 69 of the same file.



##########
src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java:
##########
@@ -346,6 +346,10 @@ protected boolean copyFile(
                 FileUtils.copyFile(source.getCanonicalFile(), destination);
                 // preserve timestamp
                 
destination.setLastModified(readAttributes.lastModifiedTime().toMillis());
+                // normalize permissions: remove executable bits for files 
copied to the webapp
+                destination.setExecutable(false, false);
+                destination.setReadable(true, false);
+                destination.setWritable(true, true);

Review Comment:
   The permission normalization calls ignore the boolean return values from 
File#setExecutable/#setReadable/#setWritable. On filesystems/OSes that don't 
support these operations, this will silently fail and the jar may remain 
executable. Consider checking the return values and logging (at debug) when 
normalization could not be applied, so the behavior is diagnosable in the 
environments this change targets.



##########
src/test/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTaskTest.java:
##########
@@ -0,0 +1,287 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugins.war.packaging;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugins.war.util.WebappStructure;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.filtering.FilterWrapper;
+import org.apache.maven.shared.filtering.MavenFileFilter;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class AbstractWarPackagingTaskTest {
+
+    @TempDir
+    File tempDir;
+
+    @Test
+    void testCopyFileRemovesExecutablePermissions() throws IOException {
+        File source = new File(tempDir, "source.jar");
+        assertTrue(source.createNewFile());
+        source.setExecutable(true, false);
+        source.setReadable(true, false);
+        source.setWritable(true, true);
+        assertTrue(source.canExecute());
+
+        File webappDir = new File(tempDir, "webapp");
+        File destination = new File(webappDir, "WEB-INF/lib/test.jar");
+
+        AbstractWarPackagingTask task = createTask();
+        task.copyFile(createContext(webappDir), source, destination, 
"WEB-INF/lib/test.jar", false);
+
+        assertTrue(destination.exists());
+        assertFalse(destination.canExecute(), "copied file should not be 
executable");
+    }

Review Comment:
   The PR description states copied dependencies should be normalized to: not 
executable, readable by everyone, and writable only by the owner. The tests 
currently only assert the executable bit; adding an assertion on the full POSIX 
permissions (e.g., 0644) would better cover the intended behavior.



-- 
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