test: テストの型が落ちてるのを修正

This commit is contained in:
2023-08-08 15:12:38 +09:00
parent 58f8005ce4
commit 2deed2980d
14 changed files with 327 additions and 163 deletions
@@ -49,19 +49,19 @@ val Application.property: Application.(propertyName: String) -> String
@Suppress("unused", "LongMethod")
fun Application.parent() {
Config.configData = ConfigData(
url = property("hideout.url"),
objectMapper = jacksonObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
url = property("hideout.url"),
objectMapper = jacksonObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
)
val module = org.koin.dsl.module {
single<Database> {
Database.connect(
url = property("hideout.database.url"),
driver = property("hideout.database.driver"),
user = property("hideout.database.username"),
password = property("hideout.database.password")
url = property("hideout.database.url"),
driver = property("hideout.database.driver"),
user = property("hideout.database.username"),
password = property("hideout.database.password")
)
}
single<JobQueueParentService> {
@@ -84,11 +84,11 @@ fun Application.parent() {
single<IdGenerateService> { TwitterSnowflakeIdGenerateService }
single<JwkProvider> {
JwkProviderBuilder(Config.configData.url).cached(
10,
24,
TimeUnit.HOURS
10,
24,
TimeUnit.HOURS
)
.rateLimited(10, 1, TimeUnit.MINUTES).build()
.rateLimited(10, 1, TimeUnit.MINUTES).build()
}
}
configureKoin(module, HideoutModule().module)
@@ -102,20 +102,20 @@ fun Application.parent() {
configureSerialization()
register(inject<IUserService>().value)
configureSecurity(
inject<JwkProvider>().value,
inject<IMetaService>().value
inject<JwkProvider>().value,
inject<IMetaService>().value
)
configureRouting(
httpSignatureVerifyService = inject<HttpSignatureVerifyService>().value,
activityPubService = inject<ActivityPubService>().value,
userService = inject<IUserService>().value,
activityPubUserService = inject<ActivityPubUserService>().value,
postService = inject<IPostApiService>().value,
userApiService = inject<IUserApiService>().value,
userAuthService = inject<IUserAuthService>().value,
userRepository = inject<IUserRepository>().value,
jwtService = inject<IJwtService>().value,
metaService = inject<IMetaService>().value
httpSignatureVerifyService = inject<HttpSignatureVerifyService>().value,
activityPubService = inject<ActivityPubService>().value,
userService = inject<IUserService>().value,
activityPubUserService = inject<ActivityPubUserService>().value,
postService = inject<IPostApiService>().value,
userApiService = inject<IUserApiService>().value,
userAuthService = inject<IUserAuthService>().value,
userRepository = inject<IUserRepository>().value,
jwtService = inject<IJwtService>().value,
metaService = inject<IMetaService>().value
)
}
@@ -10,6 +10,8 @@ open class Note : Object {
var inReplyTo: String? = null
protected constructor() : super()
@Suppress("LongParameterList")
constructor(
type: List<String> = emptyList(),
name: String,
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.JsonNode
import dev.usbharu.hideout.service.activitypub.ExtendedActivityVocabulary
class ObjectDeserializer : JsonDeserializer<Object>() {
@Suppress("LongMethod")
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): Object {
requireNotNull(p)
val treeNode: JsonNode = requireNotNull(p.codec?.readTree(p))
@@ -17,14 +17,14 @@ data class PostResponse(
companion object {
fun from(post: Post, user: User): PostResponse {
return PostResponse(
post.id,
UserResponse.from(user),
post.overview,
post.text,
post.createdAt,
post.visibility,
post.url,
post.sensitive
id = post.id,
user = UserResponse.from(user),
overview = post.overview,
text = post.text,
createdAt = post.createdAt,
visibility = post.visibility,
url = post.url,
sensitive = post.sensitive
)
}
}
@@ -18,7 +18,7 @@ data class User(
) {
override fun toString(): String {
return "User(id=$id, name='$name', domain='$domain', screenName='$screenName', description='$description'," +
" password=****, inbox='$inbox', outbox='$outbox', url='$url', publicKey='$publicKey'," +
" privateKey=****, createdAt=$createdAt)"
" password=****, inbox='$inbox', outbox='$outbox', url='$url', publicKey='$publicKey'," +
" privateKey=****, createdAt=$createdAt)"
}
}
@@ -23,16 +23,16 @@ import io.ktor.server.routing.*
@Suppress("LongParameterList")
fun Application.configureRouting(
httpSignatureVerifyService: HttpSignatureVerifyService,
activityPubService: ActivityPubService,
userService: IUserService,
activityPubUserService: ActivityPubUserService,
postService: IPostApiService,
userApiService: IUserApiService,
userAuthService: IUserAuthService,
userRepository: IUserRepository,
jwtService: IJwtService,
metaService: IMetaService
httpSignatureVerifyService: HttpSignatureVerifyService,
activityPubService: ActivityPubService,
userService: IUserService,
activityPubUserService: ActivityPubUserService,
postService: IPostApiService,
userApiService: IUserApiService,
userAuthService: IUserAuthService,
userRepository: IUserRepository,
jwtService: IJwtService,
metaService: IMetaService
) {
install(AutoHeadResponse)
routing {
@@ -43,7 +43,7 @@ fun Application.configureRouting(
route("/api/internal/v1") {
posts(postService)
users(userService, userApiService)
auth(userAuthService, userRepository, jwtService, metaService)
auth(userAuthService, userRepository, jwtService)
}
}
}
@@ -15,8 +15,8 @@ const val TOKEN_AUTH = "jwt-auth"
@Suppress("MagicNumber")
fun Application.configureSecurity(
jwkProvider: JwkProvider,
metaService: IMetaService
jwkProvider: JwkProvider,
metaService: IMetaService
) {
val issuer = Config.configData.url
install(Authentication) {
@@ -42,8 +42,8 @@ fun Application.configureSecurity(
//language=JSON
val jwt = metaService.getJwtMeta()
call.respondText(
contentType = ContentType.Application.Json,
text = JsonWebKeyUtil.publicKeyToJwk(jwt.publicKey, jwt.kid.toString())
contentType = ContentType.Application.Json,
text = JsonWebKeyUtil.publicKeyToJwk(jwt.publicKey, jwt.kid.toString())
)
}
}
@@ -7,9 +7,7 @@ import dev.usbharu.hideout.exception.UserNotFoundException
import dev.usbharu.hideout.plugins.TOKEN_AUTH
import dev.usbharu.hideout.repository.IUserRepository
import dev.usbharu.hideout.service.auth.IJwtService
import dev.usbharu.hideout.service.core.IMetaService
import dev.usbharu.hideout.service.user.IUserAuthService
import dev.usbharu.hideout.util.JsonWebKeyUtil
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
@@ -18,10 +16,11 @@ import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
fun Route.auth(userAuthService: IUserAuthService,
userRepository: IUserRepository,
jwtService: IJwtService,
metaService: IMetaService) {
fun Route.auth(
userAuthService: IUserAuthService,
userRepository: IUserRepository,
jwtService: IJwtService
) {
post("/login") {
val loginUser = call.receive<UserLogin>()
val check = userAuthService.verifyAccount(loginUser.username, loginUser.password)
@@ -30,7 +29,7 @@ fun Route.auth(userAuthService: IUserAuthService,
}
val user = userRepository.findByNameAndDomain(loginUser.username, Config.configData.domain)
?: throw UserNotFoundException("${loginUser.username} was not found.")
?: throw UserNotFoundException("${loginUser.username} was not found.")
return@post call.respond(jwtService.createToken(user))
}
@@ -42,11 +42,11 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) {
authenticate(TOKEN_AUTH, optional = true) {
get {
val userParameter = (
call.parameters["name"]
?: throw ParameterNotExistException(
"Parameter(name='userName@domain') does not exist."
)
call.parameters["name"]
?: throw ParameterNotExistException(
"Parameter(name='userName@domain') does not exist."
)
)
if (userParameter.toLongOrNull() != null) {
return@get call.respond(userApiService.findById(userParameter.toLong()))
} else {
@@ -92,11 +92,11 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) {
route("/following") {
get {
val userParameter = (
call.parameters["name"]
?: throw ParameterNotExistException(
"Parameter(name='userName@domain') does not exist."
)
call.parameters["name"]
?: throw ParameterNotExistException(
"Parameter(name='userName@domain') does not exist."
)
)
if (userParameter.toLongOrNull() != null) {
return@get call.respond(userApiService.findFollowings(userParameter.toLong()))
}
@@ -73,6 +73,7 @@ class ExposedJobRepository(
}
}
@Suppress("SuspendFunWithFlowReturnType")
override suspend fun findNext(names: Set<String>, status: Set<JobStatus>, limit: Int): Flow<ScheduledJob> {
return query {
jobs.select(