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:
Chris Rankin
2017-10-11 11:17:14 +01:00
committed by GitHub
parent ef0f0acc4a
commit 9cec137a31
2 changed files with 41 additions and 4 deletions

View File

@ -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)