Skip to content

Commit

Permalink
Add a test of a middleware providing a context to a Routes (#2487)
Browse files Browse the repository at this point in the history
* Add a test of a middleware providing a context to a `Routes`

* Add a test of a middleware providing a context to a `Routes`

* scalafmt

* scalafmt
  • Loading branch information
guizmaii authored Oct 18, 2023
1 parent 3a6525c commit d0a517e
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ object AuthSpec extends ZIOHttpSpec with HttpAppTestExtensions {
} @@ basicAuthContextM).merge.mapZIO(_.body.asString)
assertZIO(app.runZIO(Request.get(URL.empty).copy(headers = successBasicHeader)))(equalTo("user"))
},
test("Extract username via context with Routes") {
val app = {
Routes(
Method.GET / "context" -> basicAuthContextM ->
Handler.fromFunction[(AuthContext, Request)] { case (c: AuthContext, _) => Response.text(c.value) },
)
}.toHttpApp
assertZIO(
app
.runZIO(Request.get(URL.root / "context").copy(headers = successBasicHeader))
.flatMap(_.body.asString),
)(equalTo("user"))
},
),
suite("basicAuthZIO")(
test("HttpApp is accepted if the basic authentication succeeds") {
Expand Down

0 comments on commit d0a517e

Please sign in to comment.