mirror of https://github.com/usbharu/Hideout.git
feat: Acceptヘッダーのログを追加
This commit is contained in:
parent
c61710f476
commit
1f4df77f98
|
@ -35,8 +35,11 @@ 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)
|
||||||
context.call.application.log.debug("Content-Type: {}", contentType)
|
context.call.application.log.debug("Content-Type: {}", requestContentType)
|
||||||
return if (contentType.any { contentType -> contentType.match(requestContentType) }) {
|
return if (contentType.any { contentType ->
|
||||||
|
context.call.application.log.debug(contentType.toString())
|
||||||
|
contentType.match(requestContentType)
|
||||||
|
}) {
|
||||||
RouteSelectorEvaluation.Constant
|
RouteSelectorEvaluation.Constant
|
||||||
} else {
|
} else {
|
||||||
RouteSelectorEvaluation.FailedParameter
|
RouteSelectorEvaluation.FailedParameter
|
||||||
|
|
|
@ -14,19 +14,21 @@ import dev.usbharu.hideout.plugins.configureSerialization
|
||||||
import dev.usbharu.hideout.service.activitypub.ActivityPubService
|
import dev.usbharu.hideout.service.activitypub.ActivityPubService
|
||||||
import dev.usbharu.hideout.service.activitypub.ActivityPubUserService
|
import dev.usbharu.hideout.service.activitypub.ActivityPubUserService
|
||||||
import dev.usbharu.hideout.service.impl.IUserService
|
import dev.usbharu.hideout.service.impl.IUserService
|
||||||
import dev.usbharu.hideout.service.impl.UserService
|
|
||||||
import dev.usbharu.hideout.service.signature.HttpSignatureVerifyService
|
import dev.usbharu.hideout.service.signature.HttpSignatureVerifyService
|
||||||
import dev.usbharu.hideout.util.HttpUtil.Activity
|
import dev.usbharu.hideout.util.HttpUtil.Activity
|
||||||
|
import dev.usbharu.hideout.util.HttpUtil.JsonLd
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.statement.*
|
import io.ktor.client.statement.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.server.config.*
|
import io.ktor.server.config.*
|
||||||
import io.ktor.server.testing.*
|
import io.ktor.server.testing.*
|
||||||
|
import org.junit.jupiter.api.Disabled
|
||||||
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.mock
|
import org.mockito.kotlin.mock
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
|
||||||
class UsersAPTest {
|
class UsersAPTest {
|
||||||
|
@ -71,7 +73,13 @@ class UsersAPTest {
|
||||||
|
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureRouting(httpSignatureVerifyService, activityPubService, userService, activityPubUserService,mock())
|
configureRouting(
|
||||||
|
httpSignatureVerifyService,
|
||||||
|
activityPubService,
|
||||||
|
userService,
|
||||||
|
activityPubUserService,
|
||||||
|
mock()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
client.get("/users/test") {
|
client.get("/users/test") {
|
||||||
accept(ContentType.Application.Activity)
|
accept(ContentType.Application.Activity)
|
||||||
|
@ -89,4 +97,79 @@ class UsersAPTest {
|
||||||
assertEquals(person, readValue)
|
assertEquals(person, readValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test()
|
||||||
|
@Disabled
|
||||||
|
fun `ユーザのURLにAcceptヘッダーをActivityとJson-LDにしてアクセスしたときPersonが返ってくる`() = testApplication {
|
||||||
|
environment {
|
||||||
|
config = ApplicationConfig("empty.conf")
|
||||||
|
}
|
||||||
|
val person = Person(
|
||||||
|
type = emptyList(),
|
||||||
|
name = "test",
|
||||||
|
id = "http://example.com/users/test",
|
||||||
|
preferredUsername = "test",
|
||||||
|
summary = "test user",
|
||||||
|
inbox = "http://example.com/users/test/inbox",
|
||||||
|
outbox = "http://example.com/users/test/outbox",
|
||||||
|
url = "http://example.com/users/test",
|
||||||
|
icon = Image(
|
||||||
|
type = emptyList(),
|
||||||
|
name = "http://example.com/users/test/icon.png",
|
||||||
|
mediaType = "image/png",
|
||||||
|
url = "http://example.com/users/test/icon.png"
|
||||||
|
),
|
||||||
|
publicKey = Key(
|
||||||
|
type = emptyList(),
|
||||||
|
name = "Public Key",
|
||||||
|
id = "http://example.com/users/test#pubkey",
|
||||||
|
owner = "https://example.com/users/test",
|
||||||
|
publicKeyPem = "-----BEGIN PUBLIC KEY-----\n\n-----END PUBLIC KEY-----"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
person.context = listOf("https://www.w3.org/ns/activitystreams")
|
||||||
|
|
||||||
|
val httpSignatureVerifyService = mock<HttpSignatureVerifyService> {}
|
||||||
|
val activityPubService = mock<ActivityPubService> {}
|
||||||
|
val userService = mock<IUserService> {}
|
||||||
|
|
||||||
|
val activityPubUserService = mock<ActivityPubUserService> {
|
||||||
|
onBlocking { getPersonByName(anyString()) } doReturn person
|
||||||
|
}
|
||||||
|
|
||||||
|
application {
|
||||||
|
configureSerialization()
|
||||||
|
configureRouting(
|
||||||
|
httpSignatureVerifyService,
|
||||||
|
activityPubService,
|
||||||
|
userService,
|
||||||
|
activityPubUserService,
|
||||||
|
mock()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
client.get("/users/test") {
|
||||||
|
accept(ContentType.Application.JsonLd)
|
||||||
|
accept(ContentType.Application.Activity)
|
||||||
|
}.let {
|
||||||
|
val objectMapper = jacksonObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
|
||||||
|
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
|
||||||
|
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||||
|
objectMapper.configOverride(List::class.java).setSetterInfo(
|
||||||
|
JsonSetter.Value.forValueNulls(
|
||||||
|
Nulls.AS_EMPTY
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val actual = it.bodyAsText()
|
||||||
|
val readValue = objectMapper.readValue<Person>(actual)
|
||||||
|
assertEquals(person, readValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
fun contentType_Test() {
|
||||||
|
val listOf = listOf(ContentType.Application.JsonLd, ContentType.Application.Activity)
|
||||||
|
assertTrue(listOf.any { contentType -> contentType.match("application/ld+json; profile=\"\\\"https://www.w3.org/ns/activitystreams\\\",application/activity+json\"") })
|
||||||
|
assertTrue(ContentType.Application.JsonLd.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue