14
14
import java .util .zip .ZipEntry ;
15
15
import java .util .zip .ZipFile ;
16
16
17
+ import org .apache .commons .compress .archivers .zip .ZipArchiveEntry ;
17
18
import org .codehaus .plexus .archiver .ArchiverException ;
18
19
import org .junit .jupiter .api .Test ;
19
20
import org .junit .jupiter .api .io .TempDir ;
@@ -123,14 +124,16 @@ private void createReproducibleBuild(String timeZoneId) throws IOException, Mani
123
124
124
125
JarArchiver archiver = getJarArchiver ();
125
126
archiver .setDestFile (jarFile .toFile ());
126
- archiver .addConfiguredManifest (manifest );
127
- archiver .addDirectory (new File ("src/test/resources/java-classes" ));
128
127
129
128
SimpleDateFormat isoFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ssXXX" );
130
129
long parsedTime = isoFormat .parse ("2038-01-19T03:14:08Z" ).getTime ();
131
130
FileTime lastModTime = FileTime .fromMillis (parsedTime );
132
131
133
132
archiver .configureReproducibleBuild (lastModTime );
133
+
134
+ archiver .addConfiguredManifest (manifest );
135
+ archiver .addDirectory (new File ("src/test/resources/java-classes" ));
136
+
134
137
archiver .createArchive ();
135
138
136
139
// zip 2 seconds precision, normalized to UTC
@@ -148,6 +151,45 @@ private void createReproducibleBuild(String timeZoneId) throws IOException, Mani
148
151
}
149
152
}
150
153
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
+
151
193
@ Override
152
194
protected JarArchiver getJarArchiver () {
153
195
return new JarArchiver ();
0 commit comments