-
Notifications
You must be signed in to change notification settings - Fork 8
auth service added with check scope operation #62
auth service added with check scope operation #62
Conversation
Codecov Report
@@ Coverage Diff @@
## master #62 +/- ##
=========================================
+ Coverage 63.56% 64.46% +0.9%
=========================================
Files 31 32 +1
Lines 1386 1410 +24
=========================================
+ Hits 881 909 +28
+ Misses 434 427 -7
- Partials 71 74 +3
Continue to review full report at Codecov.
|
@nurali-techie @alexeykazakov I see that this repo declares a dependency on |
Currently, we don't have any way to automatically submit PR to it's consumer if we update any client(in this case auth). Also this is autogenerated code, we can easily and quickly fix it if something break due to change in client. If we see too much pain and broken code due to using master from client, then maybe we can develop automation to submit PR to it's consumer then lock this version. Otherwise we'll have to put extra efforts to update all consumers for single change in client repo. |
@dipak-pawar yes, I agree with you. I was just concerned that we may have unexpected changes brought my some client libs, but at the same time, we should "embrace" those changes and we should rarely have breaking changes in the API anyways (most of the time: new endpoints or new params for existing endpoints) |
@xcoulon @dipak-pawar one more option as below. The generate_client_setup() script should take version as param. (note - here T1, T2 is timeline ..) T1 - f8-auth call generate_client_setup(1.0.0) Now, there will be two version for f8-auth-client 1.0.0 and 1.0.1 and f8-common using 1.0.0 will keep running/compiling without any issue. In case f8-common want latest changes it should change version to 1.0.1. Benefit, f8-common build will not_failed due to incompatible changes in f8-auth goa_design. Also, if there are no incompatible changes in f8-auth goa_design then f8-common will always keep getting latest changes. |
service/auth.go
Outdated
@@ -0,0 +1,67 @@ | |||
package service |
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 was wondering if we should rename token
package to auth
package and put this service into that auth
package. Would like to keep all auth related stuff under the same package/subpackages.
@nurali-techie @xcoulon et al, any thoughts?
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.
yes, that would be easier if all AuthN/AuthZ stuff belongs to the auth
pkg, indeed
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 see pkg name token
is meaningful for the content it has atm. I am not sure is in future token
pkg get something which is unrelated to auth
at all .. in that case mixing auth
and token
would not be right.
In case we want to do this refactoring, I still want to see token
as sub-package in itself.
auth
-> token
(all existing token pkg file)
-> service
(this new auth.go file but named service.go)
With this input .. I will leave final call for @alexeykazakov
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.
Well.. token
is kinda sub area of auth
anyway. Can't imagine anything which we would like to keep in token
which is unrelated to auth
at all right now. But if we have it in the future we can always introduce a new token
package outside of auth
.
For now I would have auth
only.
While I would be fine with having:
auth
-> token
(all existing token pkg files and jwk subpackage)
-> service.go (no need for service subpackage)
But IMO
auth
->
(all existing token pkg files and jwk subpackage)
service.go (no need for service subpackage)
is even simpler. But I'm fine with both options.
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.
Done in fb124aa
service/auth.go
Outdated
CheckSpaceScope(ctx context.Context, spaceID, requiredScope string) (bool, error) | ||
} | ||
|
||
func NewAuthService(hostURL string) (Auth, 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.
hostURL
is confusing. Should be authURL
or something like this. Also add a comment to the function with explaining what param is expected.
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.
Done in fb124aa
service/auth.go
Outdated
} | ||
|
||
func (d *doer) Do(ctx context.Context, req *http.Request) (*http.Response, error) { | ||
token := jwt.ContextJWT(ctx) |
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.
Authorization header is not enough. We should also forward Requiest ID if it's present in the context.
Take a look at https://github.com/fabric8-services/fabric8-auth/blob/master/notification/service/notification.go#L82 for example.
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.
Done in ebc712d
service/auth_test.go
Outdated
} | ||
|
||
func (s *AuthServiceTestSuite) TestCheckSpaceScope() { | ||
s.T().Run("scope_found_true", func(t *testing.T) { |
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 have to check the request as well. Is the request to the Auth service has all expected headers? Authorization header has expected token? Request ID header is present? URL is expected?
This should be checked for all requests in the test.
Also check all potential responses from Auth: https://github.com/fabric8-services/fabric8-auth/blob/48c0a1b90a0ff1b7cd8621c67acd8c5c13a4cb3b/design/resource.go#L68-L71
Which are: 200, 401, 500, 404 (when the resource ID is unknown)
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.
@alexeykazakov plz check logic code_link for anything other than 200, it throws exception. We already have 401 handle in test test_code_link so I guess no more test needed.
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.
How do you know if throws an error if it's other than 200 if you don't have tests for that? It's not my eyes which you should relay on to check the logic. It should be automated tests.
Please add the tests I'm asking for.
Also please add checks for the requests:
We have to check the request as well. Is the request to the Auth service has all expected headers? Authorization header has expected token? Request ID header is present? URL is expected?
This should be checked for all requests in the test.
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.
Done in ebc712d
service/auth_test.go
Outdated
Reply(401) | ||
|
||
authZ, err := s.authService.CheckSpaceScope(context.Background(), spaceID.String(), "manage") | ||
assert.Error(t, 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.
Check the error type and message.
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.
Done in fb124aa
I don't think it's a good idea to edit releases. If there some changes then we should do another release (or not do it at all) and keep the released versions intact. If we want to track compatible and incompatible changes in our releases then we should use Semantic Versioning: MAJOR.MINOR.PATCH format. PATCH means compatible changes. Fro example 1.0.1, 1.0.2, etc. The problem here is that in that case we will need to update the version param manually every time we change design package which can be error prone. I wander if goa supports something for API versioning here which we could use to automatically generated versions based on changes... And btw, let's move this discussion to a better place (a new issue in common)? :) |
@alexeykazakov @xcoulon @dipak-pawar issue created to track |
@nurali-techie AFAIK, we only have incremental changes in the design, so we should have |
@xcoulon |
ok, so taking at step back at your proposal: having tags on the Back to your initial proposal, I would prefer a simple tag the repo with an incremental version (eg: @nurali-techie does this answer your question? |
@xcoulon I really don't want new version every time. It looks we are going away from problem domain. We want to solve the incompatible change should not impact the |
service/auth_test.go
Outdated
err := s.authService.RequireScope(context.Background(), resID.String(), "manage") | ||
assert.Error(t, err) | ||
_, ok := err.(errors.ForbiddenError) | ||
assert.True(t, ok, "error is not forbidden 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.
You can also copy this https://github.com/fabric8-services/fabric8-auth/blob/master/test/error.go file to common and reuse it like this: https://github.com/fabric8-services/fabric8-auth/blob/d546608eb57ef7a6dfb27ad6e500f8dd212eaef6/authorization/role/service/role_management_service_blackbox_test.go#L55
We will benefit from that Assert helper in other tests too.
service/auth_test.go
Outdated
Reply(401) | ||
|
||
authZ, err := s.authService.CheckSpaceScope(context.Background(), spaceID.String(), "manage") | ||
err := s.authService.RequireScope(context.Background(), resID.String(), "manage") | ||
assert.Error(t, 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.
Check error type & message. You could explicitly return InternalError in RequireScope instead of error
btw for that case.
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.
Done in fb124aa
service/auth_test.go
Outdated
Reply(500) | ||
|
||
err := s.authService.RequireScope(context.Background(), resID.String(), "manage") | ||
assert.Error(t, 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.
Check error type & message.
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.
Done in fb124aa
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 quite straight forward, I would just add some more comments in the code describing what steps are happening.
Related to fabric8-services/fabric8-env#10