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 e2e tests for banneduser #1045

Merged
merged 10 commits into from
Sep 12, 2024

Conversation

filariow
Copy link
Contributor

@filariow filariow commented Sep 9, 2024

Signed-off-by: Francesco Ilario <[email protected]>
Signed-off-by: Francesco Ilario <[email protected]>
Signed-off-by: Francesco Ilario <[email protected]>
@mfrancisc
Copy link
Contributor

You can only pair this with one of regsvc or host-operator, I see it is failing since all 3 PRs now have the same branch name.

@mfrancisc
Copy link
Contributor

since it's related to proxy test enhancements I think it should go with the regsvc PR right ?

@filariow
Copy link
Contributor Author

filariow commented Sep 9, 2024

since it's related to proxy test enhancements I think it should go with the regsvc PR right ?

yes, it should. Would e2e tests run fine even if codeready-toolchain/host-operator#1083 is not merged? I was not able to have them running in my local without this change to host-operator.

@mfrancisc
Copy link
Contributor

yes, it should. Would e2e tests run fine even if codeready-toolchain/host-operator#1083 is not merged? I was not able to have them running in my local without this change to host-operator.

Correct! You need to merge first the host-operator PR since the actual registration-service deployment is the one that comes with host-operator as briefly documented here https://github.com/codeready-toolchain/registration-service/blob/master/deploy/README.md.

So yes feel free to merge the host-operator PR once you're ready.

})

t.Run("cannot get workspace", func(t *testing.T) {
_, err := bannedUser.getWorkspace(t, hostAwait, bannedUser.compliantUsername)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to use getWorkspace() here? It uses a poll (it's slow because it will keep trying until it's timed out) and hides the actual error. Shouldn't we make sure that everything is ready (spaces, space bindings, etc) and then just use the client directly proxyCl.Get(...) and then check that the error is Forbidden with the expected error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great point, let me fix that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in a533a2b

})
})

t.Run("lazy banned user", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference comparing to banneduser tests?

Copy link
Contributor Author

@filariow filariow Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the difference is that banneduser's client does not initialize correctly -unsuccessful call to /apis, so we expect it to return NoMatch errors. In this case the client initialized correctly and we have Forbidden errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we rename it to something like "user creates client and after is banned" ? But more important does it matter when the user is banned , if before or after the initialization of a kube client ?

I'm suggesting that probably we don't need this test. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, for how Controller-Runtime's Client v0.13.0 is implemented, the Controller-Runtime's client performs a call to the /apis endpoint during initialization. If we ban the user before creating the client, this call will fail and subsequent requests will fail with NoMatch without really performing the request against the proxy, as the client was not able to initialize the list of resources the cluster is supporting.

Indeed, the client.New() function instantiates a new Dynamic RESTMapper (if not provided via client's Config).
The mapper invokes the /apis endpoint to fetch the list of resources that the cluster is supporting. That's done invoking the setStaticMapper function here.
Next usages of the client will lookup the cached list of supported resources to understand if the cluster supports the provided resource and return a NoMatch error without really executing the request.

Conversely, is we ban the user lately, the client will effectively perform the call and the proxy will reject it with Forbidden.

As the former scenario is mainly testing a Controller-Runtime's Client specific behavior, I'd say we could remove the banneduser suite, and rename the lazy banned user as banneduser. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed explanation.
I don't think we need to test the client (initialization). We want to test our proxy here. So I agree with @mfrancisc and would drop the tests which fails with the client initialization.
Create the client. Then ban the user. Then call the proxy and check the expected 403 error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 89a664f

Copy link
Contributor

@mfrancisc mfrancisc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Job! Thanks a lot for the enhancements to the e2e tests 🙏

I have only one comment.

})
})

t.Run("lazy banned user", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we rename it to something like "user creates client and after is banned" ? But more important does it matter when the user is banned , if before or after the initialization of a kube client ?

I'm suggesting that probably we don't need this test. WDYT?

@filariow
Copy link
Contributor Author

/retest

Copy link
Contributor

@mfrancisc mfrancisc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Job 👍

Thanks for the additional changes.

Copy link
Contributor

@rsoaresd rsoaresd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job 🚀

Just a minor suggestion to rename tt for better readability to something like:

})

t.Run("cannot list resources", func(t *testing.T) {
tt := map[string]client.Client{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tt := map[string]client.Client{
workspaces := map[string]client.Client{

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, let me rename them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in a8d808f

}
for k, wc := range tt {
t.Run(k, func(t *testing.T) {
tt := map[string]client.ObjectList{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tt := map[string]client.ObjectList{
resourceLists := map[string]client.ObjectList{

Signed-off-by: Francesco Ilario <[email protected]>
Copy link

sonarcloud bot commented Sep 11, 2024

Copy link
Contributor

@alexeykazakov alexeykazakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for addressing the comments.

Copy link

openshift-ci bot commented Sep 11, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexeykazakov, filariow, mfrancisc

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [alexeykazakov,mfrancisc]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@filariow filariow merged commit f8a0b98 into codeready-toolchain:master Sep 12, 2024
7 of 8 checks passed
@filariow filariow deleted the banneduser-middleware branch September 12, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants