-
-
Notifications
You must be signed in to change notification settings - Fork 456
Make Endpoint respond with a 401 status code if the Authorization header is missing #3281
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
Open
notxcain
wants to merge
18
commits into
zio:main
Choose a base branch
from
notxcain:fix-3235
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f065eaa
Respond with 401 in case of missing Authorization header
notxcain 63cef82
Make linter happy
notxcain 2d509b1
Trigger build
notxcain 7a2e227
Trigger build
notxcain 6ac5b12
Merge remote-tracking branch 'upstream/main' into fix-3235
notxcain 00f9cac
Fix implementation
notxcain ddbb739
Merge branch 'main' into fix-3235
notxcain 3f5b1d5
Merge branch 'main' into fix-3235
notxcain ad0fe12
Merge branch 'main' into fix-3235
notxcain 1bf2221
Merge remote-tracking branch 'upstream/main' into fix-3235
notxcain 93f33cc
Remove MissingAuthorizationHeader
notxcain 3176433
revert pattern matching case
notxcain eeeb709
fmt
notxcain a32d60c
Handle DecodingErrorHeader
notxcain c9da011
fmt
notxcain 64c1ea2
Remove unrelated changes
notxcain 113c497
Draft conversion to WWWAuthenticate
notxcain 142b508
Merge branch 'main' into fix-3235
notxcain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
zio-http/jvm/src/test/scala/zio/http/endpoint/UnauthorizedSpec.scala
This file contains hidden or 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,24 @@ | ||
package zio.http.endpoint | ||
|
||
import zio.ZIO | ||
import zio.test._ | ||
|
||
import zio.http._ | ||
import zio.http.codec._ | ||
|
||
object UnauthorizedSpec extends ZIOSpecDefault { | ||
override def spec = | ||
suite("UnauthorizedSpec")( | ||
test("should respond with 401 Unauthorized when required authorization header is missing") { | ||
val endpoint = Endpoint(Method.GET / "test") | ||
.header(HeaderCodec.authorization) | ||
.out[Unit] | ||
val route = endpoint.implement(_ => ZIO.unit) | ||
val request = | ||
Request(method = Method.GET, url = url"/test") | ||
for { | ||
response <- route.toRoutes.runZIO(request) | ||
} yield assertTrue(Status.Unauthorized == response.status) | ||
}, | ||
) | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if this should be reported the same way as any other missing header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The specs say, that we have to return acceptable auth methods.
And we have that data from the Endpoint API
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@987Nabil the
AuthType
has quite limited information, please see the implementation draft. Any piece of advice here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most things are optional and can be omitted. Digest nonce is generated anyway.
Basic Digest and OAuth need a realm. We can add this to
AuthType
in the same fashion likeScopedAuth
.In case there is no realm, we could return no header or a default value. I tend to a default value. Like
"default"
or"restricted"