ENT-12291: RotatedKeys can be retrieved from MockServices.

This commit is contained in:
Adel El-Beik 2024-10-10 12:49:46 +01:00
parent a2537d59f5
commit 4c0aa16f1e
2 changed files with 19 additions and 1 deletions

View File

@ -1,16 +1,31 @@
package net.corda.coretests.contracts
import net.corda.core.contracts.CordaRotatedKeys
import net.corda.core.contracts.RotatedKeys
import net.corda.core.crypto.CompositeKey
import net.corda.core.crypto.sha256
import net.corda.core.identity.CordaX500Name
import net.corda.core.internal.hash
import net.corda.core.internal.retrieveRotatedKeys
import net.corda.core.node.ServiceHub
import net.corda.testing.core.TestIdentity
import net.corda.testing.core.internal.JarSignatureTestUtils.generateKey
import net.corda.testing.core.internal.SelfCleaningDir
import net.corda.testing.node.MockServices
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class RotatedKeysTest {
@Test(timeout = 300_000)
fun `validateDefaultRotatedKeysAreRetrievableFromMockServices`() {
val services: ServiceHub = MockServices(TestIdentity(CordaX500Name("MegaCorp", "London", "GB")))
val rotatedKeys = services.retrieveRotatedKeys()
assertEquals( CordaRotatedKeys.keys.rotatedSigningKeys, rotatedKeys.rotatedSigningKeys)
}
@Test(timeout = 300_000)
fun `when input and output keys are the same canBeTransitioned returns true`() {
SelfCleaningDir().use { file ->

View File

@ -13,6 +13,7 @@ import net.corda.core.node.ServicesForResolution
import net.corda.core.serialization.*
import net.corda.core.transactions.*
import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.contextLogger
import java.io.ByteArrayOutputStream
import java.security.PublicKey
import kotlin.reflect.KClass
@ -27,7 +28,9 @@ fun ServiceHub.retrieveRotatedKeys(): RotatedKeys {
if (clazz.name == "net.corda.testing.node.MockServices") {
return clazz.getDeclaredMethod("getRotatedKeys").apply { isAccessible = true }.invoke(this) as RotatedKeys
}
clazz = clazz.superclass ?: throw ClassCastException("${javaClass.name} is not a ServiceHub")
clazz = clazz.superclass ?: return CordaRotatedKeys.keys.also {
this.contextLogger().warn("${javaClass.name} is not a MockServices instance - returning default rotated keys")
}
}
}