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(members): ensure group and project users are case-insensitive #556

Merged
merged 4 commits into from
Sep 7, 2023

Conversation

J4Numbers
Copy link
Contributor

Meddle with group and project membership checks to ensure that
usernames are case-insensitive. This change ensures that users
are not added again by mistake, causing an error where a given
user already exists within the repository.

@J4Numbers J4Numbers had a problem deploying to Integrate Pull Request June 26, 2023 20:38 — with GitHub Actions Failure
@codecov
Copy link

codecov bot commented Jun 26, 2023

Codecov Report

Merging #556 (002bad8) into main (a44e184) will increase coverage by 0.06%.
The diff coverage is 95.45%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #556      +/-   ##
==========================================
+ Coverage   78.62%   78.69%   +0.06%     
==========================================
  Files          70       70              
  Lines        2699     2703       +4     
==========================================
+ Hits         2122     2127       +5     
+ Misses        577      576       -1     
Files Changed Coverage Δ
gitlabform/processors/project/members_processor.py 87.32% <88.88%> (+0.36%) ⬆️
gitlabform/gitlab/members.py 75.00% <100.00%> (+2.08%) ⬆️
...abform/processors/group/group_members_processor.py 98.87% <100.00%> (-0.03%) ⬇️

... and 1 file with indirect coverage changes

@J4Numbers
Copy link
Contributor Author

Addresses #555 and continues the work from #475.

@gdubicki
Copy link
Member

Hey @J4Numbers, thank you for your contribution! And sorry for the CI problem, I noticed that there are HTTP 401 thrown. That's strange because it works for me locally. :/ I will try to troubleshoot it over the next few days.

@gdubicki
Copy link
Member

Ok, now it seems to be failing on something related to your code, @J4Numbers:

FAILED tests/acceptance/premium/test_branches_users_case_insensitive.py::TestBranchesUsersCaseInsensitive::test__users_case_insensitive - TypeError: cannot unpack non-iterable ProjectProtectedBranch object

Can you check it out please?

@J4Numbers
Copy link
Contributor Author

J4Numbers commented Jul 14, 2023

Thanks for kicking it off! Full error is below:

FAILED tests/acceptance/standard/test_members_enforce.py::TestMembersEnforce::test__enforce_keep_bots - assert 5 == 2
 +  where 5 = len([<ProjectMember id:37 username:gitlabform_user_maroon_4>, <ProjectMember id:40 username:gitlabform_user_maroon_5>, <Pr...:45 username:project_25_bot_016e6e53920e5925458ecb37e324d4a0>, <ProjectMember id:46 username:gitlabform_user_maroon_7>])

This might be a bit of trial and error since I can't test the premium items locally...

@gdubicki gdubicki had a problem deploying to Integrate Pull Request July 15, 2023 14:58 — with GitHub Actions Failure
@J4Numbers J4Numbers had a problem deploying to Integrate Pull Request July 15, 2023 15:13 — with GitHub Actions Failure
@gdubicki gdubicki temporarily deployed to Integrate Pull Request July 15, 2023 15:19 — with GitHub Actions Inactive
@gdubicki
Copy link
Member

gdubicki commented Jul 15, 2023

Thanks for kicking it off! Full error is below:

FAILED tests/acceptance/standard/test_members_enforce.py::TestMembersEnforce::test__enforce_keep_bots - assert 5 == 2
 +  where 5 = len([<ProjectMember id:37 username:gitlabform_user_maroon_4>, <ProjectMember id:40 username:gitlabform_user_maroon_5>, <Pr...:45 username:project_25_bot_016e6e53920e5925458ecb37e324d4a0>, <ProjectMember id:46 username:gitlabform_user_maroon_7>])

This might be a bit of trial and error since I can't test the premium items locally...

This is fixed now.

But

@J4Numbers
Copy link
Contributor Author

Thanks for picking up the missed import!

This is fixed now.

But

Guessing something got cut off here. But it does look like there's a race condition or some test overlap in this somewhere (with the odd failure between different python versions). Want me to raise an issue for it?

@gdubicki
Copy link
Member

This is fixed now.
But

Guessing something got cut off here. But it does look like there's a race condition or some test overlap in this somewhere (with the odd failure between different python versions). Want me to raise an issue for it?

This may be caused by the fact that many tests depend on each other, see #561 (review) for more info.

@J4Numbers
Copy link
Contributor Author

Fair enough. Let me know if you need me to do anything else!

Copy link
Collaborator

@amimas amimas left a comment

Choose a reason for hiding this comment

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

Unsure why there's a gitlab premium related test case. I think it doesn't belong there.

@J4Numbers J4Numbers had a problem deploying to Integrate Pull Request July 16, 2023 17:11 — with GitHub Actions Failure
@J4Numbers J4Numbers temporarily deployed to Integrate Pull Request July 16, 2023 17:17 — with GitHub Actions Inactive
@amimas amimas requested a review from gdubicki July 16, 2023 19:13
@J4Numbers J4Numbers temporarily deployed to Integrate Pull Request July 18, 2023 19:16 — with GitHub Actions Inactive
@gdubicki gdubicki had a problem deploying to Integrate Pull Request July 20, 2023 21:30 — with GitHub Actions Failure
@amimas amimas temporarily deployed to Integrate Pull Request August 4, 2023 22:24 — with GitHub Actions Inactive
@amimas
Copy link
Collaborator

