Merge branch '2.1.x' into 2.2.x
Closes gh-23263
This commit is contained in:
@@ -51,6 +51,7 @@ import org.springframework.boot.loader.TestJarCreator;
|
||||
import org.springframework.boot.loader.data.RandomAccessDataFile;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -397,29 +398,33 @@ class JarFileTests {
|
||||
|
||||
@Test
|
||||
void verifySignedJar() throws Exception {
|
||||
String classpath = System.getProperty("java.class.path");
|
||||
String[] entries = classpath.split(System.getProperty("path.separator"));
|
||||
String signedJarFile = null;
|
||||
File signedJarFile = getSignedJarFile();
|
||||
assertThat(signedJarFile).exists();
|
||||
try (java.util.jar.JarFile expected = new java.util.jar.JarFile(signedJarFile)) {
|
||||
try (JarFile actual = new JarFile(signedJarFile)) {
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
Enumeration<JarEntry> actualEntries = actual.entries();
|
||||
while (actualEntries.hasMoreElements()) {
|
||||
JarEntry actualEntry = actualEntries.nextElement();
|
||||
java.util.jar.JarEntry expectedEntry = expected.getJarEntry(actualEntry.getName());
|
||||
assertThat(actualEntry.getCertificates()).as(actualEntry.getName())
|
||||
.isEqualTo(expectedEntry.getCertificates());
|
||||
assertThat(actualEntry.getCodeSigners()).as(actualEntry.getName())
|
||||
.isEqualTo(expectedEntry.getCodeSigners());
|
||||
}
|
||||
assertThat(stopWatch.getTotalTimeSeconds()).isLessThan(3.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private File getSignedJarFile() {
|
||||
String[] entries = System.getProperty("java.class.path").split(System.getProperty("path.separator"));
|
||||
for (String entry : entries) {
|
||||
if (entry.contains("bcprov")) {
|
||||
signedJarFile = entry;
|
||||
return new File(entry);
|
||||
}
|
||||
}
|
||||
assertThat(signedJarFile).isNotNull();
|
||||
java.util.jar.JarFile jarFile = new JarFile(new File(signedJarFile));
|
||||
jarFile.getManifest();
|
||||
Enumeration<JarEntry> jarEntries = jarFile.entries();
|
||||
while (jarEntries.hasMoreElements()) {
|
||||
JarEntry jarEntry = jarEntries.nextElement();
|
||||
InputStream inputStream = jarFile.getInputStream(jarEntry);
|
||||
inputStream.skip(Long.MAX_VALUE);
|
||||
inputStream.close();
|
||||
if (!jarEntry.getName().startsWith("META-INF") && !jarEntry.isDirectory()
|
||||
&& !jarEntry.getName().endsWith("TigerDigest.class")) {
|
||||
assertThat(jarEntry.getCertificates()).isNotNull();
|
||||
}
|
||||
}
|
||||
jarFile.close();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user