fix(koreader): also accept application/json on Accept header

This commit is contained in:
Gauthier Roebroeck 2026-04-21 16:33:45 +08:00
parent 4a7d9a6510
commit ddfe65dde1
2 changed files with 19 additions and 1 deletions

View file

@ -14,6 +14,7 @@ import org.gotson.komga.infrastructure.security.KomgaPrincipal
import org.gotson.komga.interfaces.api.kosync.dto.DocumentProgressDto
import org.gotson.komga.interfaces.api.kosync.dto.UserAuthenticationDto
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.GetMapping
@ -29,7 +30,7 @@ import java.time.ZonedDateTime
private val logger = KotlinLogging.logger {}
@RestController
@RequestMapping("/koreader", produces = ["application/vnd.koreader.v1+json"])
@RequestMapping("/koreader", produces = [MediaType.APPLICATION_JSON_VALUE, "application/vnd.koreader.v1+json"])
class KoreaderSyncController(
private val bookRepository: BookRepository,
private val mediaRepository: MediaRepository,

View file

@ -7,9 +7,13 @@ import org.gotson.komga.domain.service.KomgaUserLifecycle
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.get
import org.springframework.test.web.servlet.post
@ -68,4 +72,17 @@ class KoreaderSyncControllerTest(
jsonPath("authorized") { value("OK") }
}
}
@ParameterizedTest
@ValueSource(strings = [MediaType.APPLICATION_JSON_VALUE, "application/vnd.koreader.v1+json"])
fun `given accept header when calling API user then returns OK`(acceptHeader: String) {
mockMvc
.get("/koreader/users/auth") {
header("x-auth-user", apiKey)
header(HttpHeaders.ACCEPT, acceptHeader)
}.andExpect {
status { isOk() }
jsonPath("authorized") { value("OK") }
}
}
}