-
Notifications
You must be signed in to change notification settings - Fork 210
main middleware tests #90
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
Conversation
Signed-off-by: Jon Carl <[email protected]>
| type JWTMiddleware struct { | ||
| Options Options | ||
| // Option is how options for the middleware are setup. | ||
| type Option func(*JWTMiddleware) |
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.
I opted to go with the options pattern as that is what we are doing in the josev2 validation piece.
| // New constructs a new Secure instance with supplied options. | ||
| func New(opts ...Option) *JWTMiddleware { | ||
| m := &JWTMiddleware{ | ||
| validateToken: func(string) (interface{}, error) { panic("not implemented") }, |
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.
Before v2 release we will either default to the josev2 for this, or require a specific validate token func to be passed into New.
Signed-off-by: Jon Carl <[email protected]>
Signed-off-by: Jon Carl <[email protected]>
| ) | ||
|
|
||
| // TODO: replace this with default validate token func once it is merged in | ||
| func REPLACE_ValidateToken(token string) (interface{}, error) { |
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.
this will be replaced after the merge into v2
| // DefaultErrorHandler is the default error handler implementation for the | ||
| // middleware. If an error handler is not provided via the WithErrorHandler | ||
| // option this will be used. | ||
| func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error) { |
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.
We made this public in case consumers want to wrap this default handler.
| // If debugging is turned on, log the outcome | ||
| token, err := m.tokenExtractor(r) | ||
| if err != nil { | ||
| m.logf("Error extracting JWT: %v", err) |
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.
note that we have completely dropped debug functionality for several reasons:
- in some places we were logging the full string of the JWT 😱 and that is unacceptable.
- as a library it's more idiomatic to pass errors up and let those be logged by the package consumer instead of logging them in the package
Signed-off-by: Jon Carl <[email protected]>
Codecov Report
@@ Coverage Diff @@
## v2 #90 +/- ##
=====================================
Coverage ? 95.08%
=====================================
Files ? 1
Lines ? 61
Branches ? 0
=====================================
Hits ? 58
Misses ? 2
Partials ? 1 Continue to review full report at Codecov.
|
…anged Signed-off-by: Jon Carl <[email protected]>
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.
Looks great! Examples for chi, and other famous frameworks would be a bonus, but otherwise ![]()
This started off as bringing the middleware tests up to date with the validate token pieces, but I ended up re-working some of the pieces. I've left comments throughout the code to explain the changes. The two major changes are:
CheckJWTWe've left out a lot of documentation changes as that will be added in the
v2branch.