aboutsummaryrefslogtreecommitdiff
path: root/tests/src/test/scala/com
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-07-15 11:59:10 +0200
committeradamw <adam@warski.org>2017-07-15 11:59:10 +0200
commit8d9145a04cdd21a471fba61fc19203759b95514d (patch)
tree0d5eb11f6c87ed8d2f41b483e381852d871c8ee1 /tests/src/test/scala/com
parentbc685df2cd50814b45e669f4f602732887c2879c (diff)
downloadsttp-8d9145a04cdd21a471fba61fc19203759b95514d.tar.gz
sttp-8d9145a04cdd21a471fba61fc19203759b95514d.tar.bz2
sttp-8d9145a04cdd21a471fba61fc19203759b95514d.zip
Cookie parsing
Diffstat (limited to 'tests/src/test/scala/com')
-rw-r--r--tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala
index 86d28a9..5d21d6f 100644
--- a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala
+++ b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala
@@ -2,10 +2,12 @@ package com.softwaremill.sttp
import java.io.ByteArrayInputStream
import java.net.URI
+import java.time.{ZoneId, ZonedDateTime}
import akka.stream.ActorMaterializer
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
+import akka.http.scaladsl.model.DateTime
import akka.http.scaladsl.model.headers._
import akka.http.scaladsl.model.headers.CacheDirectives._
import akka.http.scaladsl.server.Directives._
@@ -56,6 +58,32 @@ class BasicTests
}
}
}
+ } ~ pathPrefix("set_cookies") {
+ path("with_expires") {
+ setCookie(
+ HttpCookie("c",
+ "v",
+ expires = Some(DateTime(1997, 12, 8, 12, 49, 12)))) {
+ complete("ok")
+ }
+ } ~ get {
+ setCookie(
+ HttpCookie("cookie1",
+ "value1",
+ secure = true,
+ httpOnly = true,
+ maxAge = Some(123L))) {
+ setCookie(HttpCookie("cookie2", "value2")) {
+ setCookie(
+ HttpCookie("cookie3",
+ "",
+ domain = Some("xyz"),
+ path = Some("a/b/c"))) {
+ complete("ok")
+ }
+ }
+ }
+ }
}
private implicit val actorSystem: ActorSystem = ActorSystem("sttp-test")
@@ -102,6 +130,7 @@ class BasicTests
bodyTests()
headerTests()
errorsTests()
+ cookiesTests()
def parseResponseTests(): Unit = {
name should "parse response as string" in {
@@ -197,5 +226,43 @@ class BasicTests
resp.isClientError should be(true)
}
}
+
+ def cookiesTests(): Unit = {
+ name should "read response cookies" in {
+ val wrappedResponse =
+ sttp.get(new URI(endpoint + "/set_cookies")).send(ignoreResponse)
+ val response = forceResponse.force(wrappedResponse)
+ response.cookies should have length (3)
+ response.cookies.toSet should be(
+ Set(
+ Cookie("cookie1",
+ "value1",
+ secure = true,
+ httpOnly = true,
+ maxAge = Some(123L)),
+ Cookie("cookie2", "value2"),
+ Cookie("cookie3", "", domain = Some("xyz"), path = Some("a/b/c"))
+ ))
+ }
+
+ name should "read response cookies with the expires attribute" in {
+ val wrappedResponse = sttp
+ .get(new URI(endpoint + "/set_cookies/with_expires"))
+ .send(ignoreResponse)
+ val response = forceResponse.force(wrappedResponse)
+ response.cookies should have length (1)
+ val c = response.cookies(0)
+
+ c.name should be("c")
+ c.value should be("v")
+ c.expires.map(_.toInstant.toEpochMilli) should be(
+ Some(
+ ZonedDateTime
+ .of(1997, 12, 8, 12, 49, 12, 0, ZoneId.of("GMT"))
+ .toInstant
+ .toEpochMilli
+ ))
+ }
+ }
}
}