From afcab51fe3dee766831cd912d08b5429fbf0d3ab Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Tue, 11 Feb 2020 22:59:53 +0000 Subject: [PATCH] Update "in-process" test on basis it can be made to work. --- .../corda/core/internal/ClassLoadingUtils.kt | 1 - .../ContractWithSerializationWhitelistTest.kt | 51 +++++++------------ .../cordapp/JarScanningCordappLoader.kt | 29 ++--------- 3 files changed, 22 insertions(+), 59 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/internal/ClassLoadingUtils.kt b/core/src/main/kotlin/net/corda/core/internal/ClassLoadingUtils.kt index 72070a46ed..fbe359c55d 100644 --- a/core/src/main/kotlin/net/corda/core/internal/ClassLoadingUtils.kt +++ b/core/src/main/kotlin/net/corda/core/internal/ClassLoadingUtils.kt @@ -36,7 +36,6 @@ fun getNamesOfClassesImplementing(classloader: ClassLoader, clazz: Clas return ClassGraph().overrideClassLoaders(classloader) .enableURLScheme(attachmentScheme) .ignoreParentClassLoaders() - .disableDirScanning() .enableClassInfo() .pooledScan() .use { result -> diff --git a/node/src/integration-test/kotlin/net/corda/node/ContractWithSerializationWhitelistTest.kt b/node/src/integration-test/kotlin/net/corda/node/ContractWithSerializationWhitelistTest.kt index e031a046ab..2a9ae80195 100644 --- a/node/src/integration-test/kotlin/net/corda/node/ContractWithSerializationWhitelistTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/ContractWithSerializationWhitelistTest.kt @@ -5,6 +5,7 @@ import net.corda.contracts.serialization.whitelist.WhitelistData import net.corda.core.contracts.TransactionVerificationException.ContractRejection import net.corda.core.messaging.startFlow import net.corda.core.utilities.getOrThrow +import net.corda.core.utilities.loggerFor import net.corda.flows.serialization.whitelist.WhitelistFlow import net.corda.node.services.Permissions import net.corda.testing.core.ALICE_NAME @@ -18,13 +19,20 @@ import net.corda.testing.node.internal.cordappWithPackages import org.assertj.core.api.Assertions.assertThat import org.junit.BeforeClass import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.Parameterized +import org.junit.runners.Parameterized.Parameters import kotlin.test.assertFailsWith +@RunWith(Parameterized::class) @Suppress("FunctionName") -class ContractWithSerializationWhitelistTest { +class ContractWithSerializationWhitelistTest(private val runInProcess: Boolean) { companion object { const val DATA = 123456L + @JvmField + val logger = loggerFor() + @JvmField val contractCordapp = cordappWithPackages("net.corda.contracts.serialization.whitelist").signed() @@ -40,6 +48,10 @@ class ContractWithSerializationWhitelistTest { ) } + @Parameters + @JvmStatic + fun modes(): List> = listOf(Array(1) { true }, Array(1) { false }) + @BeforeClass @JvmStatic fun checkData() { @@ -47,10 +59,12 @@ class ContractWithSerializationWhitelistTest { } } - @Test - fun `test serialization whitelist out-of-process`() { + @Test(timeout = 300_000) + fun `test serialization whitelist`() { + logger.info("RUN-IN-PROCESS=$runInProcess") + val user = User("u", "p", setOf(Permissions.all())) - driver(parametersFor(runInProcess = false)) { + driver(parametersFor(runInProcess = runInProcess)) { val badData = WhitelistData(DATA) val alice = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user)).getOrThrow() val ex = assertFailsWith { @@ -66,31 +80,4 @@ class ContractWithSerializationWhitelistTest { .hasMessageContaining("WhitelistData $badData exceeds maximum value!") } } - - @Test - fun `test serialization whitelist in-process`() { - val user = User("u", "p", setOf(Permissions.all())) - driver(parametersFor(runInProcess = true)) { - val badData = WhitelistData(DATA) - val alice = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user)).getOrThrow() - val ex = assertFailsWith { - CordaRPCClient(hostAndPort = alice.rpcAddress) - .start(user.username, user.password) - .use { client -> - client.proxy.startFlow(::WhitelistFlow, badData) - .returnValue - .getOrThrow() - } - } - assertThat(ex) - .hasMessageContaining("WhitelistData $badData exceeds maximum value!") - } - } - -// @Test -// fun `test serialization whitelist in-process`() { -// assertFailsWith { -// driver(parametersFor(runInProcess = true)) {} -// } -// } -} \ No newline at end of file +} diff --git a/node/src/main/kotlin/net/corda/node/internal/cordapp/JarScanningCordappLoader.kt b/node/src/main/kotlin/net/corda/node/internal/cordapp/JarScanningCordappLoader.kt index ce2a6544fe..0eba7d18ad 100644 --- a/node/src/main/kotlin/net/corda/node/internal/cordapp/JarScanningCordappLoader.kt +++ b/node/src/main/kotlin/net/corda/node/internal/cordapp/JarScanningCordappLoader.kt @@ -270,26 +270,10 @@ class JarScanningCordappLoader private constructor(private val cordappJarPaths: private fun findWhitelists(cordappJarPath: RestrictedURL): List { val whitelists = URLClassLoader(arrayOf(cordappJarPath.url)).use { ServiceLoader.load(SerializationWhitelist::class.java, it).toList() - }.filter { - it.javaClass.name.startsWith(cordappJarPath.qualifiedNamePrefix) && it.javaClass.location == cordappJarPath.url } - - whitelists.filterNot { - it.javaClass.location == cordappJarPath.url - }.apply { - if (isNotEmpty()) { - throw NotCordappWhitelist("Whitelists ${showClasses(this)} not found within ${cordappJarPath.url}") - } - } - return whitelists + DefaultWhitelist // Always add the DefaultWhitelist to the whitelist for an app. - } - - private fun showClasses(items: Iterable): String { - return items.map { - it::class.java - }.map { - "${it.name} in ${it.protectionDomain.codeSource.location}" - }.toString() + return whitelists.filter { + it.javaClass.location == cordappJarPath.url && it.javaClass.name.startsWith(cordappJarPath.qualifiedNamePrefix) + } + DefaultWhitelist // Always add the DefaultWhitelist to the whitelist for an app. } private fun findSerializers(scanResult: RestrictedScanResult): List> { @@ -397,13 +381,6 @@ class JarScanningCordappLoader private constructor(private val cordappJarPaths: */ class MultipleCordappsForFlowException(message: String) : Exception(message) -/** - * Thrown when a [SerializationWhitelist] is loaded from outside the CorDapp. - * Most likely because you are testing with node-driver and "in-process" nodes. - * Try using "out-of-process" driver nodes instead. - */ -class NotCordappWhitelist(message: String) : Exception(message) - /** * Thrown if an exception occurs whilst parsing version identifiers within cordapp configuration */