Skip to content

Commit

Permalink
KTOR-6646 Fix overflow for cookie with long Max-Age (#3985)
Browse files Browse the repository at this point in the history
  • Loading branch information
marychatte committed Mar 11, 2024
1 parent 33b243a commit 313b381
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ public class AcceptAllCookiesStorage(private val clock: () -> Long = { getTimeMi
}

private fun Cookie.maxAgeOrExpires(createdAt: Long): Long? =
maxAge?.let { createdAt + it * 1000 } ?: expires?.timestamp
maxAge?.let { createdAt + it * 1000L } ?: expires?.timestamp
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@ class AcceptAllCookiesStorageTest {
time += 1001
assertEquals(emptyList(), storage.get(Url("http://localhost/")))
}

@Test
fun testLongMaxAge() = testSuspend {
val storage = AcceptAllCookiesStorage()
val twoYears = 2 * 365 * 24 * 3600
val cookie = Cookie("name", "value", maxAge = twoYears)
storage.addCookie(Url("/"), cookie)

assertEquals(cookie.value, storage.get(Url("/")).single().value)
}
}

0 comments on commit 313b381

Please sign in to comment.