-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(conformance): tests and move to other suite for e2e validation
- Loading branch information
Showing
4 changed files
with
156 additions
and
89 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
103 changes: 103 additions & 0 deletions
103
zio-http/jvm/src/test/scala/zio/http/ConformanceE2ESpec.scala
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,103 @@ | ||
package zio.http | ||
|
||
import zio._ | ||
import zio.test.Assertion._ | ||
import zio.test.TestAspect._ | ||
import zio.test._ | ||
|
||
import zio.http._ | ||
import zio.http.internal.{DynamicServer, RoutesRunnableSpec} | ||
import zio.http.netty.NettyConfig | ||
|
||
object ConformanceE2ESpec extends RoutesRunnableSpec { | ||
|
||
private val port = 8080 | ||
private val MaxSize = 1024 * 10 | ||
val configApp = Server.Config.default | ||
.requestDecompression(true) | ||
.disableRequestStreaming(MaxSize) | ||
.port(port) | ||
.responseCompression() | ||
|
||
private val app = serve | ||
|
||
def conformanceSpec = suite("ConformanceE2ESpec")( | ||
test("should return 400 Bad Request if Host header is missing") { | ||
val routes = Handler.ok.toRoutes | ||
|
||
val res = routes.deploy.status.run(path = Path.root, headers = Headers(Header.Host("%%%%invalid%%%%"))) | ||
assertZIO(res)(equalTo(Status.BadRequest)) | ||
}, | ||
test("should return 200 OK if Host header is present") { | ||
val routes = Handler.ok.toRoutes | ||
|
||
val res = routes.deploy.status.run(path = Path.root, headers = Headers(Header.Host("localhost"))) | ||
assertZIO(res)(equalTo(Status.Ok)) | ||
}, | ||
test("should reply with 501 for unknown HTTP methods (code_501_unknown_methods)") { | ||
val routes = Handler.ok.toRoutes | ||
|
||
val res = routes.deploy.status.run(path = Path.root, method = Method.CUSTOM("ABC")) | ||
|
||
assertZIO(res)(equalTo(Status.NotImplemented)) | ||
}, | ||
test( | ||
"should reply with 405 when the request method is not allowed for the target resource (code_405_blocked_methods)", | ||
) { | ||
val routes = Handler.ok.toRoutes | ||
|
||
val res = routes.deploy.status.run(path = Path.root, method = Method.CONNECT) | ||
assertZIO(res)(equalTo(Status.MethodNotAllowed)) | ||
}, | ||
test("should return 400 Bad Request if header contains CR, LF, or NULL (reject_fields_containing_cr_lf_nul)") { | ||
val routes = Handler.ok.toRoutes | ||
|
||
val resCRLF = | ||
routes.deploy.status.run(path = Path.root / "test", headers = Headers("InvalidHeader" -> "Value\r\n")) | ||
val resNull = | ||
routes.deploy.status.run(path = Path.root / "test", headers = Headers("InvalidHeader" -> "Value\u0000")) | ||
|
||
for { | ||
responseCRLF <- resCRLF | ||
responseNull <- resNull | ||
} yield assertTrue( | ||
responseCRLF == Status.BadRequest, | ||
responseNull == Status.BadRequest, | ||
) | ||
}, | ||
test("should return 400 Bad Request if there is whitespace between start-line and first header field") { | ||
val route = Method.GET / "test" -> Handler.ok | ||
val routes = Routes(route) | ||
|
||
val malformedRequest = Request | ||
.get("/test") | ||
.copy(headers = Headers.empty) | ||
.withBody(Body.fromString("\r\nHost: localhost")) | ||
|
||
val res = routes.deploy.status.run(path = Path.root / "test", headers = malformedRequest.headers) | ||
assertZIO(res)(equalTo(Status.BadRequest)) | ||
}, | ||
test("should return 400 Bad Request if there is whitespace between header field and colon") { | ||
val route = Method.GET / "test" -> Handler.ok | ||
val routes = Routes(route) | ||
|
||
val requestWithWhitespaceHeader = Request.get("/test").addHeader(Header.Custom("Invalid Header ", "value")) | ||
|
||
val res = routes.deploy.status.run(path = Path.root / "test", headers = requestWithWhitespaceHeader.headers) | ||
assertZIO(res)(equalTo(Status.BadRequest)) | ||
}, | ||
) | ||
|
||
override def spec = | ||
suite("ConformanceE2ESpec") { | ||
val spec = conformanceSpec | ||
suite("app without request streaming") { app.as(List(spec)) } | ||
}.provideShared( | ||
DynamicServer.live, | ||
ZLayer.succeed(configApp), | ||
Server.customized, | ||
Client.default, | ||
ZLayer.succeed(NettyConfig.default), | ||
) @@ sequential @@ withLiveClock | ||
|
||
} |
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