mirror of
https://github.com/corda/corda.git
synced 2025-06-18 15:18:16 +00:00
CORDA-702: Don't whitelist certain non-annotated types (#1864)
* Don't whitelist arrays of non-serialisable types for RPC. * Don't whitelist enums which have not been annotated as serialisable.
This commit is contained in:
@ -34,6 +34,23 @@ enum class Foo {
|
||||
abstract val value: Int
|
||||
}
|
||||
|
||||
enum class BadFood {
|
||||
Mud {
|
||||
override val value = -1
|
||||
};
|
||||
|
||||
abstract val value: Int
|
||||
}
|
||||
|
||||
@CordaSerializable
|
||||
enum class Simple {
|
||||
Easy
|
||||
}
|
||||
|
||||
enum class BadSimple {
|
||||
Nasty
|
||||
}
|
||||
|
||||
@CordaSerializable
|
||||
open class Element
|
||||
|
||||
@ -106,17 +123,36 @@ class CordaClassResolverTests {
|
||||
|
||||
@Test
|
||||
fun `Annotation on enum works for specialised entries`() {
|
||||
// TODO: Remove this suppress when we upgrade to kotlin 1.1 or when JetBrain fixes the bug.
|
||||
@Suppress("UNSUPPORTED_FEATURE")
|
||||
CordaClassResolver(emptyWhitelistContext).getRegistration(Foo.Bar::class.java)
|
||||
}
|
||||
|
||||
@Test(expected = KryoException::class)
|
||||
fun `Unannotated specialised enum does not work`() {
|
||||
CordaClassResolver(emptyWhitelistContext).getRegistration(BadFood.Mud::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Annotation on simple enum works`() {
|
||||
CordaClassResolver(emptyWhitelistContext).getRegistration(Simple.Easy::class.java)
|
||||
}
|
||||
|
||||
@Test(expected = KryoException::class)
|
||||
fun `Unannotated simple enum does not work`() {
|
||||
CordaClassResolver(emptyWhitelistContext).getRegistration(BadSimple.Nasty::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Annotation on array element works`() {
|
||||
val values = arrayOf(Element())
|
||||
CordaClassResolver(emptyWhitelistContext).getRegistration(values.javaClass)
|
||||
}
|
||||
|
||||
@Test(expected = KryoException::class)
|
||||
fun `Unannotated array elements do not work`() {
|
||||
val values = arrayOf(NotSerializable())
|
||||
CordaClassResolver(emptyWhitelistContext).getRegistration(values.javaClass)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Annotation not needed on abstract class`() {
|
||||
CordaClassResolver(emptyWhitelistContext).getRegistration(AbstractClass::class.java)
|
||||
|
Reference in New Issue
Block a user