mirror of https://github.com/usbharu/Hideout.git
test: テストの型が落ちてるのを修正
This commit is contained in:
parent
58f8005ce4
commit
2deed2980d
|
@ -49,19 +49,19 @@ val Application.property: Application.(propertyName: String) -> String
|
||||||
@Suppress("unused", "LongMethod")
|
@Suppress("unused", "LongMethod")
|
||||||
fun Application.parent() {
|
fun Application.parent() {
|
||||||
Config.configData = ConfigData(
|
Config.configData = ConfigData(
|
||||||
url = property("hideout.url"),
|
url = property("hideout.url"),
|
||||||
objectMapper = jacksonObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
|
objectMapper = jacksonObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
|
||||||
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
|
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
|
||||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||||
)
|
)
|
||||||
|
|
||||||
val module = org.koin.dsl.module {
|
val module = org.koin.dsl.module {
|
||||||
single<Database> {
|
single<Database> {
|
||||||
Database.connect(
|
Database.connect(
|
||||||
url = property("hideout.database.url"),
|
url = property("hideout.database.url"),
|
||||||
driver = property("hideout.database.driver"),
|
driver = property("hideout.database.driver"),
|
||||||
user = property("hideout.database.username"),
|
user = property("hideout.database.username"),
|
||||||
password = property("hideout.database.password")
|
password = property("hideout.database.password")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
single<JobQueueParentService> {
|
single<JobQueueParentService> {
|
||||||
|
@ -84,11 +84,11 @@ fun Application.parent() {
|
||||||
single<IdGenerateService> { TwitterSnowflakeIdGenerateService }
|
single<IdGenerateService> { TwitterSnowflakeIdGenerateService }
|
||||||
single<JwkProvider> {
|
single<JwkProvider> {
|
||||||
JwkProviderBuilder(Config.configData.url).cached(
|
JwkProviderBuilder(Config.configData.url).cached(
|
||||||
10,
|
10,
|
||||||
24,
|
24,
|
||||||
TimeUnit.HOURS
|
TimeUnit.HOURS
|
||||||
)
|
)
|
||||||
.rateLimited(10, 1, TimeUnit.MINUTES).build()
|
.rateLimited(10, 1, TimeUnit.MINUTES).build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
configureKoin(module, HideoutModule().module)
|
configureKoin(module, HideoutModule().module)
|
||||||
|
@ -102,20 +102,20 @@ fun Application.parent() {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
register(inject<IUserService>().value)
|
register(inject<IUserService>().value)
|
||||||
configureSecurity(
|
configureSecurity(
|
||||||
inject<JwkProvider>().value,
|
inject<JwkProvider>().value,
|
||||||
inject<IMetaService>().value
|
inject<IMetaService>().value
|
||||||
)
|
)
|
||||||
configureRouting(
|
configureRouting(
|
||||||
httpSignatureVerifyService = inject<HttpSignatureVerifyService>().value,
|
httpSignatureVerifyService = inject<HttpSignatureVerifyService>().value,
|
||||||
activityPubService = inject<ActivityPubService>().value,
|
activityPubService = inject<ActivityPubService>().value,
|
||||||
userService = inject<IUserService>().value,
|
userService = inject<IUserService>().value,
|
||||||
activityPubUserService = inject<ActivityPubUserService>().value,
|
activityPubUserService = inject<ActivityPubUserService>().value,
|
||||||
postService = inject<IPostApiService>().value,
|
postService = inject<IPostApiService>().value,
|
||||||
userApiService = inject<IUserApiService>().value,
|
userApiService = inject<IUserApiService>().value,
|
||||||
userAuthService = inject<IUserAuthService>().value,
|
userAuthService = inject<IUserAuthService>().value,
|
||||||
userRepository = inject<IUserRepository>().value,
|
userRepository = inject<IUserRepository>().value,
|
||||||
jwtService = inject<IJwtService>().value,
|
jwtService = inject<IJwtService>().value,
|
||||||
metaService = inject<IMetaService>().value
|
metaService = inject<IMetaService>().value
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ open class Note : Object {
|
||||||
var inReplyTo: String? = null
|
var inReplyTo: String? = null
|
||||||
|
|
||||||
protected constructor() : super()
|
protected constructor() : super()
|
||||||
|
|
||||||
|
@Suppress("LongParameterList")
|
||||||
constructor(
|
constructor(
|
||||||
type: List<String> = emptyList(),
|
type: List<String> = emptyList(),
|
||||||
name: String,
|
name: String,
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.JsonNode
|
||||||
import dev.usbharu.hideout.service.activitypub.ExtendedActivityVocabulary
|
import dev.usbharu.hideout.service.activitypub.ExtendedActivityVocabulary
|
||||||
|
|
||||||
class ObjectDeserializer : JsonDeserializer<Object>() {
|
class ObjectDeserializer : JsonDeserializer<Object>() {
|
||||||
|
@Suppress("LongMethod")
|
||||||
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): Object {
|
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): Object {
|
||||||
requireNotNull(p)
|
requireNotNull(p)
|
||||||
val treeNode: JsonNode = requireNotNull(p.codec?.readTree(p))
|
val treeNode: JsonNode = requireNotNull(p.codec?.readTree(p))
|
||||||
|
|
|
@ -17,14 +17,14 @@ data class PostResponse(
|
||||||
companion object {
|
companion object {
|
||||||
fun from(post: Post, user: User): PostResponse {
|
fun from(post: Post, user: User): PostResponse {
|
||||||
return PostResponse(
|
return PostResponse(
|
||||||
post.id,
|
id = post.id,
|
||||||
UserResponse.from(user),
|
user = UserResponse.from(user),
|
||||||
post.overview,
|
overview = post.overview,
|
||||||
post.text,
|
text = post.text,
|
||||||
post.createdAt,
|
createdAt = post.createdAt,
|
||||||
post.visibility,
|
visibility = post.visibility,
|
||||||
post.url,
|
url = post.url,
|
||||||
post.sensitive
|
sensitive = post.sensitive
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ data class User(
|
||||||
) {
|
) {
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "User(id=$id, name='$name', domain='$domain', screenName='$screenName', description='$description'," +
|
return "User(id=$id, name='$name', domain='$domain', screenName='$screenName', description='$description'," +
|
||||||
" password=****, inbox='$inbox', outbox='$outbox', url='$url', publicKey='$publicKey'," +
|
" password=****, inbox='$inbox', outbox='$outbox', url='$url', publicKey='$publicKey'," +
|
||||||
" privateKey=****, createdAt=$createdAt)"
|
" privateKey=****, createdAt=$createdAt)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,16 +23,16 @@ import io.ktor.server.routing.*
|
||||||
|
|
||||||
@Suppress("LongParameterList")
|
@Suppress("LongParameterList")
|
||||||
fun Application.configureRouting(
|
fun Application.configureRouting(
|
||||||
httpSignatureVerifyService: HttpSignatureVerifyService,
|
httpSignatureVerifyService: HttpSignatureVerifyService,
|
||||||
activityPubService: ActivityPubService,
|
activityPubService: ActivityPubService,
|
||||||
userService: IUserService,
|
userService: IUserService,
|
||||||
activityPubUserService: ActivityPubUserService,
|
activityPubUserService: ActivityPubUserService,
|
||||||
postService: IPostApiService,
|
postService: IPostApiService,
|
||||||
userApiService: IUserApiService,
|
userApiService: IUserApiService,
|
||||||
userAuthService: IUserAuthService,
|
userAuthService: IUserAuthService,
|
||||||
userRepository: IUserRepository,
|
userRepository: IUserRepository,
|
||||||
jwtService: IJwtService,
|
jwtService: IJwtService,
|
||||||
metaService: IMetaService
|
metaService: IMetaService
|
||||||
) {
|
) {
|
||||||
install(AutoHeadResponse)
|
install(AutoHeadResponse)
|
||||||
routing {
|
routing {
|
||||||
|
@ -43,7 +43,7 @@ fun Application.configureRouting(
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
posts(postService)
|
posts(postService)
|
||||||
users(userService, userApiService)
|
users(userService, userApiService)
|
||||||
auth(userAuthService, userRepository, jwtService, metaService)
|
auth(userAuthService, userRepository, jwtService)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@ const val TOKEN_AUTH = "jwt-auth"
|
||||||
|
|
||||||
@Suppress("MagicNumber")
|
@Suppress("MagicNumber")
|
||||||
fun Application.configureSecurity(
|
fun Application.configureSecurity(
|
||||||
jwkProvider: JwkProvider,
|
jwkProvider: JwkProvider,
|
||||||
metaService: IMetaService
|
metaService: IMetaService
|
||||||
) {
|
) {
|
||||||
val issuer = Config.configData.url
|
val issuer = Config.configData.url
|
||||||
install(Authentication) {
|
install(Authentication) {
|
||||||
|
@ -42,8 +42,8 @@ fun Application.configureSecurity(
|
||||||
//language=JSON
|
//language=JSON
|
||||||
val jwt = metaService.getJwtMeta()
|
val jwt = metaService.getJwtMeta()
|
||||||
call.respondText(
|
call.respondText(
|
||||||
contentType = ContentType.Application.Json,
|
contentType = ContentType.Application.Json,
|
||||||
text = JsonWebKeyUtil.publicKeyToJwk(jwt.publicKey, jwt.kid.toString())
|
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.plugins.TOKEN_AUTH
|
||||||
import dev.usbharu.hideout.repository.IUserRepository
|
import dev.usbharu.hideout.repository.IUserRepository
|
||||||
import dev.usbharu.hideout.service.auth.IJwtService
|
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.service.user.IUserAuthService
|
||||||
import dev.usbharu.hideout.util.JsonWebKeyUtil
|
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
import io.ktor.server.auth.*
|
import io.ktor.server.auth.*
|
||||||
|
@ -18,10 +16,11 @@ import io.ktor.server.request.*
|
||||||
import io.ktor.server.response.*
|
import io.ktor.server.response.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
|
|
||||||
fun Route.auth(userAuthService: IUserAuthService,
|
fun Route.auth(
|
||||||
userRepository: IUserRepository,
|
userAuthService: IUserAuthService,
|
||||||
jwtService: IJwtService,
|
userRepository: IUserRepository,
|
||||||
metaService: IMetaService) {
|
jwtService: IJwtService
|
||||||
|
) {
|
||||||
post("/login") {
|
post("/login") {
|
||||||
val loginUser = call.receive<UserLogin>()
|
val loginUser = call.receive<UserLogin>()
|
||||||
val check = userAuthService.verifyAccount(loginUser.username, loginUser.password)
|
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)
|
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))
|
return@post call.respond(jwtService.createToken(user))
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,11 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) {
|
||||||
authenticate(TOKEN_AUTH, optional = true) {
|
authenticate(TOKEN_AUTH, optional = true) {
|
||||||
get {
|
get {
|
||||||
val userParameter = (
|
val userParameter = (
|
||||||
call.parameters["name"]
|
call.parameters["name"]
|
||||||
?: throw ParameterNotExistException(
|
?: throw ParameterNotExistException(
|
||||||
"Parameter(name='userName@domain') does not exist."
|
"Parameter(name='userName@domain') does not exist."
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
if (userParameter.toLongOrNull() != null) {
|
if (userParameter.toLongOrNull() != null) {
|
||||||
return@get call.respond(userApiService.findById(userParameter.toLong()))
|
return@get call.respond(userApiService.findById(userParameter.toLong()))
|
||||||
} else {
|
} else {
|
||||||
|
@ -92,11 +92,11 @@ fun Route.users(userService: IUserService, userApiService: IUserApiService) {
|
||||||
route("/following") {
|
route("/following") {
|
||||||
get {
|
get {
|
||||||
val userParameter = (
|
val userParameter = (
|
||||||
call.parameters["name"]
|
call.parameters["name"]
|
||||||
?: throw ParameterNotExistException(
|
?: throw ParameterNotExistException(
|
||||||
"Parameter(name='userName@domain') does not exist."
|
"Parameter(name='userName@domain') does not exist."
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
if (userParameter.toLongOrNull() != null) {
|
if (userParameter.toLongOrNull() != null) {
|
||||||
return@get call.respond(userApiService.findFollowings(userParameter.toLong()))
|
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> {
|
override suspend fun findNext(names: Set<String>, status: Set<JobStatus>, limit: Int): Flow<ScheduledJob> {
|
||||||
return query {
|
return query {
|
||||||
jobs.select(
|
jobs.select(
|
||||||
|
|
|
@ -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.domain.model.hideout.form.UserLogin
|
||||||
import dev.usbharu.hideout.exception.InvalidRefreshTokenException
|
import dev.usbharu.hideout.exception.InvalidRefreshTokenException
|
||||||
import dev.usbharu.hideout.repository.IUserRepository
|
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.auth.IJwtService
|
||||||
import dev.usbharu.hideout.service.core.IMetaService
|
import dev.usbharu.hideout.service.core.IMetaService
|
||||||
import dev.usbharu.hideout.service.user.IUserAuthService
|
import dev.usbharu.hideout.service.user.IUserAuthService
|
||||||
|
@ -24,6 +25,7 @@ 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
|
||||||
|
@ -70,7 +72,10 @@ class SecurityKtTest {
|
||||||
val jwkProvider = mock<JwkProvider>()
|
val jwkProvider = mock<JwkProvider>()
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(jwkProvider)
|
configureSecurity(jwkProvider, metaService)
|
||||||
|
routing {
|
||||||
|
auth(userAuthService, userRepository, jwtService)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client.post("/login") {
|
client.post("/login") {
|
||||||
|
@ -97,7 +102,10 @@ class SecurityKtTest {
|
||||||
val jwkProvider = mock<JwkProvider>()
|
val jwkProvider = mock<JwkProvider>()
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(jwkProvider)
|
configureSecurity(jwkProvider, metaService)
|
||||||
|
routing {
|
||||||
|
auth(userAuthService, userRepository, jwtService)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.post("/login") {
|
client.post("/login") {
|
||||||
contentType(ContentType.Application.Json)
|
contentType(ContentType.Application.Json)
|
||||||
|
@ -122,7 +130,10 @@ class SecurityKtTest {
|
||||||
val jwkProvider = mock<JwkProvider>()
|
val jwkProvider = mock<JwkProvider>()
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(jwkProvider)
|
configureSecurity(jwkProvider, metaService)
|
||||||
|
routing {
|
||||||
|
auth(userAuthService, userRepository, jwtService)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.post("/login") {
|
client.post("/login") {
|
||||||
contentType(ContentType.Application.Json)
|
contentType(ContentType.Application.Json)
|
||||||
|
@ -140,7 +151,10 @@ class SecurityKtTest {
|
||||||
Config.configData = ConfigData(url = "http://example.com", objectMapper = jacksonObjectMapper())
|
Config.configData = ConfigData(url = "http://example.com", objectMapper = jacksonObjectMapper())
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
|
routing {
|
||||||
|
auth(mock(), mock(), mock())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.get("/auth-check").apply {
|
client.get("/auth-check").apply {
|
||||||
assertEquals(HttpStatusCode.Unauthorized, call.response.status)
|
assertEquals(HttpStatusCode.Unauthorized, call.response.status)
|
||||||
|
@ -155,7 +169,10 @@ class SecurityKtTest {
|
||||||
Config.configData = ConfigData(url = "http://example.com", objectMapper = jacksonObjectMapper())
|
Config.configData = ConfigData(url = "http://example.com", objectMapper = jacksonObjectMapper())
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
|
routing {
|
||||||
|
auth(mock(), mock(), mock())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.get("/auth-check") {
|
client.get("/auth-check") {
|
||||||
header("Authorization", "Digest dsfjjhogalkjdfmlhaog")
|
header("Authorization", "Digest dsfjjhogalkjdfmlhaog")
|
||||||
|
@ -172,7 +189,10 @@ class SecurityKtTest {
|
||||||
Config.configData = ConfigData(url = "http://example.com", objectMapper = jacksonObjectMapper())
|
Config.configData = ConfigData(url = "http://example.com", objectMapper = jacksonObjectMapper())
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
|
routing {
|
||||||
|
auth(mock(), mock(), mock())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.get("/auth-check") {
|
client.get("/auth-check") {
|
||||||
header("Authorization", "")
|
header("Authorization", "")
|
||||||
|
@ -190,7 +210,10 @@ class SecurityKtTest {
|
||||||
|
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
|
routing {
|
||||||
|
auth(mock(), mock(), mock())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.get("/auth-check") {
|
client.get("/auth-check") {
|
||||||
header("Authorization", "Bearer ")
|
header("Authorization", "Bearer ")
|
||||||
|
@ -244,11 +267,12 @@ class SecurityKtTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val userRepository = mock<IUserRepository>()
|
|
||||||
val jwtService = mock<IJwtService>()
|
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(jwkProvider)
|
configureSecurity(jwkProvider, metaService)
|
||||||
|
routing {
|
||||||
|
auth(mock(), mock(), mock())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client.get("/auth-check") {
|
client.get("/auth-check") {
|
||||||
|
@ -304,11 +328,12 @@ class SecurityKtTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val userRepository = mock<IUserRepository>()
|
|
||||||
val jwtService = mock<IJwtService>()
|
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(jwkProvider)
|
configureSecurity(jwkProvider, metaService)
|
||||||
|
routing {
|
||||||
|
auth(mock(), mock(), mock())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.get("/auth-check") {
|
client.get("/auth-check") {
|
||||||
header("Authorization", "Bearer $token")
|
header("Authorization", "Bearer $token")
|
||||||
|
@ -362,11 +387,12 @@ class SecurityKtTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val userRepository = mock<IUserRepository>()
|
|
||||||
val jwtService = mock<IJwtService>()
|
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(jwkProvider)
|
configureSecurity(jwkProvider, metaService)
|
||||||
|
routing {
|
||||||
|
auth(mock(), mock(), mock())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.get("/auth-check") {
|
client.get("/auth-check") {
|
||||||
header("Authorization", "Bearer $token")
|
header("Authorization", "Bearer $token")
|
||||||
|
@ -420,11 +446,12 @@ class SecurityKtTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val userRepository = mock<IUserRepository>()
|
|
||||||
val jwtService = mock<IJwtService>()
|
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(jwkProvider)
|
configureSecurity(jwkProvider, metaService)
|
||||||
|
routing {
|
||||||
|
auth(mock(), mock(), mock())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.get("/auth-check") {
|
client.get("/auth-check") {
|
||||||
header("Authorization", "Bearer $token")
|
header("Authorization", "Bearer $token")
|
||||||
|
@ -477,11 +504,12 @@ class SecurityKtTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val userRepository = mock<IUserRepository>()
|
|
||||||
val jwtService = mock<IJwtService>()
|
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(jwkProvider)
|
configureSecurity(jwkProvider, metaService)
|
||||||
|
routing {
|
||||||
|
auth(mock(), mock(), mock())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.get("/auth-check") {
|
client.get("/auth-check") {
|
||||||
header("Authorization", "Bearer $token")
|
header("Authorization", "Bearer $token")
|
||||||
|
@ -501,7 +529,10 @@ class SecurityKtTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
|
routing {
|
||||||
|
auth(mock(), mock(), jwtService)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.post("/refresh-token") {
|
client.post("/refresh-token") {
|
||||||
header("Content-Type", "application/json")
|
header("Content-Type", "application/json")
|
||||||
|
@ -523,7 +554,10 @@ class SecurityKtTest {
|
||||||
application {
|
application {
|
||||||
configureStatusPages()
|
configureStatusPages()
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
|
routing {
|
||||||
|
auth(mock(), mock(), jwtService)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.post("/refresh-token") {
|
client.post("/refresh-token") {
|
||||||
header("Content-Type", "application/json")
|
header("Content-Type", "application/json")
|
||||||
|
|
|
@ -4,6 +4,8 @@ import com.auth0.jwt.interfaces.Claim
|
||||||
import com.auth0.jwt.interfaces.Payload
|
import com.auth0.jwt.interfaces.Payload
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import dev.usbharu.hideout.config.Config
|
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.Post
|
||||||
import dev.usbharu.hideout.domain.model.hideout.entity.Visibility
|
import dev.usbharu.hideout.domain.model.hideout.entity.Visibility
|
||||||
import dev.usbharu.hideout.plugins.TOKEN_AUTH
|
import dev.usbharu.hideout.plugins.TOKEN_AUTH
|
||||||
|
@ -32,18 +34,27 @@ class PostsTest {
|
||||||
environment {
|
environment {
|
||||||
config = ApplicationConfig("empty.conf")
|
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(
|
val posts = listOf(
|
||||||
Post(
|
PostResponse(
|
||||||
id = 12345,
|
id = 12345,
|
||||||
userId = 4321,
|
user = user,
|
||||||
text = "test1",
|
text = "test1",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
url = "https://example.com/posts/1"
|
url = "https://example.com/posts/1"
|
||||||
),
|
),
|
||||||
Post(
|
PostResponse(
|
||||||
id = 123456,
|
id = 123456,
|
||||||
userId = 4322,
|
user = user,
|
||||||
text = "test2",
|
text = "test2",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
|
@ -64,7 +75,7 @@ class PostsTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
posts(postService)
|
posts(postService)
|
||||||
|
@ -89,27 +100,35 @@ class PostsTest {
|
||||||
val payload = mock<Payload> {
|
val payload = mock<Payload> {
|
||||||
on { getClaim(eq("uid")) } doReturn claim
|
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(
|
val posts = listOf(
|
||||||
Post(
|
PostResponse(
|
||||||
id = 12345,
|
id = 12345,
|
||||||
userId = 4321,
|
user = user,
|
||||||
text = "test1",
|
text = "test1",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
url = "https://example.com/posts/1"
|
url = "https://example.com/posts/1"
|
||||||
),
|
),
|
||||||
Post(
|
PostResponse(
|
||||||
id = 123456,
|
id = 123456,
|
||||||
userId = 4322,
|
user = user,
|
||||||
text = "test2",
|
text = "test2",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
url = "https://example.com/posts/2"
|
url = "https://example.com/posts/2"
|
||||||
),
|
),
|
||||||
Post(
|
PostResponse(
|
||||||
id = 1234567,
|
id = 1234567,
|
||||||
userId = 4333,
|
user = user,
|
||||||
text = "Followers only",
|
text = "Followers only",
|
||||||
visibility = Visibility.FOLLOWERS,
|
visibility = Visibility.FOLLOWERS,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
|
@ -156,9 +175,18 @@ class PostsTest {
|
||||||
environment {
|
environment {
|
||||||
config = ApplicationConfig("empty.conf")
|
config = ApplicationConfig("empty.conf")
|
||||||
}
|
}
|
||||||
val post = Post(
|
val user = UserResponse(
|
||||||
12345,
|
id = 54321,
|
||||||
1234,
|
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",
|
text = "aaa",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
|
@ -169,7 +197,7 @@ class PostsTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
posts(postService)
|
posts(postService)
|
||||||
|
@ -187,9 +215,17 @@ class PostsTest {
|
||||||
environment {
|
environment {
|
||||||
config = ApplicationConfig("empty.conf")
|
config = ApplicationConfig("empty.conf")
|
||||||
}
|
}
|
||||||
val post = Post(
|
val post = PostResponse(
|
||||||
12345,
|
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",
|
text = "aaa",
|
||||||
visibility = Visibility.FOLLOWERS,
|
visibility = Visibility.FOLLOWERS,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
|
@ -242,14 +278,22 @@ class PostsTest {
|
||||||
onBlocking { createPost(any(), any()) } doAnswer {
|
onBlocking { createPost(any(), any()) } doAnswer {
|
||||||
val argument = it.getArgument<dev.usbharu.hideout.domain.model.hideout.form.Post>(0)
|
val argument = it.getArgument<dev.usbharu.hideout.domain.model.hideout.form.Post>(0)
|
||||||
val userId = it.getArgument<Long>(1)
|
val userId = it.getArgument<Long>(1)
|
||||||
Post(
|
PostResponse(
|
||||||
123L,
|
id = 123L,
|
||||||
userId,
|
user = UserResponse(
|
||||||
null,
|
id = 54321,
|
||||||
argument.text,
|
name = "user1",
|
||||||
Instant.now().toEpochMilli(),
|
domain = "example.com",
|
||||||
Visibility.PUBLIC,
|
screenName = "user 1",
|
||||||
"https://example.com"
|
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 {
|
environment {
|
||||||
config = ApplicationConfig("empty.conf")
|
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(
|
val posts = listOf(
|
||||||
Post(
|
PostResponse(
|
||||||
id = 12345,
|
id = 12345,
|
||||||
userId = 1,
|
user = user,
|
||||||
text = "test1",
|
text = "test1",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
url = "https://example.com/posts/1"
|
url = "https://example.com/posts/1"
|
||||||
),
|
),
|
||||||
Post(
|
PostResponse(
|
||||||
id = 123456,
|
id = 123456,
|
||||||
userId = 1,
|
user = user,
|
||||||
text = "test2",
|
text = "test2",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
|
@ -323,7 +376,7 @@ class PostsTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
posts(postService)
|
posts(postService)
|
||||||
|
@ -342,18 +395,27 @@ class PostsTest {
|
||||||
environment {
|
environment {
|
||||||
config = ApplicationConfig("empty.conf")
|
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(
|
val posts = listOf(
|
||||||
Post(
|
PostResponse(
|
||||||
id = 12345,
|
id = 12345,
|
||||||
userId = 1,
|
user = user,
|
||||||
text = "test1",
|
text = "test1",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
url = "https://example.com/posts/1"
|
url = "https://example.com/posts/1"
|
||||||
),
|
),
|
||||||
Post(
|
PostResponse(
|
||||||
id = 123456,
|
id = 123456,
|
||||||
userId = 1,
|
user = user,
|
||||||
text = "test2",
|
text = "test2",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
|
@ -375,7 +437,7 @@ class PostsTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
posts(postService)
|
posts(postService)
|
||||||
|
@ -394,18 +456,27 @@ class PostsTest {
|
||||||
environment {
|
environment {
|
||||||
config = ApplicationConfig("empty.conf")
|
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(
|
val posts = listOf(
|
||||||
Post(
|
PostResponse(
|
||||||
id = 12345,
|
id = 12345,
|
||||||
userId = 1,
|
user = user,
|
||||||
text = "test1",
|
text = "test1",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
url = "https://example.com/posts/1"
|
url = "https://example.com/posts/1"
|
||||||
),
|
),
|
||||||
Post(
|
PostResponse(
|
||||||
id = 123456,
|
id = 123456,
|
||||||
userId = 1,
|
user = user,
|
||||||
text = "test2",
|
text = "test2",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
|
@ -427,7 +498,7 @@ class PostsTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
posts(postService)
|
posts(postService)
|
||||||
|
@ -446,18 +517,27 @@ class PostsTest {
|
||||||
environment {
|
environment {
|
||||||
config = ApplicationConfig("empty.conf")
|
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(
|
val posts = listOf(
|
||||||
Post(
|
PostResponse(
|
||||||
id = 12345,
|
id = 12345,
|
||||||
userId = 1,
|
user = user,
|
||||||
text = "test1",
|
text = "test1",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
url = "https://example.com/posts/1"
|
url = "https://example.com/posts/1"
|
||||||
),
|
),
|
||||||
Post(
|
PostResponse(
|
||||||
id = 123456,
|
id = 123456,
|
||||||
userId = 1,
|
user = user,
|
||||||
text = "test2",
|
text = "test2",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
|
@ -479,7 +559,7 @@ class PostsTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
posts(postService)
|
posts(postService)
|
||||||
|
@ -498,9 +578,17 @@ class PostsTest {
|
||||||
environment {
|
environment {
|
||||||
config = ApplicationConfig("empty.conf")
|
config = ApplicationConfig("empty.conf")
|
||||||
}
|
}
|
||||||
val post = Post(
|
val post = PostResponse(
|
||||||
id = 123456,
|
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",
|
text = "test2",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
|
@ -511,7 +599,7 @@ class PostsTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
posts(postService)
|
posts(postService)
|
||||||
|
@ -530,9 +618,17 @@ class PostsTest {
|
||||||
environment {
|
environment {
|
||||||
config = ApplicationConfig("empty.conf")
|
config = ApplicationConfig("empty.conf")
|
||||||
}
|
}
|
||||||
val post = Post(
|
val post = PostResponse(
|
||||||
id = 123456,
|
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",
|
text = "test2",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
|
@ -543,7 +639,7 @@ class PostsTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
posts(postService)
|
posts(postService)
|
||||||
|
@ -562,9 +658,17 @@ class PostsTest {
|
||||||
environment {
|
environment {
|
||||||
config = ApplicationConfig("empty.conf")
|
config = ApplicationConfig("empty.conf")
|
||||||
}
|
}
|
||||||
val post = Post(
|
val post = PostResponse(
|
||||||
id = 123456,
|
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",
|
text = "test2",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
|
@ -575,7 +679,7 @@ class PostsTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
posts(postService)
|
posts(postService)
|
||||||
|
@ -594,9 +698,17 @@ class PostsTest {
|
||||||
environment {
|
environment {
|
||||||
config = ApplicationConfig("empty.conf")
|
config = ApplicationConfig("empty.conf")
|
||||||
}
|
}
|
||||||
val post = Post(
|
val post = PostResponse(
|
||||||
id = 123456,
|
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",
|
text = "test2",
|
||||||
visibility = Visibility.PUBLIC,
|
visibility = Visibility.PUBLIC,
|
||||||
createdAt = Instant.now().toEpochMilli(),
|
createdAt = Instant.now().toEpochMilli(),
|
||||||
|
@ -607,7 +719,7 @@ class PostsTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
posts(postService)
|
posts(postService)
|
||||||
|
|
|
@ -58,7 +58,7 @@ class UsersTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
users(mock(), userService)
|
users(mock(), userService)
|
||||||
|
@ -96,7 +96,7 @@ class UsersTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
users(userService, mock())
|
users(userService, mock())
|
||||||
|
@ -127,7 +127,7 @@ class UsersTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
users(userService, mock())
|
users(userService, mock())
|
||||||
|
@ -162,7 +162,7 @@ class UsersTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
users(mock(), userApiService)
|
users(mock(), userApiService)
|
||||||
|
@ -195,7 +195,7 @@ class UsersTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
users(mock(), userApiService)
|
users(mock(), userApiService)
|
||||||
|
@ -228,7 +228,7 @@ class UsersTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
users(mock(), userApiService)
|
users(mock(), userApiService)
|
||||||
|
@ -261,7 +261,7 @@ class UsersTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
users(mock(), userApiService)
|
users(mock(), userApiService)
|
||||||
|
@ -306,7 +306,7 @@ class UsersTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
users(mock(), userApiService)
|
users(mock(), userApiService)
|
||||||
|
@ -351,7 +351,7 @@ class UsersTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
users(mock(), userApiService)
|
users(mock(), userApiService)
|
||||||
|
@ -396,7 +396,7 @@ class UsersTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
users(mock(), userApiService)
|
users(mock(), userApiService)
|
||||||
|
@ -591,7 +591,7 @@ class UsersTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
users(mock(), userApiService)
|
users(mock(), userApiService)
|
||||||
|
@ -636,7 +636,7 @@ class UsersTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
users(mock(), userApiService)
|
users(mock(), userApiService)
|
||||||
|
@ -681,7 +681,7 @@ class UsersTest {
|
||||||
}
|
}
|
||||||
application {
|
application {
|
||||||
configureSerialization()
|
configureSerialization()
|
||||||
configureSecurity(mock())
|
configureSecurity(mock(), mock())
|
||||||
routing {
|
routing {
|
||||||
route("/api/internal/v1") {
|
route("/api/internal/v1") {
|
||||||
users(mock(), userApiService)
|
users(mock(), userApiService)
|
||||||
|
|
|
@ -48,13 +48,21 @@ class ActivityPubReceiveFollowServiceImplTest {
|
||||||
firstValue.invoke(scheduleContext, ReceiveFollowJob)
|
firstValue.invoke(scheduleContext, ReceiveFollowJob)
|
||||||
val actor = scheduleContext.props.props[ReceiveFollowJob.actor.name]
|
val actor = scheduleContext.props.props[ReceiveFollowJob.actor.name]
|
||||||
val targetActor = scheduleContext.props.props[ReceiveFollowJob.targetActor.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://follower.example.com", actor)
|
||||||
assertEquals("https://example.com", targetActor)
|
assertEquals("https://example.com", targetActor)
|
||||||
//language=JSON
|
//language=JSON
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"""{"type":"Follow","name":"Follow","actor":"https://follower.example.com","object":"https://example.com","@context":null}""",
|
Json.parseToJsonElement(
|
||||||
follow
|
"""{
|
||||||
|
"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<String, Any>(
|
data = mapOf<String, Any>(
|
||||||
ReceiveFollowJob.actor.name to "https://follower.example.com",
|
ReceiveFollowJob.actor.name to "https://follower.example.com",
|
||||||
ReceiveFollowJob.targetActor.name to "https://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
|
json = Json
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue