-
-
Notifications
You must be signed in to change notification settings - Fork 386
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
Unsanitize user and org names in DB #4762
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4762 +/- ##
==========================================
- Coverage 28.29% 28.28% -0.01%
==========================================
Files 398 399 +1
Lines 28295 28318 +23
==========================================
+ Hits 8005 8011 +6
- Misses 19580 19594 +14
- Partials 710 713 +3 ☔ View full report in Codecov by Sentry. |
server/store/datastore/migration/024_unsanitize_org_and_user_names.go
Outdated
Show resolved
Hide resolved
server/store/datastore/migration/024_unsanitize_org_and_user_names.go
Outdated
Show resolved
Hide resolved
server/store/datastore/migration/024_unsanitize_org_and_user_names.go
Outdated
Show resolved
Hide resolved
server/store/datastore/migration/024_unsanitize_org_and_user_names.go
Outdated
Show resolved
Hide resolved
…ames.go Co-authored-by: Robert Kaussow <[email protected]>
…ames.go Co-authored-by: Robert Kaussow <[email protected]>
…ames.go Co-authored-by: Robert Kaussow <[email protected]>
…ames.go Co-authored-by: Robert Kaussow <[email protected]>
Tests are failing. |
After thinking of it again, I'm not sure if thats the best approach. Cant really say why but I see a lot of potential for issues and corner cases. Looks like this issue only occurs with forgejo/gitea and the api returns mixed capitalization while the forge only supports case-insensitive values. What do you think? Edit: Tested it. You can create an org "Foo" in gitea and in that case its even displayed as "Foo" in the url.... But you cant create "foo" with the error "The organization name is already taken." This is a somewhat inconsistent behavior upstream, however I think we should switch back to the initial approach from @pat-s |
If all users are sanitized, the user list in the UI would also reflect a non-optimal state. The simplest fix which also wouldn't require a migration would probably be to just sanitize the comparison call of |
Why does the license header of the migration start with |
Ok I dont have time to look into this on my own. Feel free to go on if you think the current state is fine. |
In best case we add a test case. Try to write "org1/foo" and "org1/Foo" to the db. If it fails, we are good to go if not we should still add db level restrictions. |
Added two tests which explicitly check that attempting to add a case-sensitive duplicate for orgs and users results in an error. |
Thanks! |
Deployment of preview was successful: https://woodpecker-ci-woodpecker-pr-4762.surge.sh |
Code LGTM, have you tested the PR locally? |
@anbraten Something is wrong. I have applied this PR to an existing WP instance. While I was able to log-in with the user before this PR, this now fails:
|
I also noticed this sql errors in the logs:
but the table is called Edit: This seems to be unrelated https://github.com/woodpecker-ci/woodpecker/blob/main/server/store/datastore/migration/migration.go#L84 |
I've seen this error before a few times.
This is worrisome. Can you check which forge ID got assigned to the user org? Actually, tests should catch this. |
Co-authored-by: Robert Kaussow <[email protected]>
server/store/datastore/org.go
Outdated
name = strings.ToLower(name) | ||
org := new(model.Org) | ||
return org, wrapGet(sess.Where("name = ?", name).Get(org)) | ||
return org, wrapGet(sess.Where("LOWER(name) = ?", strings.ToLower(name)).Get(org)) |
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.
This might be a mistake? I thought we don't want to sanitize calls/entries in the DB but only to the forge API.
Also removing sanitation in l87 and then re-adding it seems strange.
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.
The idea is to have searching case insensitive and storing case sensitive (the same way how forges do it, you can use both ways in urls etc and it shows the casing in the UI etc the user used).
Also removing sanitation in l87 and then re-adding it seems strange.
It was previously missing the lower part on both sides. The change makes it unique with other calls.
|
Strange, I started to add a method to the storage interface to directly get an org by name and forge-id, that might prevent such cases. Forge-id 0 sounds like not set at all (gos default for not setting a number). |
Yeah maybe we mixed in too much different fixes into this PR? Can we revert it to focus on the sanitizing issue and move other improvements to another PR? I have a backup of the DB before the migration from this PR so I can also re-test this PR. |
Extracted most other changes to #4817 |
fix #3614
As discussed in chat, preferred to use non-sanitized values everywhere.