amimas commented Aug 4, 2023

@J4Numbers - Pushed the latest update to your branch. Noticed a test failure from one of your test case.

https://github.com/gitlabform/gitlabform/actions/runs/5767054764/job/15636113972?pr=556

Is this an intermittent test failure? If yes, would you be able to look into the test setup? It'd be good to have it fixed if possible as intermittent failures take away too much time in processing other PRs.

Hopefully we can merge this PR soon.

@amimas
Copy link
Collaborator

amimas commented Aug 24, 2023

@J4Numbers - Did you get a chance to look at the test failure mentioned above?

@gdubicki gdubicki temporarily deployed to Integrate Pull Request August 25, 2023 11:42 — with GitHub Actions Inactive
@J4Numbers
Copy link
Contributor Author

J4Numbers commented Aug 30, 2023

Ah, sorry. I started looking into it, but then real life got in the way slightly. From what I can tell, a lot of the code should be pretty segregated due to the random group creation that the tests are separated between (something similar to gitlabform_group_horse) which then has its own projects and users - all of which follow that format of gitlabform_{basename}_{random_xkcd_string} which makes unpicking why the tests are interdependent... fun.

I can keep looking into it if required, but the base logic for generating random groups/projects/users/etc. seems sound (though the reliance on randomness is eh), which makes me suspect that it might be something to do with the fixtures holding state when they shouldn't...

@J4Numbers J4Numbers temporarily deployed to Integrate Pull Request August 30, 2023 23:48 — with GitHub Actions Inactive
@J4Numbers J4Numbers temporarily deployed to Integrate Pull Request August 31, 2023 00:00 — with GitHub Actions Inactive
@J4Numbers J4Numbers temporarily deployed to Integrate Pull Request September 2, 2023 00:44 — with GitHub Actions Inactive
@J4Numbers
Copy link
Contributor Author

So, as far as I can tell, separating the two project member tests into their own fixtures seems to have resolved my issue. And this run seems to have rolled a lucky six so far in terms of pipelines behaving...

I did notice one other intermittent failure, which was regarding a branch protection test. (See: https://github.com/gitlabform/gitlabform/actions/runs/6031288955/job/16364708681)

@amimas
Copy link
Collaborator

amimas commented Sep 2, 2023

I started looking into it, but then real life got in the way slightly.

Hey @J4Numbers . Completely understandable. Hope all is well. Thanks for continuing with this PR. Really appreciate it 🙏 .

@amimas
Copy link
Collaborator

amimas commented Sep 2, 2023

makes me suspect that it might be something to do with the fixtures holding state when they shouldn't...

So, as far as I can tell, separating the two project member tests into their own fixtures seems to have resolved my issue. And this run seems to have rolled a lucky six so far in terms of pipelines behaving...

First of all, thanks for making it more reliable. I'm not an expert at this but think you're on the right path. Looks like you've split your original tests into 2 separate test class (i.e. tests/acceptance/standard/test_project_members_case_insensitve.py and tests/acceptance/standard/test_project_group_members_case_insensitive.py`).

I believe what was happening before is that the tests were in the same class. Both tests were using the project fixture whose scope is at the class level. So, when the first test's membership is updated and verified, the 2nd test's evaluation will need to keep in mind the result from the earlier test, unless that one manually did the cleanup of members so that the project is at it's initial state. Why this happens intermittently, I'm not sure. Another similar intermittent issue was addressed by switching to project_for_function fixture in the test cases instead of using the project fixture. This has the same effect as splitting the tests into separate classes as you've done.

It would probably be nice if those tests were in the same class. Reduce some duplication and logically grouped; might be easier to maintain.

@gdubicki - Would you be able to do another review, please?

tests/acceptance/__init__.py Outdated Show resolved Hide resolved
@amimas
Copy link
Collaborator

amimas commented Sep 2, 2023

I did notice one other intermittent failure, which was regarding a branch protection test. (See: https://github.com/gitlabform/gitlabform/actions/runs/6031288955/job/16364708681)

Yeah, I noticed it a few times too. It's annoying 😄 .

@J4Numbers J4Numbers temporarily deployed to Integrate Pull Request September 2, 2023 17:14 — with GitHub Actions Inactive
Copy link
Member

@gdubicki gdubicki left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for the contribution @J4Numbers!

gdubicki and others added 4 commits September 6, 2023 22:15
although they should not be, as in GitLab they are not.
(You cannot have 2 users in a GitLab instances for which
the username differs only in the case.)

Reported in gitlabform#466
Meddle with group and project membership checks to ensure that
usernames are case insensitive. This change ensures that users
are not added again by mistake, causing an error where a given
user already exists within the repository.

Signed-off-by: Jayne Doe <jayne.doe@ibm.com>
@amimas amimas temporarily deployed to Integrate Pull Request September 7, 2023 02:15 — with GitHub Actions Inactive
@amimas amimas enabled auto-merge (squash) September 7, 2023 02:25
@amimas amimas merged commit 2381ebe into gitlabform:main Sep 7, 2023
20 checks passed
@J4Numbers J4Numbers deleted the ignore_usernames_case branch September 7, 2023 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants