【发布时间】:2021-10-08 08:16:08
【问题描述】:
我有以下路线:
get("/user") {
val principal: UserIdPrincipal = call.principal()
?: return@get call.respond(HttpStatusCode.Unauthorized)
val user = userService.findUserForId(principal.name.toLong())
?: return@get call.respond(HttpStatusCode.Unauthorized)
val userResponse = UserResponse(username = user.username)
call.respond(userResponse)
}
我不想测试身份验证是否适用于我的每条路由,所以我想模拟call.principal()。由于它是内联扩展函数,因此不能轻易模拟。任何想法如何解决这个问题?
【问题讨论】:
标签: ktor