1414import java .util .zip .ZipEntry ;
1515import java .util .zip .ZipFile ;
1616
17+ import org .apache .commons .compress .archivers .zip .ZipArchiveEntry ;
1718import org .codehaus .plexus .archiver .ArchiverException ;
1819import org .junit .jupiter .api .Test ;
1920import org .junit .jupiter .api .io .TempDir ;
@@ -123,14 +124,16 @@ private void createReproducibleBuild(String timeZoneId) throws IOException, Mani
123124
124125 JarArchiver archiver = getJarArchiver ();
125126 archiver .setDestFile (jarFile .toFile ());
126- archiver .addConfiguredManifest (manifest );
127- archiver .addDirectory (new File ("src/test/resources/java-classes" ));
128127
129128 SimpleDateFormat isoFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ssXXX" );
130129 long parsedTime = isoFormat .parse ("2038-01-19T03:14:08Z" ).getTime ();
131130 FileTime lastModTime = FileTime .fromMillis (parsedTime );
132131
133132 archiver .configureReproducibleBuild (lastModTime );
133+
134+ archiver .addConfiguredManifest (manifest );
135+ archiver .addDirectory (new File ("src/test/resources/java-classes" ));
136+
134137 archiver .createArchive ();
135138
136139 // zip 2 seconds precision, normalized to UTC
@@ -148,6 +151,45 @@ private void createReproducibleBuild(String timeZoneId) throws IOException, Mani
148151 }
149152 }
150153
154+ /**
155+ * Check group not writable for reproducible archive.
156+ *
157+ * @throws IOException
158+ * @throws ParseException
159+ */
160+ @ Test
161+ public void testReproducibleUmask () throws IOException , ParseException {
162+ Path jarFile = Files .createTempFile (tempDir , "JarArchiverTest-umask" , ".jar" );
163+
164+ JarArchiver archiver = getJarArchiver ();
165+ archiver .setDestFile (jarFile .toFile ());
166+
167+ SimpleDateFormat isoFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ssXXX" );
168+ long parsedTime = isoFormat .parse ("2038-01-19T03:14:08Z" ).getTime ();
169+ FileTime lastModTime = FileTime .fromMillis (parsedTime );
170+
171+ archiver .configureReproducibleBuild (lastModTime );
172+
173+ archiver .addDirectory (new File ("src/test/resources/java-classes" ));
174+ archiver .addFile (new File ("src/test/resources/world-writable/foo.txt" ), "addFile.txt" );
175+
176+ archiver .createArchive ();
177+
178+ try (org .apache .commons .compress .archivers .zip .ZipFile zip =
179+ new org .apache .commons .compress .archivers .zip .ZipFile (jarFile .toFile ())) {
180+ Enumeration <? extends ZipArchiveEntry > entries = zip .getEntries ();
181+ while (entries .hasMoreElements ()) {
182+ ZipArchiveEntry entry = entries .nextElement ();
183+ int mode = entry .getUnixMode ();
184+ assertEquals (
185+ 0 ,
186+ mode & 0 _020 ,
187+ entry .getName () + " group should not be writable in reproducible mode: "
188+ + Integer .toOctalString (mode ));
189+ }
190+ }
191+ }
192+
151193 @ Override
152194 protected JarArchiver getJarArchiver () {
153195 return new JarArchiver ();
0 commit comments