aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorJakob Odersky <jakob@driver.xyz>2018-08-22 12:51:36 -0700
committerJakob Odersky <jakob@driver.xyz>2018-09-12 14:17:39 -0700
commit5ec270aa98b806f32338fa25357abdf45dd0625b (patch)
treef1423f8add00cc2f899d2f8259b9ab33ba3c914b /src/test
parent3eb6a9e96bd8bf111490f390ea94a1c6d7677eff (diff)
downloaddriver-core-5ec270aa98b806f32338fa25357abdf45dd0625b.tar.gz
driver-core-5ec270aa98b806f32338fa25357abdf45dd0625b.tar.bz2
driver-core-5ec270aa98b806f32338fa25357abdf45dd0625b.zip
Trait-based initialization and other utilities
Adds the concept of a 'platform', a centralized place in which environment-specific information will be managed, and provides common initialization logic for most "standard" apps. As part of the common initialization, other parts of core have also been reworked: - HTTP-related unmarshallers and path matchers have been factored out from core.json to a new core.rest.directives package (core.json extends those unmarshallers and matchers for backwards compatibility) - CORS handling has also been moved to a dedicated utility trait - Some custom headers have been moved from raw headers to typed ones in core.rest.headers - The concept of a "reporter" has been introduced. A reporter is a context-aware combination of tracing and logging. It is intended to issue diagnostic messages that can be traced across service boundaries. Closes #192 Closes #195
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/xyz/driver/core/rest/DriverAppTest.scala18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/test/scala/xyz/driver/core/rest/DriverAppTest.scala b/src/test/scala/xyz/driver/core/rest/DriverAppTest.scala
index 118024a..324c8d8 100644
--- a/src/test/scala/xyz/driver/core/rest/DriverAppTest.scala
+++ b/src/test/scala/xyz/driver/core/rest/DriverAppTest.scala
@@ -12,16 +12,16 @@ class DriverAppTest extends AsyncFlatSpec with ScalatestRouteTest with Matchers
val config = ConfigFactory.parseString("""
|application {
| cors {
- | allowedMethods: ["GET", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"]
- | allowedOrigins: [{scheme: https, hostSuffix: example.com}]
+ | allowedOrigins: ["example.com"]
| }
|}
""".stripMargin).withFallback(ConfigFactory.load)
+ val origin = Origin(HttpOrigin("https", Host("example.com")))
val allowedOrigins = Set(HttpOrigin("https", Host("example.com")))
val allowedMethods: collection.immutable.Seq[HttpMethod] = {
import akka.http.scaladsl.model.HttpMethods._
- collection.immutable.Seq(GET, PUT, POST, PATCH, DELETE, OPTIONS)
+ collection.immutable.Seq(GET, PUT, POST, PATCH, DELETE, OPTIONS, TRACE)
}
import scala.reflect.runtime.universe.typeOf
@@ -37,7 +37,7 @@ class DriverAppTest extends AsyncFlatSpec with ScalatestRouteTest with Matchers
it should "respond with the correct CORS headers for the swagger OPTIONS route" in {
val route = new TestApp(get(complete(StatusCodes.OK)))
- Options(s"/api-docs/swagger.json") ~> route.appRoute ~> check {
+ Options(s"/api-docs/swagger.json").withHeaders(origin) ~> route.appRoute ~> check {
status shouldBe StatusCodes.OK
headers should contain(`Access-Control-Allow-Origin`(HttpOriginRange(allowedOrigins.toSeq: _*)))
header[`Access-Control-Allow-Methods`].get.methods should contain theSameElementsAs allowedMethods
@@ -46,19 +46,17 @@ class DriverAppTest extends AsyncFlatSpec with ScalatestRouteTest with Matchers
it should "respond with the correct CORS headers for the test route" in {
val route = new TestApp(get(complete(StatusCodes.OK)))
- Get(s"/api/v1/test") ~> route.appRoute ~> check {
+ Get(s"/api/v1/test").withHeaders(origin) ~> route.appRoute ~> check {
status shouldBe StatusCodes.OK
headers should contain(`Access-Control-Allow-Origin`(HttpOriginRange(allowedOrigins.toSeq: _*)))
- header[`Access-Control-Allow-Methods`].get.methods should contain theSameElementsAs allowedMethods
}
}
it should "respond with the correct CORS headers for a concatenated route" in {
val route = new TestApp(get(complete(StatusCodes.OK)) ~ post(complete(StatusCodes.OK)))
- Post(s"/api/v1/test") ~> route.appRoute ~> check {
+ Post(s"/api/v1/test").withHeaders(origin) ~> route.appRoute ~> check {
status shouldBe StatusCodes.OK
headers should contain(`Access-Control-Allow-Origin`(HttpOriginRange(allowedOrigins.toSeq: _*)))
- header[`Access-Control-Allow-Methods`].get.methods should contain theSameElementsAs allowedMethods
}
}
@@ -68,7 +66,6 @@ class DriverAppTest extends AsyncFlatSpec with ScalatestRouteTest with Matchers
.withHeaders(Origin(HttpOrigin("https", Host("foo.example.com")))) ~> route.appRoute ~> check {
status shouldBe StatusCodes.OK
headers should contain(`Access-Control-Allow-Origin`(HttpOrigin("https", Host("foo.example.com"))))
- header[`Access-Control-Allow-Methods`].get.methods should contain theSameElementsAs allowedMethods
}
}
@@ -77,8 +74,7 @@ class DriverAppTest extends AsyncFlatSpec with ScalatestRouteTest with Matchers
Get(s"/api/v1/test")
.withHeaders(Origin(HttpOrigin("https", Host("invalid.foo.bar.com")))) ~> route.appRoute ~> check {
status shouldBe StatusCodes.OK
- headers should contain(`Access-Control-Allow-Origin`(HttpOriginRange(allowedOrigins.toSeq: _*)))
- header[`Access-Control-Allow-Methods`].get.methods should contain theSameElementsAs allowedMethods
+ headers should contain(`Access-Control-Allow-Origin`(HttpOriginRange.*))
}
}