From 9bf7d5af684f4b63a840bd4cd59035d791225653 Mon Sep 17 00:00:00 2001 From: John Zhang Date: Sat, 9 Apr 2022 15:54:23 +1000 Subject: [PATCH] fix duplicate test --- .../test/io/ktor/client/tests/CookiesTest.kt | 226 ------------------ .../ktor/client/tests/plugins/CookiesTest.kt | 2 +- 2 files changed, 1 insertion(+), 227 deletions(-) delete mode 100644 ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/CookiesTest.kt diff --git a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/CookiesTest.kt b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/CookiesTest.kt deleted file mode 100644 index c90ab03276..0000000000 --- a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/CookiesTest.kt +++ /dev/null @@ -1,226 +0,0 @@ -/* -* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. -*/ - -package io.ktor.client.tests - -import io.ktor.client.* -import io.ktor.client.call.* -import io.ktor.client.plugins.cookies.* -import io.ktor.client.request.* -import io.ktor.client.statement.* -import io.ktor.client.tests.utils.* -import io.ktor.http.* -import kotlin.test.* - -class CookiesTest : ClientLoader() { - private val hostname = "http://127.0.0.1/cookies" - private val TEST_HOST = "$TEST_SERVER/cookies" - private val domain = "127.0.0.1" - - @Test - fun testAccept() = clientTests(listOf("Js")) { - config { - install(HttpCookies) - } - - test { client -> - client.get(TEST_HOST).body() - client.cookies(hostname).let { - assertEquals(1, it.size) - assertEquals("my-awesome-value", it["hello-cookie"]!!.value) - } - } - } - - @Test - fun testUpdate() = clientTests(listOf("Js")) { - config { - install(HttpCookies) { - default { - addCookie(hostname, Cookie("id", "1", domain = domain)) - } - } - } - - test { client -> - repeat(10) { - val before = client.getId() - client.get("$TEST_HOST/update-user-id").body() - assertEquals(before + 1, client.getId()) - assertEquals("ktor", client.cookies(hostname)["user"]?.value) - } - } - } - - @Test - fun testExpiration() = clientTests(listOf("Js")) { - config { - install(HttpCookies) { - default { - addCookie(hostname, Cookie("id", "777", domain = domain, path = "/")) - } - } - - test { client -> - assertFalse(client.cookies(hostname).isEmpty()) - client.get("$TEST_HOST/expire").body() - assertTrue(client.cookies(hostname).isEmpty(), "cookie should be expired") - } - } - } - - @Test - fun testConstant() = clientTests(listOf("Js")) { - config { - install(HttpCookies) { - storage = ConstantCookiesStorage(Cookie("id", "1", domain = domain)) - } - } - - test { client -> - repeat(3) { - client.get("$TEST_HOST/update-user-id").body() - assertEquals(1, client.getId()) - assertNull(client.cookies(hostname)["user"]?.value) - } - } - } - - @Test - fun testMultipleCookies() = clientTests(listOf("Js")) { - config { - install(HttpCookies) { - default { - addCookie(hostname, Cookie("first", "first-cookie", domain = domain)) - addCookie(hostname, Cookie("second", "second-cookie", domain = domain)) - } - } - } - - test { client -> - val response = client.get("$TEST_HOST/multiple").body() - assertEquals("Multiple done", response) - } - } - - @Test - fun testPath() = clientTests(listOf("js")) { - config { - install(HttpCookies) - } - - test { client -> - assertEquals("OK", client.get("$TEST_HOST/withPath").body()) - assertEquals("OK", client.get("$TEST_HOST/withPath/something").body()) - } - } - - @Test - fun testWithLeadingDot() = clientTests(listOf("Js", "Darwin", "native:CIO")) { - config { - install(HttpCookies) - } - - test { client -> - client.get("https://m.vk.com").body() - assertTrue(client.cookies("https://.vk.com").isNotEmpty()) - assertTrue(client.cookies("https://vk.com").isNotEmpty()) - assertTrue(client.cookies("https://m.vk.com").isNotEmpty()) - assertTrue(client.cookies("https://m.vk.com").isNotEmpty()) - - assertTrue(client.cookies("https://google.com").isEmpty()) - } - } - - @Test - fun caseSensitive() = clientTests(listOf("Js", "Darwin")) { - config { - install(HttpCookies) - } - - test { client -> - try { - client.get("$TEST_HOST/foo").body() - client.get("$TEST_HOST/FOO").body() - } catch (cause: Throwable) { - throw cause - } - } - } - - @Test - fun testMultipleCookiesWithComma() = clientTests(listOf("Js")) { - config { - install(HttpCookies) { - default { - addCookie(hostname, Cookie("fir,st", "first, cookie", domain = domain)) - addCookie(hostname, Cookie("sec,ond", "second, cookie", domain = domain)) - } - } - } - - test { client -> - val response = client.get("$TEST_HOST/multiple-comma").body() - val cookies = client.cookies(hostname) - assertEquals("first, cookie", cookies["fir,st"]!!.value) - assertEquals("second, cookie", cookies["sec,ond"]!!.value) - assertEquals("third cookie", cookies["third"]!!.value) - assertEquals("fourth cookie", cookies["fourth"]!!.value) - - assertEquals("Multiple done", response) - } - } - - @Test - fun testCookiesEncodedWithRespectiveEncoding() = clientTests(listOf("Js")) { - val cookies = listOf( - Cookie("uri", "first, cookie", domain = domain, encoding = CookieEncoding.URI_ENCODING), - Cookie("raw", "first%2C+cookie", domain = domain, encoding = CookieEncoding.RAW), - Cookie("base64", "first, cookie", domain = domain, encoding = CookieEncoding.BASE64_ENCODING), - Cookie("dquotes", "first, cookie", domain = domain, encoding = CookieEncoding.DQUOTES) - ) - config { - install(HttpCookies) { - default { - cookies.forEach { addCookie(hostname, it) } - } - } - } - - test { client -> - client.prepareGet("$TEST_HOST/encoded").execute { httpResponse -> - val response = httpResponse.bodyAsText() - val cookieStrings = response.split("; ").filter { it.isNotBlank() } - assertEquals(4, cookieStrings.size) - assertEquals("uri=first%2C+cookie", cookieStrings[0]) - assertEquals("raw=first%2C+cookie", cookieStrings[1]) - assertEquals("base64=Zmlyc3QsIGNvb2tpZQ==", cookieStrings[2]) - assertEquals("dquotes=\"first, cookie\"", cookieStrings[3]) - } - } - } - - @Test - fun testRequestBuilderSingleCookie() = clientTests(listOf("Js")) { - test { client -> - val result = client.get("$TEST_HOST/respond-single-cookie") { - cookie("single", value = "abacaba") - }.body() - assertEquals("abacaba", result) - } - } - - @Test - fun testRequestBuilderMultipleCookies() = clientTests(listOf("Js")) { - test { client -> - val result = client.get("$TEST_HOST/respond-a-minus-b") { - cookie("a", value = "10") - cookie("b", value = "4") - }.body() - assertEquals("6", result) - } - } - - private suspend fun HttpClient.getId() = cookies(hostname)["id"]!!.value.toInt() -} diff --git a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/plugins/CookiesTest.kt b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/plugins/CookiesTest.kt index 6e7b1f0ddb..152886f432 100644 --- a/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/plugins/CookiesTest.kt +++ b/ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/plugins/CookiesTest.kt @@ -192,7 +192,7 @@ class CookiesTest : ClientLoader() { test { client -> client.prepareGet("$TEST_HOST/encoded").execute { httpResponse -> val response = httpResponse.bodyAsText() - val cookieStrings = response.split(";").filter { it.isNotBlank() } + val cookieStrings = response.split("; ").filter { it.isNotBlank() } assertEquals(4, cookieStrings.size) assertEquals("uri=first%2C+cookie", cookieStrings[0]) assertEquals("raw=first%2C+cookie", cookieStrings[1])