Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KTOR-917 Keep some characters in cookie URI encoding according to RFC…
… 3986
- Loading branch information
Showing
8 changed files
with
277 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...tor-server-tests/jvmAndNix/test/io/ktor/tests/server/plugins/Base64EncodingCookiesTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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.server.plugins | ||
|
||
import io.ktor.http.* | ||
import kotlin.test.* | ||
|
||
class Base64EncodingCookiesTest { | ||
@Test | ||
fun `no bad characters`() { | ||
testEncode("YWJj", "abc") | ||
} | ||
|
||
@Test | ||
fun `space inside`() { | ||
testEncode("YWJjIDEyMw==", "abc 123") | ||
} | ||
|
||
@Test | ||
fun `equals inside`() { | ||
testEncode("YWJjPTEyMw==", "abc=123") | ||
} | ||
|
||
private fun testEncode(expected: String, value: String): String { | ||
val encoded = encodeCookieValue(value, CookieEncoding.BASE64_ENCODING) | ||
assertEquals(expected, encoded, "Encode failed") | ||
assertEquals(value, decodeCookieValue(encoded, CookieEncoding.BASE64_ENCODING), "Decode failed") | ||
return encoded | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...or-server-tests/jvmAndNix/test/io/ktor/tests/server/plugins/DQuotesCookiesEncodingTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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.server.plugins | ||
|
||
import io.ktor.http.* | ||
import kotlin.test.* | ||
|
||
class DQuotesCookiesEncodingTest { | ||
@Test | ||
fun `no bad characters`() { | ||
testEncode("abc", "abc") | ||
} | ||
|
||
@Test | ||
fun `space inside`() { | ||
testEncode("\"abc 123\"", "abc 123") | ||
} | ||
|
||
@Test | ||
fun `equals inside`() { | ||
testEncode("abc=123", "abc=123") | ||
} | ||
|
||
private fun testEncode(expected: String, value: String) { | ||
val encoded = encodeCookieValue(value, CookieEncoding.DQUOTES) | ||
assertEquals(expected, encoded, "Encode failed") | ||
assertEquals(value, decodeCookieValue(encoded, CookieEncoding.DQUOTES), "Decode failed") | ||
} | ||
} |
Oops, something went wrong.