test: 認証関係を修正2

This commit is contained in:
usbharu 2023-05-18 15:45:37 +09:00
parent f0d5d8b672
commit 050efb1ee0
1 changed files with 17 additions and 21 deletions

View File

@ -1,7 +1,6 @@
package dev.usbharu.hideout.routing.activitypub package dev.usbharu.hideout.routing.activitypub
import dev.usbharu.hideout.exception.JsonParseException import dev.usbharu.hideout.exception.JsonParseException
import dev.usbharu.hideout.plugins.configureRouting
import dev.usbharu.hideout.plugins.configureSerialization import dev.usbharu.hideout.plugins.configureSerialization
import dev.usbharu.hideout.plugins.configureStatusPages import dev.usbharu.hideout.plugins.configureStatusPages
import dev.usbharu.hideout.service.activitypub.ActivityPubService import dev.usbharu.hideout.service.activitypub.ActivityPubService
@ -11,6 +10,7 @@ import dev.usbharu.hideout.service.signature.HttpSignatureVerifyService
import io.ktor.client.request.* import io.ktor.client.request.*
import io.ktor.http.* import io.ktor.http.*
import io.ktor.server.config.* import io.ktor.server.config.*
import io.ktor.server.routing.*
import io.ktor.server.testing.* import io.ktor.server.testing.*
import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
@ -27,7 +27,9 @@ class InboxRoutingKtTest {
} }
application { application {
configureSerialization() configureSerialization()
configureRouting(mock(), mock(), mock(), mock(), mock()) routing {
inbox(mock(), mock())
}
} }
client.get("/inbox").let { client.get("/inbox").let {
Assertions.assertEquals(HttpStatusCode.MethodNotAllowed, it.status) Assertions.assertEquals(HttpStatusCode.MethodNotAllowed, it.status)
@ -45,18 +47,14 @@ class InboxRoutingKtTest {
val activityPubService = mock<ActivityPubService> { val activityPubService = mock<ActivityPubService> {
on { parseActivity(any()) } doThrow JsonParseException() on { parseActivity(any()) } doThrow JsonParseException()
} }
val userService = mock<IUserService>() mock<IUserService>()
val activityPubUserService = mock<ActivityPubUserService>() mock<ActivityPubUserService>()
application { application {
configureStatusPages() configureStatusPages()
configureSerialization() configureSerialization()
configureRouting( routing {
httpSignatureVerifyService, inbox(httpSignatureVerifyService, activityPubService)
activityPubService, }
userService,
activityPubUserService,
mock()
)
} }
client.post("/inbox").let { client.post("/inbox").let {
Assertions.assertEquals(HttpStatusCode.BadRequest, it.status) Assertions.assertEquals(HttpStatusCode.BadRequest, it.status)
@ -70,7 +68,9 @@ class InboxRoutingKtTest {
} }
application { application {
configureSerialization() configureSerialization()
configureRouting(mock(), mock(), mock(), mock(), mock()) routing {
inbox(mock(), mock())
}
} }
client.get("/users/test/inbox").let { client.get("/users/test/inbox").let {
Assertions.assertEquals(HttpStatusCode.MethodNotAllowed, it.status) Assertions.assertEquals(HttpStatusCode.MethodNotAllowed, it.status)
@ -88,18 +88,14 @@ class InboxRoutingKtTest {
val activityPubService = mock<ActivityPubService> { val activityPubService = mock<ActivityPubService> {
on { parseActivity(any()) } doThrow JsonParseException() on { parseActivity(any()) } doThrow JsonParseException()
} }
val userService = mock<IUserService>() mock<IUserService>()
val activityPubUserService = mock<ActivityPubUserService>() mock<ActivityPubUserService>()
application { application {
configureStatusPages() configureStatusPages()
configureSerialization() configureSerialization()
configureRouting( routing {
httpSignatureVerifyService, inbox(httpSignatureVerifyService, activityPubService)
activityPubService, }
userService,
activityPubUserService,
mock()
)
} }
client.post("/users/test/inbox").let { client.post("/users/test/inbox").let {
Assertions.assertEquals(HttpStatusCode.BadRequest, it.status) Assertions.assertEquals(HttpStatusCode.BadRequest, it.status)