mirror of https://github.com/usbharu/Hideout.git
fix: なぜか必ずJsonを返すようになっていたので修正
This commit is contained in:
parent
97c18b0754
commit
bd927677a0
|
@ -37,8 +37,7 @@ class ContentTypeRouteSelector(private vararg val contentType: ContentType) : Ro
|
||||||
val requestContentType =
|
val requestContentType =
|
||||||
ContentType.parse(context.call.request.accept() ?: return RouteSelectorEvaluation.FailedParameter)
|
ContentType.parse(context.call.request.accept() ?: return RouteSelectorEvaluation.FailedParameter)
|
||||||
|
|
||||||
return if (contentType.find { contentType: ContentType -> contentType.match(requestContentType) }
|
return if (contentType.find { contentType: ContentType -> contentType.match(requestContentType) } != null) {
|
||||||
.let { true }) {
|
|
||||||
RouteSelectorEvaluation.Constant
|
RouteSelectorEvaluation.Constant
|
||||||
} else {
|
} else {
|
||||||
RouteSelectorEvaluation.FailedParameter
|
RouteSelectorEvaluation.FailedParameter
|
||||||
|
|
|
@ -9,6 +9,7 @@ import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import dev.usbharu.hideout.domain.model.ap.Image
|
import dev.usbharu.hideout.domain.model.ap.Image
|
||||||
import dev.usbharu.hideout.domain.model.ap.Key
|
import dev.usbharu.hideout.domain.model.ap.Key
|
||||||
import dev.usbharu.hideout.domain.model.ap.Person
|
import dev.usbharu.hideout.domain.model.ap.Person
|
||||||
|
import dev.usbharu.hideout.domain.model.hideout.entity.User
|
||||||
import dev.usbharu.hideout.plugins.configureRouting
|
import dev.usbharu.hideout.plugins.configureRouting
|
||||||
import dev.usbharu.hideout.plugins.configureSerialization
|
import dev.usbharu.hideout.plugins.configureSerialization
|
||||||
import dev.usbharu.hideout.service.activitypub.ActivityPubService
|
import dev.usbharu.hideout.service.activitypub.ActivityPubService
|
||||||
|
@ -25,7 +26,9 @@ import io.ktor.server.testing.*
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.ArgumentMatchers.anyString
|
import org.mockito.ArgumentMatchers.anyString
|
||||||
import org.mockito.kotlin.doReturn
|
import org.mockito.kotlin.doReturn
|
||||||
|
import org.mockito.kotlin.eq
|
||||||
import org.mockito.kotlin.mock
|
import org.mockito.kotlin.mock
|
||||||
|
import java.time.Instant
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
@ -168,7 +171,47 @@ class UsersAPTest {
|
||||||
// @Disabled
|
// @Disabled
|
||||||
fun contentType_Test() {
|
fun contentType_Test() {
|
||||||
val listOf = listOf(ContentType.Application.JsonLd, ContentType.Application.Activity)
|
val listOf = listOf(ContentType.Application.JsonLd, ContentType.Application.Activity)
|
||||||
assertTrue(listOf.find { contentType -> contentType.match("application/ld+json; profile=\"\\\"https://www.w3.org/ns/activitystreams\\\",application/activity+json\"") }.let { true })
|
assertTrue(listOf.find { contentType ->
|
||||||
|
contentType.match("application/ld+json; profile=\"\\\"https://www.w3.org/ns/activitystreams\\\",application/activity+json\"")
|
||||||
|
}.let { it != null })
|
||||||
assertTrue(ContentType.Application.JsonLd.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""))
|
assertTrue(ContentType.Application.JsonLd.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ユーザーのURLにAcceptヘッダーをhtmlにしてアクセスしたときはただの文字を返す() = testApplication {
|
||||||
|
environment {
|
||||||
|
config = ApplicationConfig("empty.conf")
|
||||||
|
}
|
||||||
|
val userService = mock<IUserService> {
|
||||||
|
onBlocking { findByNameLocalUser(eq("test")) } doReturn User(
|
||||||
|
1L,
|
||||||
|
"test",
|
||||||
|
"example.com",
|
||||||
|
"test",
|
||||||
|
"",
|
||||||
|
"hashedPassword",
|
||||||
|
"https://example.com/inbox",
|
||||||
|
"https://example.com/outbox",
|
||||||
|
"https://example.com",
|
||||||
|
"-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----",
|
||||||
|
"-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----",
|
||||||
|
Instant.now()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
application {
|
||||||
|
configureRouting(
|
||||||
|
mock(),
|
||||||
|
mock(),
|
||||||
|
userService,
|
||||||
|
mock(),
|
||||||
|
mock()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
client.get("/users/test") {
|
||||||
|
accept(ContentType.Text.Html)
|
||||||
|
}.let {
|
||||||
|
assertEquals(HttpStatusCode.OK, it.status)
|
||||||
|
assertTrue(it.contentType()?.match(ContentType.Text.Plain) == true)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue