Skip to content

Commit

Permalink
fix: Reject JSON with duplicate keys (#2073)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrozev authored Nov 29, 2023
1 parent 814bffd commit 73fb0cf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.JsonMappingException
import com.fasterxml.jackson.databind.MapperFeature
Expand Down Expand Up @@ -86,6 +87,7 @@ sealed class BridgeChannelMessage {
companion object {
private val mapper = jacksonObjectMapper().apply {
enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION)
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.jitsi.videobridge.message

import com.fasterxml.jackson.core.JsonParseException
import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.exc.InvalidTypeIdException
Expand Down Expand Up @@ -65,6 +66,49 @@ class BridgeChannelMessageTest : ShouldSpec() {
shouldThrow<InvalidTypeIdException> {
parse("""{"colibriClass": "invalid-colibri-class" }""")
}
shouldThrow<JsonParseException> {
parse(
"""
{
"colibriClass": "EndpointStats",
"colibriClass": "duplicate"
}
""".trimIndent()
)
}
shouldThrow<JsonParseException> {
parse(
"""
{
"colibriClass": "EndpointStats",
"to": "a",
"to": "b"
}
""".trimIndent()
)
}
shouldThrow<JsonParseException> {
parse(
"""
{
"colibriClass": "EndpointStats",
"from": "a",
"from": "b"
}
""".trimIndent()
)
}
shouldThrow<JsonParseException> {
parse(
"""
{
"colibriClass": "EndpointStats",
"non-defined-prop": "a",
"non-defined-prop": "b"
}
""".trimIndent()
)
}

context("when some of the message-specific fields are missing/invalid") {
shouldThrow<JsonProcessingException> {
Expand Down

0 comments on commit 73fb0cf

Please sign in to comment.