-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sourcing maxInitialLineLength through the config and propagating it t…
…o netty's configuration (#2561) developing feature and testing Co-authored-by: hdriviere <[email protected]>
- Loading branch information
Showing
6 changed files
with
96 additions
and
3 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
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
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
59 changes: 59 additions & 0 deletions
59
zio-http/src/test/scala/zio/http/NettyMaxInitialLineLengthSpec.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,59 @@ | ||
/* | ||
* Copyright 2021 - 2023 Sporta Technologies PVT LTD & the ZIO HTTP contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package zio.http | ||
|
||
import zio.test.TestAspect.withLiveClock | ||
import zio.test._ | ||
import zio.{Scope, ZLayer} | ||
|
||
object NettyMaxInitialLineLength extends ZIOHttpSpec { | ||
val minimalInitialLineLength: Int = "GET / HTTP/1.1".getBytes.length | ||
|
||
def extractStatus(response: Response): Status = response.status | ||
|
||
private val serverConfig: Server.Config = | ||
Server.Config.default.onAnyOpenPort.copy(maxInitialLineLength = minimalInitialLineLength) | ||
|
||
override def spec: Spec[TestEnvironment with Scope, Any] = | ||
test("should get a failure instead of an empty body") { | ||
val app = Handler | ||
.fromFunctionZIO[Request] { request => | ||
request.body.asString.map { body => | ||
val responseBody = if (body.isEmpty) "<empty>" else body | ||
Response.text(responseBody) | ||
} // this should not be run, as the request is invalid | ||
} | ||
.sandbox | ||
.toHttpApp | ||
for { | ||
port <- Server.install(app) | ||
url = URL | ||
.decode(s"http://localhost:$port/a%20looooooooooooooooooooooooooooong%20query%20parameter") | ||
.toOption | ||
.get | ||
headers = Headers.empty | ||
|
||
res <- Client.request(Request(url = url, headers = headers, body = Body.fromString("some-body"))) | ||
data <- res.body.asString | ||
} yield assertTrue(extractStatus(res) == Status.InternalServerError, data == "") | ||
}.provide( | ||
Client.default, | ||
Server.live, | ||
ZLayer.succeed(serverConfig), | ||
Scope.default, | ||
) @@ withLiveClock | ||
} |