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

Fix gitlab oauth token validation request #674

Merged
merged 2 commits into from
Apr 4, 2024
Merged

Fix gitlab oauth token validation request #674

merged 2 commits into from
Apr 4, 2024

Conversation

vinokurig
Copy link
Contributor

@vinokurig vinokurig commented Apr 2, 2024

What does this PR do?

Rework the gitlab oauth token validation check to verify if the test response has data in the returned object.

Screenshot/screencast of this PR

What issues does this PR fix or reference?

eclipse-che/che#22836

How to test this PR?

  1. Deploy che with the PR image: quay.io/eclipse/che-server:pr-674
  2. Configure Gitlab oauth.
  3. Start a workspace from a Gitlab repository with a devfile.
  4. Go to dashboard -> User Preferences -> Git Services tab, see: the Gitlab provider is in the authorised state.
  5. Revoke the Gitlab authorisation.

See: the authorisation state of the Gitlab provider has changed to unauthorised.

PR Checklist

As the author of this Pull Request I made sure that:

Reviewers

Reviewers, please comment how you tested the PR when approving it.

@vinokurig
Copy link
Contributor Author

/retest

1 similar comment
@vinokurig
Copy link
Contributor Author

/retest

@dmytro-ndp
Copy link
Contributor

@vinokurig : hello,
Question about test scenario in description:

How to test this PR?

  1. Deploy che with the PR image: quay.io/eclipse/che-server:pr-

Did you mean quay.io/eclipse/che-server:pr-674 ?

@vinokurig
Copy link
Contributor Author

vinokurig commented Apr 3, 2024

@dmytro-ndp

Question about test scenario in description:

How to test this PR?

  1. Deploy che with the PR image: quay.io/eclipse/che-server:pr-

Did you mean quay.io/eclipse/che-server:pr-674 ?

Right, When I start creating a che-server pull request I don't know the id before it is opened. This time I forgot to update the description after the pr creation. Updated the description.

@@ -93,7 +94,8 @@ public OAuthToken getToken(String userId) throws IOException {
if (token == null
|| token.getToken() == null
|| token.getToken().isEmpty()
|| getJson(gitlabUserEndpoint, token.getToken(), GitLabUser.class) == null) {
|| isNullOrEmpty(
Copy link
Member

Choose a reason for hiding this comment

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

@vinokurig could you clarify the principle difference and how it fixes gitlab validation? can we add a unit test for that ?

Copy link
Contributor Author

@vinokurig vinokurig Apr 3, 2024

Choose a reason for hiding this comment

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

could you clarify the principle difference and how it fixes gitlab validation?

Currently, in the main branch we check that the GitLabUser object is not null. If we request the GitLab user with an invalid token, we will not get null, but a GitLabUser object with empty (null) fields. To fix that I changed the check to verify if the userId field is not null.

can we add a unit test for that ?

Done

@@ -93,7 +94,8 @@ public OAuthToken getToken(String userId) throws IOException {
if (token == null
|| token.getToken() == null
|| token.getToken().isEmpty()
|| getJson(gitlabUserEndpoint, token.getToken(), GitLabUser.class) == null) {
|| isNullOrEmpty(
getJson(gitlabUserEndpoint, token.getToken(), GitLabUser.class).getId())) {
return null;
Copy link
Member

Choose a reason for hiding this comment

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

returning null is a bad practice in general

Copy link
Contributor Author

@vinokurig vinokurig Apr 3, 2024

Choose a reason for hiding this comment

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

Agree, added a TODO for refactoring to return Optional.

Copy link
Contributor

@dmytro-ndp dmytro-ndp left a comment

Choose a reason for hiding this comment

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

Test scenario from description with additional steps has tested successfully using quay.io/eclipse/che-server:pr-674 image using private repo https://gitlab-gitlab-system.apps.git.crw-qe.com/admin-user/private-repo.git with Gitlab Server on OCP 4.14.

Remark: Git Services tab showed state "unauthorized", not "unauthorised".
I would suggest using the same vocabulary in the test scenario as used in Eclipse Che UI.

Test scenario with additional steps:

  1. Deploy che with the PR image: quay.io/eclipse/che-server:pr-674
  2. Configure Gitlab oauth.
  3. Start a workspace from a Gitlab repository with a devfile https://gitlab-gitlab-system.apps.git.crw-qe.com/admin-user/private-repo.git.
    3.a See page to authorize OAuth on GitLab server during the workspace startup.
  4. Go to dashboard -> User Preferences -> Git Services tab, see: the Gitlab provider is in the authorized state.
  5. Revoke the Gitlab authorization.
  6. See: the authorization state of the Gitlab provider has changed to unauthorized.
  7. Refresh dashboard page
  8. See: the authorization state of the Gitlab provider is unauthorized.
  9. Start a new workspace from a Gitlab repository with a devfile https://gitlab-gitlab-system.apps.git.crw-qe.com/admin-user/private-repo.git.
  10. Go to VS Code Editor terminal and make sure git config --list | grep user.name returns TestUser.
  11. See page to authorize OAuth on GitLab server during the workspace startup.
  12. Start a new workspace from a Gitlab repository with a devfile https://gitlab-gitlab-system.apps.git.crw-qe.com/admin-user/private-repo.git.
  13. See NO page to authorize OAuth on GitLab server during the workspace startup.

Test screencast: screencast-bpconcjcammlapcogcnnelfmaeghhagj-2024.04.03-11_59_12.webm

@vinokurig
Copy link
Contributor Author

/retest

@openshift-ci openshift-ci bot added the lgtm label Apr 4, 2024
@ibuziuk ibuziuk merged commit c51919d into main Apr 4, 2024
27 of 28 checks passed
@ibuziuk ibuziuk deleted the che-22836_gitlab branch April 4, 2024 09:10
Copy link

openshift-ci bot commented Apr 4, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dmytro-ndp, ibuziuk, tolusha, vinokurig

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

Needs approval from an approver in each of these files:

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

@devstudio-release
Copy link

Build 3.13 :: server_3.x/332: Console, Changes, Git Data

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

Build 3.13 :: server_3.x/332: SUCCESS

Upstream sync done; /DS_CI/sync-to-downstream_3.x/6404 triggered

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

Build 3.13 :: copyIIBsToQuay/2600: Console, Changes, Git Data

@devstudio-release
Copy link

Build 3.13 :: sync-to-downstream_3.x/6407: SUCCESS

Build container: devspaces-operator-bundle synced; /DS_CI/get-sources-rhpkg-container-build_3.x/6369 triggered; /job/DS_CI/job/dsc_3.x triggered;

@devstudio-release
Copy link

Build 3.13 :: operator-bundle_3.x/2732: SUCCESS

Upstream sync done; /DS_CI/sync-to-downstream_3.x/6407 triggered

@devstudio-release
Copy link

Build 3.13 :: update-digests_3.x/6247: SUCCESS

Detected new images: rebuild operator-bundle
* server; /DS_CI/operator-bundle_3.x/2732 triggered

@devstudio-release
Copy link

Build 3.13 :: dsc_3.x/1883: Console, Changes, Git Data

@devstudio-release
Copy link

Build 3.13 :: dsc_3.x/1883: SUCCESS

3.13.0-CI

@devstudio-release
Copy link

Build 3.13 :: copyIIBsToQuay/2600: SUCCESS

3.13
arches = x86_64, s390x, ppc64le;
  * LATEST DS OPERATOR BUNDLE = <a href=https://quay.io/repository/devspaces/devspaces-operator-bundle?tab=tags>registry-proxy.engineering.redhat.com/rh-osbs/devspaces-operator-bundle:3.13-91
  * LATEST DWO OPERATOR BUNDLE = <a href=https://quay.io/repository/devworkspace/devworkspace-operator-bundle?tab=tags>registry-proxy.engineering.redhat.com/rh-osbs/devworkspace-operator-bundle:0.27-3
+ s390x-rhel8 IIB(s) copied:
  + quay.io/devspaces/iib:3.13-v4.15-703047-693074-s390x
  + quay.io/devspaces/iib:3.13-v4.15-s390x
  + quay.io/devspaces/iib:next-v4.15-s390x
  + quay.io/devspaces/iib:3.13-v4.14-703043-693070-s390x
  + quay.io/devspaces/iib:3.13-v4.14-s390x
  + quay.io/devspaces/iib:next-v4.14-s390x
  + quay.io/devspaces/iib:3.13-v4.13-703063-693064-s390x
  + quay.io/devspaces/iib:3.13-v4.13-s390x
  + quay.io/devspaces/iib:next-v4.13-s390x
  + quay.io/devspaces/iib:3.13-v4.12-703060-693054-s390x
  + quay.io/devspaces/iib:3.13-v4.12-s390x
  + quay.io/devspaces/iib:next-v4.12-s390x
+ x86_64-rhel8 IIB(s) copied:
  + quay.io/devspaces/iib:3.13-v4.15-703047-693074-x86_64
  + quay.io/devspaces/iib:3.13-v4.15-x86_64
  + quay.io/devspaces/iib:next-v4.15-x86_64
  + quay.io/devspaces/iib:3.13-v4.14-703043-693070-x86_64
  + quay.io/devspaces/iib:3.13-v4.14-x86_64
  + quay.io/devspaces/iib:next-v4.14-x86_64
  + quay.io/devspaces/iib:3.13-v4.13-703063-693064-x86_64
  + quay.io/devspaces/iib:3.13-v4.13-x86_64
  + quay.io/devspaces/iib:next-v4.13-x86_64
  + quay.io/devspaces/iib:3.13-v4.12-703060-693054-x86_64
  + quay.io/devspaces/iib:3.13-v4.12-x86_64
  + quay.io/devspaces/iib:next-v4.12-x86_64
+ ppc64le-rhel8 IIB(s) copied:
  + quay.io/devspaces/iib:3.13-v4.15-703047-693074-ppc64le
  + quay.io/devspaces/iib:3.13-v4.15-ppc64le
  + quay.io/devspaces/iib:next-v4.15-ppc64le
  + quay.io/devspaces/iib:3.13-v4.14-703043-693070-ppc64le
  + quay.io/devspaces/iib:3.13-v4.14-ppc64le
  + quay.io/devspaces/iib:next-v4.14-ppc64le
  + quay.io/devspaces/iib:3.13-v4.13-703063-693064-ppc64le
  + quay.io/devspaces/iib:3.13-v4.13-ppc64le
  + quay.io/devspaces/iib:next-v4.13-ppc64le
  + quay.io/devspaces/iib:3.13-v4.12-703060-693054-ppc64le
  + quay.io/devspaces/iib:3.13-v4.12-ppc64le
  + quay.io/devspaces/iib:next-v4.12-ppc64le

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.

5 participants