mirror of
https://github.com/gotson/komga.git
synced 2026-05-08 12:35:30 +02:00
fix: improper json deserialization when missing mandatory fields
This commit is contained in:
parent
ebf94cbeea
commit
594194fafd
5 changed files with 99 additions and 4 deletions
|
|
@ -43,6 +43,9 @@ spring:
|
||||||
web:
|
web:
|
||||||
resources:
|
resources:
|
||||||
add-mappings: false
|
add-mappings: false
|
||||||
|
jackson:
|
||||||
|
deserialization:
|
||||||
|
FAIL_ON_NULL_FOR_PRIMITIVES: true
|
||||||
|
|
||||||
server:
|
server:
|
||||||
servlet.session.timeout: 7d
|
servlet.session.timeout: 7d
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,23 @@
|
||||||
package org.gotson.komga.infrastructure.metadata.mylar.dto
|
package org.gotson.komga.infrastructure.metadata.mylar.dto
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import com.fasterxml.jackson.databind.exc.MismatchedInputException
|
||||||
|
import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
|
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.assertj.core.api.Assertions.catchThrowable
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
import org.springframework.core.io.ClassPathResource
|
import org.springframework.core.io.ClassPathResource
|
||||||
|
import org.springframework.test.context.junit.jupiter.SpringExtension
|
||||||
|
|
||||||
class SeriesTest {
|
@ExtendWith(SpringExtension::class)
|
||||||
|
@SpringBootTest
|
||||||
private val mapper = ObjectMapper().registerKotlinModule()
|
class SeriesTest(
|
||||||
|
@Autowired private val mapper: ObjectMapper,
|
||||||
|
) {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given valid json file when deserializing then properties are available`() {
|
fun `given valid json file when deserializing then properties are available`() {
|
||||||
|
|
@ -60,4 +68,28 @@ class SeriesTest {
|
||||||
assertThat(status).isEqualTo(Status.Ended)
|
assertThat(status).isEqualTo(Status.Ended)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given invalid json file missing year when deserializing then it fails`() {
|
||||||
|
val file = ClassPathResource("mylar/series-missing-year.json")
|
||||||
|
val thrown = catchThrowable { mapper.readValue<Series>(file.url) }
|
||||||
|
|
||||||
|
assertThat(thrown).isInstanceOf(MismatchedInputException::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given invalid json file missing publisher when deserializing then it fails`() {
|
||||||
|
val file = ClassPathResource("mylar/series-missing-publisher.json")
|
||||||
|
val thrown = catchThrowable { mapper.readValue<Series>(file.url) }
|
||||||
|
|
||||||
|
assertThat(thrown).isInstanceOf(MissingKotlinParameterException::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given invalid json file missing status when deserializing then it fails`() {
|
||||||
|
val file = ClassPathResource("mylar/series-missing-status.json")
|
||||||
|
val thrown = catchThrowable { mapper.readValue<Series>(file.url) }
|
||||||
|
|
||||||
|
assertThat(thrown).isInstanceOf(MissingKotlinParameterException::class.java)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
komga/src/test/resources/mylar/series-missing-publisher.json
Executable file
20
komga/src/test/resources/mylar/series-missing-publisher.json
Executable file
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"version": "1.0.1",
|
||||||
|
"metadata": {
|
||||||
|
"type": "comicSeries",
|
||||||
|
"imprint": null,
|
||||||
|
"name": "Usagi Yojimbo",
|
||||||
|
"cid": 119731,
|
||||||
|
"year": 2019,
|
||||||
|
"description_text": null,
|
||||||
|
"description_formatted": null,
|
||||||
|
"volume": 4,
|
||||||
|
"booktype": "Print",
|
||||||
|
"age_rating": null,
|
||||||
|
"collects": null,
|
||||||
|
"ComicImage": "https://comicvine1.cbsistatic.com/uploads/scale_large/6/67663/6974029-01a.jpg",
|
||||||
|
"total_issues": 20,
|
||||||
|
"publication_run": "June 2019 - Present",
|
||||||
|
"status": "Ended"
|
||||||
|
}
|
||||||
|
}
|
||||||
20
komga/src/test/resources/mylar/series-missing-status.json
Executable file
20
komga/src/test/resources/mylar/series-missing-status.json
Executable file
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"version": "1.0.1",
|
||||||
|
"metadata": {
|
||||||
|
"type": "comicSeries",
|
||||||
|
"publisher": "IDW Publishing",
|
||||||
|
"imprint": null,
|
||||||
|
"name": "Usagi Yojimbo",
|
||||||
|
"cid": 119731,
|
||||||
|
"year": 2019,
|
||||||
|
"description_text": null,
|
||||||
|
"description_formatted": null,
|
||||||
|
"volume": 4,
|
||||||
|
"booktype": "Print",
|
||||||
|
"age_rating": null,
|
||||||
|
"collects": null,
|
||||||
|
"ComicImage": "https://comicvine1.cbsistatic.com/uploads/scale_large/6/67663/6974029-01a.jpg",
|
||||||
|
"total_issues": 20,
|
||||||
|
"publication_run": "June 2019 - Present"
|
||||||
|
}
|
||||||
|
}
|
||||||
20
komga/src/test/resources/mylar/series-missing-year.json
Executable file
20
komga/src/test/resources/mylar/series-missing-year.json
Executable file
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"version": "1.0.1",
|
||||||
|
"metadata": {
|
||||||
|
"type": "comicSeries",
|
||||||
|
"publisher": "IDW Publishing",
|
||||||
|
"imprint": null,
|
||||||
|
"name": "Usagi Yojimbo",
|
||||||
|
"cid": 119731,
|
||||||
|
"description_text": null,
|
||||||
|
"description_formatted": null,
|
||||||
|
"volume": 4,
|
||||||
|
"booktype": "Print",
|
||||||
|
"age_rating": null,
|
||||||
|
"collects": null,
|
||||||
|
"ComicImage": "https://comicvine1.cbsistatic.com/uploads/scale_large/6/67663/6974029-01a.jpg",
|
||||||
|
"total_issues": 20,
|
||||||
|
"publication_run": "June 2019 - Present",
|
||||||
|
"status": "Ended"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue