Skip to content

Commit

Permalink
fix: disable entity content validation as it breaks a lot of use-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bobeal committed Sep 1, 2023
1 parent f776a3b commit eb06254
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ private fun Any.checkContentIsNgsiLdSupported(): Either<APIException, Unit> =
} else Unit.right()

/**
* Relaxed list of forbidden characters in entity content defined in 4.6.4. Full list prevents from a lot of use-cases.
* List of forbidden characters in entity content as defined in 4.6.4. Currently disabled as it prevents
* from a lot of use-cases.
*/
private val invalidCharactersForValues = ">\"".toCharArray()
// private val invalidCharactersForValues = "<>\"'=()".toCharArray()
private val invalidCharactersForValues = "".toCharArray()

/**
* Returns whether the given string is a supported content as defined in 4.6.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,93 +155,6 @@ class DataRepresentationUtilsTests {
}
}

@Test
fun `it should not validate an entity with an invalid content in attribute value`() = runTest {
val rawEntity =
"""
{
"id": "urn:ngsi-ld:Device:01234",
"type": "Device",
"device": {
"type": "Property",
"value": "23>=23"
}
}
""".trimIndent()

rawEntity.deserializeAsMap().checkContentIsNgsiLdSupported()
.shouldFail {
assertInstanceOf(BadRequestDataException::class.java, it)
assertEquals(
"The JSON-LD object contains a member with invalid characters in value (4.6.4): 23>=23",
it.message
)
}
}

@Test
fun `it should not validate an entity with an invalid content in sub-attribute value`() = runTest {
val rawEntity =
"""
{
"id": "urn:ngsi-ld:Device:01234",
"type": "Device",
"device": {
"type": "Property",
"value": 23,
"subAttribute": {
"type": "Property",
"value": "23>=23"
}
}
}
""".trimIndent()

rawEntity.deserializeAsMap().checkContentIsNgsiLdSupported()
.shouldFail {
assertInstanceOf(BadRequestDataException::class.java, it)
assertEquals(
"The JSON-LD object contains a member with invalid characters in value (4.6.4): 23>=23",
it.message
)
}
}

@Test
fun `it should not validate an entity with an invalid content in a multi-attribute`() = runTest {
val rawEntity =
"""
{
"id": "urn:ngsi-ld:Device:01234",
"type": "Device",
"device": [{
"type": "Property",
"value": 23,
"state": {
"type": "Property",
"value": "open>open;"
}
},{
"type": "Property",
"value": 23,
"state": {
"type": "Property",
"value": "open"
}
}]
}
""".trimIndent()

rawEntity.deserializeAsMap().checkContentIsNgsiLdSupported()
.shouldFail {
assertInstanceOf(BadRequestDataException::class.java, it)
assertEquals(
"The JSON-LD object contains a member with invalid characters in value (4.6.4): open>open;",
it.message
)
}
}

@Test
fun `it should not validate an entity with a null value`() = runTest {
val rawEntity =
Expand Down

0 comments on commit eb06254

Please sign in to comment.