Skip to content

Commit

Permalink
Fix SSLSpec (#2415)
Browse files Browse the repository at this point in the history
* fix test

* do not fork installation of app
  • Loading branch information
adamgfraser authored Aug 30, 2023
1 parent 6411c97 commit 23f04fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object ResponseCompressionSpec extends ZIOHttpSpec {
for {
server <- ZIO.service[Server]
client <- ZIO.service[Client]
_ <- server.install(app).fork
_ <- server.install(app)
response <- client.request(
Request(
method = Method.GET,
Expand All @@ -78,7 +78,7 @@ object ResponseCompressionSpec extends ZIOHttpSpec {
for {
server <- ZIO.service[Server]
client <- ZIO.service[Client]
_ <- server.install(app).fork
_ <- server.install(app)
response <- client.request(
Request(
method = Method.GET,
Expand Down
45 changes: 12 additions & 33 deletions zio-http/src/test/scala/zio/http/SSLSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,22 @@ object SSLSpec extends ZIOHttpSpec {

val app: HttpApp[Any] = Routes(
Method.GET / "success" -> handler(Response.ok),
Method.POST / "text" -> handler { (req: Request) =>
for {
body <- req.body.asString
} yield Response.text(body)
},
).sandbox.toHttpApp

val successUrl =
URL.decode("https://localhost:8073/success").toOption.get
val httpUrl =
URL.decode("http://localhost:8073/success").toOption.get

val textUrl =
URL.decode("https://localhost:8073/text").toOption.get
val httpsUrl =
URL.decode("https://localhost:8073/success").toOption.get

override def spec = suite("SSL")(
Server
.serve(app)
.install(app)
.as(
List(
test("succeed when client has the server certificate") {
val actual = Client
.request(Request.get(successUrl))
.request(Request.get(httpsUrl))
.map(_.status)
assertZIO(actual)(equalTo(Status.Ok))
}.provide(
Expand All @@ -69,7 +64,7 @@ object SSLSpec extends ZIOHttpSpec {
),
test("fail with DecoderException when client doesn't have the server certificate") {
val actual = Client
.request(Request.get(successUrl))
.request(Request.get(httpsUrl))
.catchSome {
case e if e.getClass.getSimpleName == "DecoderException" =>
ZIO.succeed("DecoderException")
Expand All @@ -85,7 +80,7 @@ object SSLSpec extends ZIOHttpSpec {
),
test("succeed when client has default SSL") {
val actual = Client
.request(Request.get(successUrl))
.request(Request.get(httpsUrl))
.map(_.status)
assertZIO(actual)(equalTo(Status.Ok))
}.provide(
Expand All @@ -98,7 +93,7 @@ object SSLSpec extends ZIOHttpSpec {
),
test("Https Redirect when client makes http request") {
val actual = Client
.request(Request.get(successUrl))
.request(Request.get(httpUrl))
.map(_.status)
assertZIO(actual)(equalTo(Status.PermanentRedirect))
}.provide(
Expand All @@ -109,27 +104,11 @@ object SSLSpec extends ZIOHttpSpec {
ZLayer.succeed(NettyConfig.default),
Scope.default,
),
test("Https request with a large payload should respond with 413") {
check(payload) { payload =>
val actual = Client
.request(
Request.post(textUrl, Body.fromString(payload)),
)
.map(_.status)
assertZIO(actual)(equalTo(Status.RequestEntityTooLarge))
}
}.provide(
Client.customized,
ZLayer.succeed(ZClient.Config.default.ssl(clientSSL1)),
NettyClientDriver.live,
DnsResolver.default,
ZLayer.succeed(NettyConfig.default),
Scope.default,
),
),
),
).provideShared(
Server.default,
) @@ ignore
Server.live,
ZLayer.succeed(config),
)

}

0 comments on commit 23f04fd

Please sign in to comment.