mirror of
https://github.com/corda/corda.git
synced 2025-04-07 11:27:01 +00:00
Update "in-process" test on basis it can be made to work.
This commit is contained in:
parent
d89ce6608a
commit
afcab51fe3
@ -36,7 +36,6 @@ fun <T: Any> getNamesOfClassesImplementing(classloader: ClassLoader, clazz: Clas
|
||||
return ClassGraph().overrideClassLoaders(classloader)
|
||||
.enableURLScheme(attachmentScheme)
|
||||
.ignoreParentClassLoaders()
|
||||
.disableDirScanning()
|
||||
.enableClassInfo()
|
||||
.pooledScan()
|
||||
.use { result ->
|
||||
|
@ -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<ContractWithSerializationWhitelistTest>()
|
||||
|
||||
@JvmField
|
||||
val contractCordapp = cordappWithPackages("net.corda.contracts.serialization.whitelist").signed()
|
||||
|
||||
@ -40,6 +48,10 @@ class ContractWithSerializationWhitelistTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Parameters
|
||||
@JvmStatic
|
||||
fun modes(): List<Array<Boolean>> = 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<ContractRejection> {
|
||||
@ -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<ContractRejection> {
|
||||
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<NotCordappWhitelist> {
|
||||
// driver(parametersFor(runInProcess = true)) {}
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -270,26 +270,10 @@ class JarScanningCordappLoader private constructor(private val cordappJarPaths:
|
||||
private fun findWhitelists(cordappJarPath: RestrictedURL): List<SerializationWhitelist> {
|
||||
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<Any>): 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<SerializationCustomSerializer<*, *>> {
|
||||
@ -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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user