test: 認証関係を修正

This commit is contained in:
usbharu 2023-05-18 15:33:00 +09:00
parent cd8e8d530b
commit 7c55f5c8c3
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
6 changed files with 391 additions and 31 deletions

View File

@ -5,7 +5,7 @@ import dev.usbharu.hideout.domain.model.hideout.entity.Visibility
data class PostCreateDto( data class PostCreateDto(
val text: String, val text: String,
val overview: String? = null, val overview: String? = null,
val visibility: Visibility, val visibility: Visibility = Visibility.PUBLIC,
val repostId: Long? = null, val repostId: Long? = null,
val repolyId: Long? = null, val repolyId: Long? = null,
val userId: Long val userId: Long

View File

@ -38,6 +38,19 @@ fun Route.users(userService: IUserService) {
} }
route("/{name}") { route("/{name}") {
authenticate(TOKEN_AUTH, optional = true) {
get {
val userParameter = (call.parameters["name"]
?: throw ParameterNotExistException("Parameter(name='userName@domain') does not exist."))
if (userParameter.toLongOrNull() != null) {
return@get call.respond(userService.findById(userParameter.toLong()))
} else {
val acct = AcctUtil.parse(userParameter)
return@get call.respond(userService.findByNameAndDomain(acct.username, acct.domain))
}
}
}
route("/followers") { route("/followers") {
get { get {
val userParameter = call.parameters["name"] val userParameter = call.parameters["name"]

View File

@ -0,0 +1,365 @@
openapi: "3.0.3"
info:
title: "hideout API"
description: "hideout API"
version: "1.0.0"
servers:
- url: "https://hideout"
paths:
/.well-known/jwks.json:
get:
description: ""
responses:
"200":
description: "OK"
content:
application/json:
schema:
type: "string"
/auth-check:
get:
description: ""
responses:
"200":
description: "OK"
content:
text/plain:
schema:
type: "string"
examples:
Example#1:
value: ""
/login:
post:
description: ""
requestBody:
content:
'*/*':
schema:
$ref: "#/components/schemas/UserLogin"
required: true
responses:
"401":
description: "Unauthorized"
content:
'*/*':
schema:
type: "object"
"200":
description: "OK"
content:
'*/*':
schema:
$ref: "#/components/schemas/JwtToken"
/refresh-token:
post:
description: ""
requestBody:
content:
'*/*':
schema:
$ref: "#/components/schemas/RefreshToken"
required: true
responses:
"200":
description: "OK"
content:
'*/*':
schema:
$ref: "#/components/schemas/JwtToken"
/.well-known/webfinger:
get:
description: ""
parameters:
- name: "resource"
in: "query"
required: false
schema:
type: "string"
responses:
"200":
description: "OK"
content:
'*/*':
schema:
$ref: "#/components/schemas/WebFinger"
/api/internal/v1/posts:
get:
description: ""
parameters:
- name: "since"
in: "query"
required: false
schema:
type: "string"
- name: "until"
in: "query"
required: false
schema:
type: "string"
- name: "minId"
in: "query"
required: false
schema:
type: "number"
- name: "maxId"
in: "query"
required: false
schema:
type: "number"
- name: "limit"
in: "query"
required: false
schema:
type: "integer"
post:
description: ""
requestBody:
content:
'*/*':
schema:
$ref: "#/components/schemas/Post"
required: true
responses:
"200":
description: "OK"
content:
'*/*':
schema:
type: "object"
/inbox:
get:
description: ""
responses:
"405":
description: "Method Not Allowed"
content:
'*/*':
schema:
type: "object"
post:
description: ""
responses:
"200":
description: "OK"
content:
'*/*':
schema:
type: "string"
"501":
description: "Not Implemented"
content:
'*/*':
schema:
type: "object"
/outbox:
get:
description: ""
responses:
"501":
description: "Not Implemented"
content:
'*/*':
schema:
type: "object"
post:
description: ""
responses:
"501":
description: "Not Implemented"
content:
'*/*':
schema:
type: "object"
/users/{name}:
get:
description: ""
parameters:
- name: "name"
in: "path"
required: true
schema:
type: "string"
responses:
"200":
description: "OK"
content:
text/plain:
schema:
type: "string"
/users/{name}/inbox:
get:
description: ""
parameters:
- name: "name"
in: "path"
required: true
schema:
type: "string"
responses:
"405":
description: "Method Not Allowed"
content:
'*/*':
schema:
type: "object"
post:
description: ""
parameters:
- name: "name"
in: "path"
required: true
schema:
type: "string"
responses:
"200":
description: "OK"
content:
'*/*':
schema:
type: "string"
"501":
description: "Not Implemented"
content:
'*/*':
schema:
type: "object"
/users/{name}/outbox:
get:
description: ""
parameters:
- name: "name"
in: "path"
required: true
schema:
type: "string"
responses:
"501":
description: "Not Implemented"
content:
'*/*':
schema:
type: "object"
post:
description: ""
parameters:
- name: "name"
in: "path"
required: true
schema:
type: "string"
responses:
"501":
description: "Not Implemented"
content:
'*/*':
schema:
type: "object"
/:
get:
description: ""
responses:
"200":
description: "OK"
content:
text/html:
schema:
type: "string"
/register:
get:
description: ""
responses:
"200":
description: "OK"
content:
text/html:
schema:
type: "string"
post:
description: ""
parameters:
- name: "password"
in: "query"
required: false
schema:
type: "string"
- name: "username"
in: "query"
required: false
schema:
type: "string"
responses:
"200":
description: "OK <br> Redirect"
content:
text/plain:
schema:
type: "string"
examples:
Example#1:
value: ""
Example#2:
value: "/register"
Example#3:
value: "/register"
Example#4:
value: "/register"
components:
schemas:
UserLogin:
type: "object"
properties:
username:
type: "string"
password:
type: "string"
JwtToken:
type: "object"
properties:
token:
type: "string"
refreshToken:
type: "string"
RefreshToken:
type: "object"
properties:
refreshToken:
type: "string"
Link:
type: "object"
properties:
rel:
type: "string"
type:
type: "string"
href:
type: "string"
WebFinger:
type: "object"
properties:
subject:
type: "string"
links:
type: "array"
items:
$ref: "#/components/schemas/Link"
Post:
type: "object"
properties:
text:
type: "string"
overview:
type: "string"
visibility:
type: "string"
enum:
- "PUBLIC"
- "UNLISTED"
- "FOLLOWERS"
- "DIRECT"
repostId:
type: "integer"
format: "int64"
replyId:
type: "integer"
format: "int64"

View File

@ -10,18 +10,16 @@ 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.domain.model.hideout.entity.User
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.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.signature.HttpSignatureVerifyService
import dev.usbharu.hideout.util.HttpUtil.Activity import dev.usbharu.hideout.util.HttpUtil.Activity
import dev.usbharu.hideout.util.HttpUtil.JsonLd 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.routing.*
import io.ktor.server.testing.* 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
@ -64,8 +62,6 @@ class UsersAPTest {
) )
person.context = listOf("https://www.w3.org/ns/activitystreams") person.context = listOf("https://www.w3.org/ns/activitystreams")
val httpSignatureVerifyService = mock<HttpSignatureVerifyService> {}
val activityPubService = mock<ActivityPubService> {}
val userService = mock<IUserService> {} val userService = mock<IUserService> {}
val activityPubUserService = mock<ActivityPubUserService> { val activityPubUserService = mock<ActivityPubUserService> {
@ -74,13 +70,9 @@ class UsersAPTest {
application { application {
configureSerialization() configureSerialization()
configureRouting( routing {
httpSignatureVerifyService, usersAP(activityPubUserService, userService)
activityPubService, }
userService,
activityPubUserService,
mock()
)
} }
client.get("/users/test") { client.get("/users/test") {
accept(ContentType.Application.Activity) accept(ContentType.Application.Activity)
@ -130,8 +122,6 @@ class UsersAPTest {
) )
person.context = listOf("https://www.w3.org/ns/activitystreams") person.context = listOf("https://www.w3.org/ns/activitystreams")
val httpSignatureVerifyService = mock<HttpSignatureVerifyService> {}
val activityPubService = mock<ActivityPubService> {}
val userService = mock<IUserService> {} val userService = mock<IUserService> {}
val activityPubUserService = mock<ActivityPubUserService> { val activityPubUserService = mock<ActivityPubUserService> {
@ -140,13 +130,9 @@ class UsersAPTest {
application { application {
configureSerialization() configureSerialization()
configureRouting( routing {
httpSignatureVerifyService, usersAP(activityPubUserService, userService)
activityPubService, }
userService,
activityPubUserService,
mock()
)
} }
client.get("/users/test") { client.get("/users/test") {
accept(ContentType.Application.JsonLd) accept(ContentType.Application.JsonLd)
@ -205,13 +191,9 @@ class UsersAPTest {
) )
} }
application { application {
configureRouting( routing {
mock(), usersAP(mock(), userService)
mock(), }
userService,
mock(),
mock()
)
} }
client.get("/users/test") { client.get("/users/test") {
accept(ContentType.Text.Html) accept(ContentType.Text.Html)

View File

@ -78,7 +78,7 @@ class PostsKtTest {
} }
argumentCaptor<PostCreateDto> { argumentCaptor<PostCreateDto> {
verify(postService).create(capture()) verify(postService).create(capture())
assertEquals(PostCreateDto("test", 1234), firstValue) assertEquals(PostCreateDto("test", userId = 1234), firstValue)
} }
} }
} }

View File

@ -115,7 +115,7 @@ class ActivityPubFollowServiceImplTest {
createdAt = Instant.now() createdAt = Instant.now()
) )
) )
onBlocking { addFollowers(any(), any()) } doReturn Unit onBlocking { addFollowers(any(), any()) } doReturn false
} }
val activityPubFollowService = val activityPubFollowService =
ActivityPubFollowServiceImpl( ActivityPubFollowServiceImpl(