-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
jwt validation #171
jwt validation #171
Conversation
6dd2956
to
f205092
Compare
31b1471
to
502345e
Compare
Hi @fabiocicerchia , I don't have access to see why the snyk test is not passing, can you give me access permit to check it out please? |
502345e
to
6bafe05
Compare
6bafe05
to
291df62
Compare
a8bd311
to
8acec37
Compare
Hi @abel296, thank you for the PR. |
f326f4a
to
7b4c1a4
Compare
Hi @fabiocicerchia , could you review the PR please? |
7b4c1a4
to
c398bcb
Compare
ff0bc17
to
0b3995e
Compare
Hi @fabiocicerchia , we've added a couple of changes:
|
dc4cc31
to
dcf1a34
Compare
23c7218
to
4e87b96
Compare
Hi @fabiocicerchia , these are the last updates:
|
Signed-off-by: Abel Andrés <[email protected]>
4e87b96
to
c12a5ce
Compare
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.
Hi @abel296, apologies for not getting back to you sooner, recently I couldn't focus on the project properly.
I'll try spending some more time to test properly this MR in the next following days.
It would be really good not to push force and have a reviewable commit history, because as of now, it's really impossible to figure out what each change contributed to.
I made some more suggestions, but let me test it first before starting fixing, as I might add some more comments, and don't want to let you do too much back and forth.
Thank you for the patience and the effort for putting together this PR!
# - JWT_JWKS_URL enviroment variable | ||
|
||
# Time in minutes that takes for JWKS to refresh automatically | ||
# JWT_REFRESH_INTERVAL= |
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's use the same example values from config.yml.dist
:
# JWT_REFRESH_INTERVAL= | |
# JWT_REFRESH_INTERVAL=15 |
|
||
# --- JWT | ||
# A list of space-separated paths. | ||
# JWT_EXCLUDED_PATHS= |
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's use the same example values from config.yml.dist
:
# JWT_EXCLUDED_PATHS= | |
# JWT_EXCLUDED_PATHS=/ |
# JWT_EXCLUDED_PATHS= | ||
|
||
# A list of space-separated scopes to be allowed. | ||
# JWT_ALLOWED_SCOPES= |
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's use the same example values from config.yml.dist
:
# JWT_ALLOWED_SCOPES= | |
# JWT_ALLOWED_SCOPES=scope1, scope2 |
# # A list of space-separated paths. | ||
# excluded_paths: | ||
# - / | ||
# # A list of space-separated scopes to be allowed. |
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.
space or comma separated?
// Jwt - Defines the config for the jwt validation. | ||
type Jwt struct { | ||
ExcludedPaths []string `yaml:"excluded_paths" envconfig:"JWT_EXCLUDED_PATHS" split_words:"true"` | ||
AllowedScopes []string `yaml:"allowed_scopes" envconfig:"JWT_ALLOWED_SCOPES" split_words:"true"` |
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.
scope1, scope2
will end up in having item 0 scope1,
and item 1 scope2
|
||
h.ServeHTTP(rr, req) | ||
|
||
assert.Equal(t, http.StatusMovedPermanently, rr.Code) |
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.
it would be useful to assert the Location
header of this 301 respose.
|
||
h.ServeHTTP(rr, req) | ||
|
||
assert.Equal(t, http.StatusMovedPermanently, rr.Code) |
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.
it would be useful to assert the Location
header of this 301 respose.
|
||
h.ServeHTTP(rr, req) | ||
|
||
assert.Equal(t, http.StatusMovedPermanently, rr.Code) |
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.
is it correct that all the tests with a JWT are going to 301?
|
||
res := getScopes(token) | ||
|
||
assert.ElementsMatch(t, res, []string{"scope1", "scope2", "scope3"}, "Scopes provided doesn't match") |
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.
assert.ElementsMatch(t, res, []string{"scope1", "scope2", "scope3"}, "Scopes provided doesn't match") | |
assert.ElementsMatch(t, res, []string{"scope1", "scope2", "scope3"}, "The provided scopes don't match") |
|
||
res := getScopes(token) | ||
|
||
assert.ElementsMatch(t, res, []string{"scope1", "scope2", "scope3"}, "Scopes provided doesn't match") |
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.
assert.ElementsMatch(t, res, []string{"scope1", "scope2", "scope3"}, "Scopes provided doesn't match") | |
assert.ElementsMatch(t, res, []string{"scope1", "scope2", "scope3"}, "The provided scopes don't match") |
return logJWTErrorAndAbort(w, err) | ||
} | ||
if err := jwt.Validate(token); err != nil { | ||
return logJWTErrorAndAbort(w, 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.
it would be good to increase the test coverage by adding a test case to cover this scenario as well (ie testing the failure of validation).
} | ||
|
||
func TestRefreshKeySet(t *testing.T) { | ||
t.Skip("To run this test, you should set refreshIntervalDuration (from config.go) to time.Second") |
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.
Can this test be executed automatically, without any manual changes?
merged all changes + improvements in #208 |
Features: