Открыть боковую панель
Aurora OS
Kotlin Multiplatform
Libraries
ktor
Коммиты
0beebb9b
Не подтверждена
Коммит
0beebb9b
создал
Сен 06, 2022
по автору
Leonid Stashevsky
Зафиксировано автором
GitHub
Сен 06, 2022
Просмотр файлов
KTOR-678 Add test for Auth with Jackson (#3154)
владелец
4657cb29
Изменения
2
Скрыть пробелы
Построчно
Рядом
ktor-server/ktor-server-plugins/ktor-server-auth/build.gradle.kts
Просмотр файла @
0beebb9b
...
...
@@ -26,5 +26,11 @@ kotlin {
api
(
project
(
":ktor-server:ktor-server-test-host"
))
}
}
jvmTest
{
dependencies
{
api
(
project
(
":ktor-server:ktor-server-plugins:ktor-server-content-negotiation"
))
api
(
project
(
":ktor-shared:ktor-serialization:ktor-serialization-jackson"
))
}
}
}
}
ktor-server/ktor-server-plugins/ktor-server-auth/jvm/test/io/ktor/tests/auth/AuthWithPlugins.kt
0 → 100644
Просмотр файла @
0beebb9b
/*
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
package
io.ktor.tests.auth
import
io.ktor.client.request.*
import
io.ktor.http.*
import
io.ktor.serialization.jackson.*
import
io.ktor.server.application.*
import
io.ktor.server.auth.*
import
io.ktor.server.plugins.contentnegotiation.*
import
io.ktor.server.response.*
import
io.ktor.server.routing.*
import
io.ktor.server.testing.*
import
kotlin.test.*
class
AuthWithPlugins
{
@Test
fun
testFormAuthWithJackson
()
=
testApplication
{
install
(
ContentNegotiation
)
{
jackson
()
}
install
(
Authentication
)
{
form
{
challenge
(
"/unauthorized"
)
validate
{
credentials
->
if
(
credentials
.
name
==
credentials
.
password
)
{
UserIdPrincipal
(
credentials
.
name
)
}
else
{
null
}
}
}
}
routing
{
get
(
"/unauthorized"
)
{
call
.
respond
(
HttpStatusCode
.
Unauthorized
,
"Unauthorized"
)
}
authenticate
{
post
(
"/test"
)
{
call
.
respondText
(
"OK"
)
}
}
}
val
response
=
client
.
post
(
"/test"
)
{
header
(
HttpHeaders
.
ContentType
,
ContentType
.
Application
.
Json
)
setBody
(
"{}"
)
}
assertEquals
(
HttpStatusCode
.
Found
,
response
.
status
)
val
location
=
response
.
headers
[
HttpHeaders
.
Location
]
?:
fail
(
"Location header is missing"
)
assertEquals
(
"/unauthorized"
,
location
)
}
}
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать