diff --git a/src/main/kotlin/dev/usbharu/hideout/Application.kt b/src/main/kotlin/dev/usbharu/hideout/Application.kt index e94ec8a5..a80d3399 100644 --- a/src/main/kotlin/dev/usbharu/hideout/Application.kt +++ b/src/main/kotlin/dev/usbharu/hideout/Application.kt @@ -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.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 { @@ -84,11 +84,11 @@ fun Application.parent() { single { TwitterSnowflakeIdGenerateService } single { 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().value) configureSecurity( - inject().value, - inject().value + inject().value, + inject().value ) configureRouting( - httpSignatureVerifyService = inject().value, - activityPubService = inject().value, - userService = inject().value, - activityPubUserService = inject().value, - postService = inject().value, - userApiService = inject().value, - userAuthService = inject().value, - userRepository = inject().value, - jwtService = inject().value, - metaService = inject().value + httpSignatureVerifyService = inject().value, + activityPubService = inject().value, + userService = inject().value, + activityPubUserService = inject().value, + postService = inject().value, + userApiService = inject().value, + userAuthService = inject().value, + userRepository = inject().value, + jwtService = inject().value, + metaService = inject().value ) } diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Note.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Note.kt index 8425fc79..21c2f25c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Note.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Note.kt @@ -10,6 +10,8 @@ open class Note : Object { var inReplyTo: String? = null protected constructor() : super() + + @Suppress("LongParameterList") constructor( type: List = emptyList(), name: String, diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/ObjectDeserializer.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/ObjectDeserializer.kt index ba2f9868..6656ee14 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/ObjectDeserializer.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/ObjectDeserializer.kt @@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.JsonNode import dev.usbharu.hideout.service.activitypub.ExtendedActivityVocabulary class ObjectDeserializer : JsonDeserializer() { + @Suppress("LongMethod") override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): Object { requireNotNull(p) val treeNode: JsonNode = requireNotNull(p.codec?.readTree(p)) diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/PostResponse.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/PostResponse.kt index 6be3ba4d..c6845da9 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/PostResponse.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/PostResponse.kt @@ -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 ) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/User.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/User.kt index 45af9cc2..6754df4f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/User.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/User.kt @@ -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)" } } diff --git a/src/main/kotlin/dev/usbharu/hideout/plugins/Routing.kt b/src/main/kotlin/dev/usbharu/hideout/plugins/Routing.kt index b45fc1a7..501b4e43 100644 --- a/src/main/kotlin/dev/usbharu/hideout/plugins/Routing.kt +++ b/src/main/kotlin/dev/usbharu/hideout/plugins/Routing.kt @@ -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) } } } diff --git a/src/main/kotlin/dev/usbharu/hideout/plugins/Security.kt b/src/main/kotlin/dev/usbharu/hideout/plugins/Security.kt index 2bba7f6c..84966882 100644 --- a/src/main/kotlin/dev/usbharu/hideout/plugins/Security.kt +++ b/src/main/kotlin/dev/usbharu/hideout/plugins/Security.kt @@ -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()) ) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Auth.kt b/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Auth.kt index 8a1e344a..f185e832 100644 --- a/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Auth.kt +++ b/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Auth.kt @@ -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() 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)) } diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Users.kt b/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Users.kt index 8609e439..24a45006 100644 --- a/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Users.kt +++ b/src/main/kotlin/dev/usbharu/hideout/routing/api/internal/v1/Users.kt @@ -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())) } diff --git a/src/main/kotlin/dev/usbharu/kjob/exposed/ExposedJobRepository.kt b/src/main/kotlin/dev/usbharu/kjob/exposed/ExposedJobRepository.kt index f2cccc4d..c9ff10c5 100644 --- a/src/main/kotlin/dev/usbharu/kjob/exposed/ExposedJobRepository.kt +++ b/src/main/kotlin/dev/usbharu/kjob/exposed/ExposedJobRepository.kt @@ -73,6 +73,7 @@ class ExposedJobRepository( } } + @Suppress("SuspendFunWithFlowReturnType") override suspend fun findNext(names: Set, status: Set, limit: Int): Flow { return query { jobs.select( diff --git a/src/test/kotlin/dev/usbharu/hideout/plugins/SecurityKtTest.kt b/src/test/kotlin/dev/usbharu/hideout/plugins/SecurityKtTest.kt index 113e9b38..8c1f4d13 100644 --- a/src/test/kotlin/dev/usbharu/hideout/plugins/SecurityKtTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/plugins/SecurityKtTest.kt @@ -15,6 +15,7 @@ import dev.usbharu.hideout.domain.model.hideout.form.RefreshToken import dev.usbharu.hideout.domain.model.hideout.form.UserLogin import dev.usbharu.hideout.exception.InvalidRefreshTokenException import dev.usbharu.hideout.repository.IUserRepository +import dev.usbharu.hideout.routing.api.internal.v1.auth import dev.usbharu.hideout.service.auth.IJwtService import dev.usbharu.hideout.service.core.IMetaService import dev.usbharu.hideout.service.user.IUserAuthService @@ -24,6 +25,7 @@ import io.ktor.client.request.* import io.ktor.client.statement.* import io.ktor.http.* import io.ktor.server.config.* +import io.ktor.server.routing.* import io.ktor.server.testing.* import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers.anyString @@ -70,7 +72,10 @@ class SecurityKtTest { val jwkProvider = mock() application { configureSerialization() - configureSecurity(jwkProvider) + configureSecurity(jwkProvider, metaService) + routing { + auth(userAuthService, userRepository, jwtService) + } } client.post("/login") { @@ -97,7 +102,10 @@ class SecurityKtTest { val jwkProvider = mock() application { configureSerialization() - configureSecurity(jwkProvider) + configureSecurity(jwkProvider, metaService) + routing { + auth(userAuthService, userRepository, jwtService) + } } client.post("/login") { contentType(ContentType.Application.Json) @@ -122,7 +130,10 @@ class SecurityKtTest { val jwkProvider = mock() application { configureSerialization() - configureSecurity(jwkProvider) + configureSecurity(jwkProvider, metaService) + routing { + auth(userAuthService, userRepository, jwtService) + } } client.post("/login") { contentType(ContentType.Application.Json) @@ -140,7 +151,10 @@ class SecurityKtTest { Config.configData = ConfigData(url = "http://example.com", objectMapper = jacksonObjectMapper()) application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) + routing { + auth(mock(), mock(), mock()) + } } client.get("/auth-check").apply { assertEquals(HttpStatusCode.Unauthorized, call.response.status) @@ -155,7 +169,10 @@ class SecurityKtTest { Config.configData = ConfigData(url = "http://example.com", objectMapper = jacksonObjectMapper()) application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) + routing { + auth(mock(), mock(), mock()) + } } client.get("/auth-check") { header("Authorization", "Digest dsfjjhogalkjdfmlhaog") @@ -172,7 +189,10 @@ class SecurityKtTest { Config.configData = ConfigData(url = "http://example.com", objectMapper = jacksonObjectMapper()) application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) + routing { + auth(mock(), mock(), mock()) + } } client.get("/auth-check") { header("Authorization", "") @@ -190,7 +210,10 @@ class SecurityKtTest { application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) + routing { + auth(mock(), mock(), mock()) + } } client.get("/auth-check") { header("Authorization", "Bearer ") @@ -244,11 +267,12 @@ class SecurityKtTest { ) ) } - val userRepository = mock() - val jwtService = mock() application { configureSerialization() - configureSecurity(jwkProvider) + configureSecurity(jwkProvider, metaService) + routing { + auth(mock(), mock(), mock()) + } } client.get("/auth-check") { @@ -304,11 +328,12 @@ class SecurityKtTest { ) ) } - val userRepository = mock() - val jwtService = mock() application { configureSerialization() - configureSecurity(jwkProvider) + configureSecurity(jwkProvider, metaService) + routing { + auth(mock(), mock(), mock()) + } } client.get("/auth-check") { header("Authorization", "Bearer $token") @@ -362,11 +387,12 @@ class SecurityKtTest { ) ) } - val userRepository = mock() - val jwtService = mock() application { configureSerialization() - configureSecurity(jwkProvider) + configureSecurity(jwkProvider, metaService) + routing { + auth(mock(), mock(), mock()) + } } client.get("/auth-check") { header("Authorization", "Bearer $token") @@ -420,11 +446,12 @@ class SecurityKtTest { ) ) } - val userRepository = mock() - val jwtService = mock() application { configureSerialization() - configureSecurity(jwkProvider) + configureSecurity(jwkProvider, metaService) + routing { + auth(mock(), mock(), mock()) + } } client.get("/auth-check") { header("Authorization", "Bearer $token") @@ -477,11 +504,12 @@ class SecurityKtTest { ) ) } - val userRepository = mock() - val jwtService = mock() application { configureSerialization() - configureSecurity(jwkProvider) + configureSecurity(jwkProvider, metaService) + routing { + auth(mock(), mock(), mock()) + } } client.get("/auth-check") { header("Authorization", "Bearer $token") @@ -501,7 +529,10 @@ class SecurityKtTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) + routing { + auth(mock(), mock(), jwtService) + } } client.post("/refresh-token") { header("Content-Type", "application/json") @@ -523,7 +554,10 @@ class SecurityKtTest { application { configureStatusPages() configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) + routing { + auth(mock(), mock(), jwtService) + } } client.post("/refresh-token") { header("Content-Type", "application/json") diff --git a/src/test/kotlin/dev/usbharu/hideout/routing/api/internal/v1/PostsTest.kt b/src/test/kotlin/dev/usbharu/hideout/routing/api/internal/v1/PostsTest.kt index c9842020..bb057308 100644 --- a/src/test/kotlin/dev/usbharu/hideout/routing/api/internal/v1/PostsTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/routing/api/internal/v1/PostsTest.kt @@ -4,6 +4,8 @@ import com.auth0.jwt.interfaces.Claim import com.auth0.jwt.interfaces.Payload import com.fasterxml.jackson.module.kotlin.readValue import dev.usbharu.hideout.config.Config +import dev.usbharu.hideout.domain.model.hideout.dto.PostResponse +import dev.usbharu.hideout.domain.model.hideout.dto.UserResponse import dev.usbharu.hideout.domain.model.hideout.entity.Post import dev.usbharu.hideout.domain.model.hideout.entity.Visibility import dev.usbharu.hideout.plugins.TOKEN_AUTH @@ -32,18 +34,27 @@ class PostsTest { environment { config = ApplicationConfig("empty.conf") } + val user = UserResponse( + id = 54321, + name = "user1", + domain = "example.com", + screenName = "user 1", + description = "Test user", + url = "https://example.com/users/54321", + createdAt = Instant.now().toEpochMilli() + ) val posts = listOf( - Post( + PostResponse( id = 12345, - userId = 4321, + user = user, text = "test1", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), url = "https://example.com/posts/1" ), - Post( + PostResponse( id = 123456, - userId = 4322, + user = user, text = "test2", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), @@ -64,7 +75,7 @@ class PostsTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { posts(postService) @@ -89,27 +100,35 @@ class PostsTest { val payload = mock { on { getClaim(eq("uid")) } doReturn claim } - + val user = UserResponse( + id = 54321, + name = "user1", + domain = "example.com", + screenName = "user 1", + description = "Test user", + url = "https://example.com/users/54321", + createdAt = Instant.now().toEpochMilli() + ) val posts = listOf( - Post( + PostResponse( id = 12345, - userId = 4321, + user = user, text = "test1", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), url = "https://example.com/posts/1" ), - Post( + PostResponse( id = 123456, - userId = 4322, + user = user, text = "test2", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), url = "https://example.com/posts/2" ), - Post( + PostResponse( id = 1234567, - userId = 4333, + user = user, text = "Followers only", visibility = Visibility.FOLLOWERS, createdAt = Instant.now().toEpochMilli(), @@ -156,9 +175,18 @@ class PostsTest { environment { config = ApplicationConfig("empty.conf") } - val post = Post( - 12345, - 1234, + val user = UserResponse( + id = 54321, + name = "user1", + domain = "example.com", + screenName = "user 1", + description = "Test user", + url = "https://example.com/users/54321", + createdAt = Instant.now().toEpochMilli() + ) + val post = PostResponse( + id = 12345, + user = user, text = "aaa", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), @@ -169,7 +197,7 @@ class PostsTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { posts(postService) @@ -187,9 +215,17 @@ class PostsTest { environment { config = ApplicationConfig("empty.conf") } - val post = Post( + val post = PostResponse( 12345, - 1234, + UserResponse( + id = 54321, + name = "user1", + domain = "example.com", + screenName = "user 1", + description = "Test user", + url = "https://example.com/users/54321", + createdAt = Instant.now().toEpochMilli() + ), text = "aaa", visibility = Visibility.FOLLOWERS, createdAt = Instant.now().toEpochMilli(), @@ -242,14 +278,22 @@ class PostsTest { onBlocking { createPost(any(), any()) } doAnswer { val argument = it.getArgument(0) val userId = it.getArgument(1) - Post( - 123L, - userId, - null, - argument.text, - Instant.now().toEpochMilli(), - Visibility.PUBLIC, - "https://example.com" + PostResponse( + id = 123L, + user = UserResponse( + id = 54321, + name = "user1", + domain = "example.com", + screenName = "user 1", + description = "Test user", + url = "https://example.com/users/54321", + createdAt = Instant.now().toEpochMilli() + ), + overview = null, + text = argument.text, + createdAt = Instant.now().toEpochMilli(), + visibility = Visibility.PUBLIC, + url = "https://example.com" ) } } @@ -290,18 +334,27 @@ class PostsTest { environment { config = ApplicationConfig("empty.conf") } + val user = UserResponse( + id = 54321, + name = "user1", + domain = "example.com", + screenName = "user 1", + description = "Test user", + url = "https://example.com/users/54321", + createdAt = Instant.now().toEpochMilli() + ) val posts = listOf( - Post( + PostResponse( id = 12345, - userId = 1, + user = user, text = "test1", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), url = "https://example.com/posts/1" ), - Post( + PostResponse( id = 123456, - userId = 1, + user = user, text = "test2", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), @@ -323,7 +376,7 @@ class PostsTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { posts(postService) @@ -342,18 +395,27 @@ class PostsTest { environment { config = ApplicationConfig("empty.conf") } + val user = UserResponse( + id = 54321, + name = "user1", + domain = "example.com", + screenName = "user 1", + description = "Test user", + url = "https://example.com/users/54321", + createdAt = Instant.now().toEpochMilli() + ) val posts = listOf( - Post( + PostResponse( id = 12345, - userId = 1, + user = user, text = "test1", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), url = "https://example.com/posts/1" ), - Post( + PostResponse( id = 123456, - userId = 1, + user = user, text = "test2", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), @@ -375,7 +437,7 @@ class PostsTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { posts(postService) @@ -394,18 +456,27 @@ class PostsTest { environment { config = ApplicationConfig("empty.conf") } + val user = UserResponse( + id = 54321, + name = "user1", + domain = "example.com", + screenName = "user 1", + description = "Test user", + url = "https://example.com/users/54321", + createdAt = Instant.now().toEpochMilli() + ) val posts = listOf( - Post( + PostResponse( id = 12345, - userId = 1, + user = user, text = "test1", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), url = "https://example.com/posts/1" ), - Post( + PostResponse( id = 123456, - userId = 1, + user = user, text = "test2", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), @@ -427,7 +498,7 @@ class PostsTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { posts(postService) @@ -446,18 +517,27 @@ class PostsTest { environment { config = ApplicationConfig("empty.conf") } + val user = UserResponse( + id = 54321, + name = "user1", + domain = "example.com", + screenName = "user 1", + description = "Test user", + url = "https://example.com/users/54321", + createdAt = Instant.now().toEpochMilli() + ) val posts = listOf( - Post( + PostResponse( id = 12345, - userId = 1, + user = user, text = "test1", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), url = "https://example.com/posts/1" ), - Post( + PostResponse( id = 123456, - userId = 1, + user = user, text = "test2", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), @@ -479,7 +559,7 @@ class PostsTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { posts(postService) @@ -498,9 +578,17 @@ class PostsTest { environment { config = ApplicationConfig("empty.conf") } - val post = Post( + val post = PostResponse( id = 123456, - userId = 1, + user = UserResponse( + id = 54321, + name = "user1", + domain = "example.com", + screenName = "user 1", + description = "Test user", + url = "https://example.com/users/54321", + createdAt = Instant.now().toEpochMilli() + ), text = "test2", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), @@ -511,7 +599,7 @@ class PostsTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { posts(postService) @@ -530,9 +618,17 @@ class PostsTest { environment { config = ApplicationConfig("empty.conf") } - val post = Post( + val post = PostResponse( id = 123456, - userId = 1, + user = UserResponse( + id = 54321, + name = "user1", + domain = "example.com", + screenName = "user 1", + description = "Test user", + url = "https://example.com/users/54321", + createdAt = Instant.now().toEpochMilli() + ), text = "test2", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), @@ -543,7 +639,7 @@ class PostsTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { posts(postService) @@ -562,9 +658,17 @@ class PostsTest { environment { config = ApplicationConfig("empty.conf") } - val post = Post( + val post = PostResponse( id = 123456, - userId = 1, + user = UserResponse( + id = 54321, + name = "user1", + domain = "example.com", + screenName = "user 1", + description = "Test user", + url = "https://example.com/users/54321", + createdAt = Instant.now().toEpochMilli() + ), text = "test2", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), @@ -575,7 +679,7 @@ class PostsTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { posts(postService) @@ -594,9 +698,17 @@ class PostsTest { environment { config = ApplicationConfig("empty.conf") } - val post = Post( + val post = PostResponse( id = 123456, - userId = 1, + user = UserResponse( + id = 54321, + name = "user1", + domain = "example.com", + screenName = "user 1", + description = "Test user", + url = "https://example.com/users/54321", + createdAt = Instant.now().toEpochMilli() + ), text = "test2", visibility = Visibility.PUBLIC, createdAt = Instant.now().toEpochMilli(), @@ -607,7 +719,7 @@ class PostsTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { posts(postService) diff --git a/src/test/kotlin/dev/usbharu/hideout/routing/api/internal/v1/UsersTest.kt b/src/test/kotlin/dev/usbharu/hideout/routing/api/internal/v1/UsersTest.kt index e49752d1..0f738579 100644 --- a/src/test/kotlin/dev/usbharu/hideout/routing/api/internal/v1/UsersTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/routing/api/internal/v1/UsersTest.kt @@ -58,7 +58,7 @@ class UsersTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { users(mock(), userService) @@ -96,7 +96,7 @@ class UsersTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { users(userService, mock()) @@ -127,7 +127,7 @@ class UsersTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { users(userService, mock()) @@ -162,7 +162,7 @@ class UsersTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { users(mock(), userApiService) @@ -195,7 +195,7 @@ class UsersTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { users(mock(), userApiService) @@ -228,7 +228,7 @@ class UsersTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { users(mock(), userApiService) @@ -261,7 +261,7 @@ class UsersTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { users(mock(), userApiService) @@ -306,7 +306,7 @@ class UsersTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { users(mock(), userApiService) @@ -351,7 +351,7 @@ class UsersTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { users(mock(), userApiService) @@ -396,7 +396,7 @@ class UsersTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { users(mock(), userApiService) @@ -591,7 +591,7 @@ class UsersTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { users(mock(), userApiService) @@ -636,7 +636,7 @@ class UsersTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { users(mock(), userApiService) @@ -681,7 +681,7 @@ class UsersTest { } application { configureSerialization() - configureSecurity(mock()) + configureSecurity(mock(), mock()) routing { route("/api/internal/v1") { users(mock(), userApiService) diff --git a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImplTest.kt index 5d15c039..0d703801 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubReceiveFollowServiceImplTest.kt @@ -48,13 +48,21 @@ class ActivityPubReceiveFollowServiceImplTest { firstValue.invoke(scheduleContext, ReceiveFollowJob) val actor = scheduleContext.props.props[ReceiveFollowJob.actor.name] val targetActor = scheduleContext.props.props[ReceiveFollowJob.targetActor.name] - val follow = scheduleContext.props.props[ReceiveFollowJob.follow.name] + val follow = scheduleContext.props.props[ReceiveFollowJob.follow.name] as String assertEquals("https://follower.example.com", actor) assertEquals("https://example.com", targetActor) //language=JSON assertEquals( - """{"type":"Follow","name":"Follow","actor":"https://follower.example.com","object":"https://example.com","@context":null}""", - follow + Json.parseToJsonElement( + """{ + "type": "Follow", + "name": "Follow", + "actor": "https://follower.example.com", + "object": "https://example.com", + "@context": null +}""" + ), + Json.parseToJsonElement(follow) ) } } @@ -155,7 +163,14 @@ class ActivityPubReceiveFollowServiceImplTest { data = mapOf( ReceiveFollowJob.actor.name to "https://follower.example.com", ReceiveFollowJob.targetActor.name to "https://example.com", - ReceiveFollowJob.follow.name to """{"type":"Follow","name":"Follow","object":"https://example.com","actor":"https://follower.example.com","@context":null}""" + //language=JSON + ReceiveFollowJob.follow.name to """{ + "type": "Follow", + "name": "Follow", + "object": "https://example.com", + "actor": "https://follower.example.com", + "@context": null +}""" ), json = Json )