Skip to content

Commit d720899

Browse files
marychattee5l
authored andcommitted
KTOR-3391 Fix Digest Auth: algorithm isn't specified in the Authorization header (#3732)
(cherry picked from commit 0d63c4d)
1 parent ddc3ff3 commit d720899

File tree

3 files changed

+32
-1
lines changed
  • buildSrc/src/main/kotlin/test/server/tests
  • ktor-client/ktor-client-plugins/ktor-client-auth/common

3 files changed

+32
-1
lines changed

buildSrc/src/main/kotlin/test/server/tests/Auth.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ internal fun Application.authTestServer() {
4343
}
4444
}
4545

46+
digest("digest-SHA256") {
47+
val password = "Circle Of Life"
48+
algorithmName = "SHA-256"
49+
50+
51+
digestProvider { userName, realm ->
52+
digest(MessageDigest.getInstance(algorithmName), "$userName:$realm:$password")
53+
}
54+
}
55+
4656
basic("basic") {
4757
validate { credential ->
4858
check("MyUser" == credential.name)
@@ -86,6 +96,11 @@ internal fun Application.authTestServer() {
8696
call.respondText("ok")
8797
}
8898
}
99+
authenticate("digest-SHA256") {
100+
get("digest-SHA256") {
101+
call.respondText("ok")
102+
}
103+
}
89104
authenticate("basic") {
90105
get("basic-fixed") {
91106
call.respondText("ok")

ktor-client/ktor-client-plugins/ktor-client-auth/common/src/io/ktor/client/plugins/auth/providers/DigestAuthProvider.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public class DigestAuthProvider(
189189
this["uri"] = url.fullPath
190190
actualQop?.let { this["qop"] = it }
191191
this["nc"] = nonceCount.toString()
192+
this["algorithm"] = algorithmName
192193
}
193194
)
194195

ktor-client/ktor-client-plugins/ktor-client-auth/common/test/io/ktor/client/plugins/auth/AuthTest.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import io.ktor.client.tests.utils.*
1515
import io.ktor.http.*
1616
import io.ktor.http.auth.*
1717
import io.ktor.test.dispatcher.*
18-
import io.ktor.util.*
1918
import io.ktor.utils.io.errors.*
2019
import kotlinx.coroutines.*
2120
import kotlin.test.*
@@ -83,6 +82,22 @@ class AuthTest : ClientLoader() {
8382
}
8483
}
8584

85+
@Test
86+
fun testDigestAuthSHA256() = clientTests(listOf("Js", "native")) {
87+
config {
88+
install(Auth) {
89+
digest {
90+
algorithmName = "SHA-256"
91+
credentials { DigestAuthCredentials("MyName", "Circle Of Life") }
92+
93+
}
94+
}
95+
}
96+
test { client ->
97+
assertTrue(client.get("$TEST_SERVER/auth/digest-SHA256").status.isSuccess())
98+
}
99+
}
100+
86101
@Suppress("DEPRECATION")
87102
@Test
88103
fun testBasicAuthLegacy() = clientTests(listOf("Js")) {

0 commit comments

Comments
 (0)