diff --git a/komga/src/main/resources/application.yml b/komga/src/main/resources/application.yml index b60a59413..b5861ab92 100644 --- a/komga/src/main/resources/application.yml +++ b/komga/src/main/resources/application.yml @@ -43,6 +43,9 @@ spring: web: resources: add-mappings: false + jackson: + deserialization: + FAIL_ON_NULL_FOR_PRIMITIVES: true server: servlet.session.timeout: 7d diff --git a/komga/src/test/kotlin/org/gotson/komga/infrastructure/metadata/mylar/dto/SeriesTest.kt b/komga/src/test/kotlin/org/gotson/komga/infrastructure/metadata/mylar/dto/SeriesTest.kt index 5e1e27a4d..01fcd4500 100644 --- a/komga/src/test/kotlin/org/gotson/komga/infrastructure/metadata/mylar/dto/SeriesTest.kt +++ b/komga/src/test/kotlin/org/gotson/komga/infrastructure/metadata/mylar/dto/SeriesTest.kt @@ -1,15 +1,23 @@ package org.gotson.komga.infrastructure.metadata.mylar.dto 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.registerKotlinModule 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.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.test.context.junit.jupiter.SpringExtension -class SeriesTest { - - private val mapper = ObjectMapper().registerKotlinModule() +@ExtendWith(SpringExtension::class) +@SpringBootTest +class SeriesTest( + @Autowired private val mapper: ObjectMapper, +) { @Test fun `given valid json file when deserializing then properties are available`() { @@ -60,4 +68,28 @@ class SeriesTest { 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(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(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(file.url) } + + assertThat(thrown).isInstanceOf(MissingKotlinParameterException::class.java) + } } diff --git a/komga/src/test/resources/mylar/series-missing-publisher.json b/komga/src/test/resources/mylar/series-missing-publisher.json new file mode 100755 index 000000000..2c951ecfa --- /dev/null +++ b/komga/src/test/resources/mylar/series-missing-publisher.json @@ -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" + } +} diff --git a/komga/src/test/resources/mylar/series-missing-status.json b/komga/src/test/resources/mylar/series-missing-status.json new file mode 100755 index 000000000..a1559fa13 --- /dev/null +++ b/komga/src/test/resources/mylar/series-missing-status.json @@ -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" + } +} diff --git a/komga/src/test/resources/mylar/series-missing-year.json b/komga/src/test/resources/mylar/series-missing-year.json new file mode 100755 index 000000000..3484f04f8 --- /dev/null +++ b/komga/src/test/resources/mylar/series-missing-year.json @@ -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" + } +}