diff --git a/node/src/test/kotlin/net/corda/node/internal/cordapp/CordappProviderImplTests.kt b/node/src/test/kotlin/net/corda/node/internal/cordapp/CordappProviderImplTests.kt index f981b11e24..2bd8a10258 100644 --- a/node/src/test/kotlin/net/corda/node/internal/cordapp/CordappProviderImplTests.kt +++ b/node/src/test/kotlin/net/corda/node/internal/cordapp/CordappProviderImplTests.kt @@ -18,6 +18,7 @@ import java.io.FileOutputStream import java.lang.IllegalStateException import java.net.URL import java.nio.file.Files +import java.util.Arrays.asList import java.util.jar.JarOutputStream import java.util.zip.Deflater.NO_COMPRESSION import java.util.zip.ZipEntry @@ -200,8 +201,11 @@ class CordappProviderImplTests { val duplicateJarPath = signedJarPath.parent.resolve("duplicate-" + signedJarPath.fileName) Files.copy(signedJarPath, duplicateJarPath) - assertFailsWith { - newCordappProvider(signedJarPath.toUri().toURL(), duplicateJarPath.toUri().toURL()) + val urls = asList(signedJarPath.toUri().toURL(), duplicateJarPath.toUri().toURL()) + JarScanningCordappLoader.fromJarUrls(urls, VersionInfo.UNKNOWN).use { + assertFailsWith { + CordappProviderImpl(it, stubConfigProvider, attachmentStore).apply { start() } + } } } } @@ -212,8 +216,11 @@ class CordappProviderImplTests { SelfCleaningDir().use { file -> val jarA = ContractJarTestUtils.makeTestContractJar(file.path, listOf("com.example.MyContract", "com.example.AnotherContractForA"), generateManifest = false, jarFileName = "sampleA.jar") val jarB = ContractJarTestUtils.makeTestContractJar(file.path, listOf("com.example.MyContract", "com.example.AnotherContractForB"), generateManifest = false, jarFileName = "sampleB.jar") - assertFailsWith { - newCordappProvider(jarA.toUri().toURL(), jarB.toUri().toURL()) + val urls = asList(jarA.toUri().toURL(), jarB.toUri().toURL()) + JarScanningCordappLoader.fromJarUrls(urls, VersionInfo.UNKNOWN).use { + assertFailsWith { + CordappProviderImpl(it, stubConfigProvider, attachmentStore).apply { start() } + } } } } diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/core/internal/JarSignatureTestUtils.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/core/internal/JarSignatureTestUtils.kt index 00a827c1e1..4c21340f84 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/core/internal/JarSignatureTestUtils.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/core/internal/JarSignatureTestUtils.kt @@ -12,6 +12,7 @@ import java.nio.file.Files import java.nio.file.NoSuchFileException import java.nio.file.Path import java.nio.file.Paths +import java.nio.file.StandardCopyOption.REPLACE_EXISTING import java.security.PublicKey import java.util.jar.Attributes import java.util.jar.JarInputStream @@ -88,12 +89,13 @@ object JarSignatureTestUtils { JarInputStream(FileInputStream((this / fileName).toFile())).use(JarSignatureCollector::collectSigners) fun Path.addManifest(fileName: String, vararg entries: Pair) { + val outputFile = this / (fileName + "Output") JarInputStream(FileInputStream((this / fileName).toFile())).use { input -> val manifest = input.manifest ?: Manifest() entries.forEach { (attributeName, value) -> manifest.mainAttributes[attributeName] = value } - val output = JarOutputStream(FileOutputStream((this / fileName).toFile()), manifest) + val output = JarOutputStream(FileOutputStream(outputFile.toFile()), manifest) var entry = input.nextEntry val buffer = ByteArray(1 shl 14) while (true) { @@ -108,5 +110,6 @@ object JarSignatureTestUtils { } output.close() } + Files.copy(outputFile, this / fileName, REPLACE_EXISTING) } }