Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test of a middleware providing a context to a Routes #2487

Merged
merged 5 commits into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading