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 username anonymization #70

Merged
merged 3 commits into from
Aug 30, 2023
Merged

Fix username anonymization #70

merged 3 commits into from
Aug 30, 2023

Conversation

mabulgu
Copy link
Contributor

@mabulgu mabulgu commented Aug 25, 2023

This PR fixes the username anonymization in a path by ignoring the Jinja templates in the name fields.

Fixes https://issues.redhat.com/browse/AAP-14989.

@mabulgu mabulgu changed the title Fix username anonymization by ignoring jinja Fix username anonymization Aug 25, 2023
@mabulgu mabulgu marked this pull request as ready for review August 25, 2023 23:07
@mabulgu mabulgu requested a review from goneri August 25, 2023 23:07
r"(?P<before>[c-z]:\\users\\)(?P<user_name>\w{,255})",
r"(?P<before>/(home|Users)/)(?P<user_name>[a-z0-9_-]{,255})",
r"(?P<before>[c-z]:\\users\\)(?P<user_name>([a-z0-9_-]|{{\s*.*?\s*}})\w{,255})",
r"(?P<before>/(home|Users)/)(?P<user_name>([a-z0-9_-]|{{\s*.*?\s*}})[a-z0-9_-]{,255})",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is [a-z0-9_-] for? We've got already a pattern to match the login name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I dont put it with an or (|), it will match the jinjas but not the regular texts:

https://regex101.com/r/y2o0d9/1

However, upon your comment the second one seems redundant. removing it seems to be working: https://regex101.com/r/54R0ZI/1

Let me check with the code and update it if the tests work.

Copy link
Collaborator

Choose a reason for hiding this comment

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

On Windows, a login name can come with non ASCII characters. [a-z0-9_-] is more strict than just \w which accepts any Unicode characters.

>>> import re
>>> re.match(r"[a-z0-9_-]+", "aaa")
<re.Match object; span=(0, 3), match='aaa'>
>>> re.match(r"[a-z0-9_-]+", "ááá")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On Windows, a login name can come with non ASCII characters. [a-z0-9_-] is more strict than just \w which accepts any Unicode characters.

>>> import re
>>> re.match(r"[a-z0-9_-]+", "aaa")
<re.Match object; span=(0, 3), match='aaa'>
>>> re.match(r"[a-z0-9_-]+", "ááá")

@goneri I must have preserved that \w for the windows version. Note that the code updates are different than the above regex links, which I created before I understood your point better.

@sonarcloud
Copy link

sonarcloud bot commented Aug 28, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@mabulgu mabulgu requested a review from goneri August 28, 2023 18:52
@goneri goneri merged commit 22e36bf into main Aug 30, 2023
4 checks passed
@goneri
Copy link
Collaborator

goneri commented Aug 30, 2023

Thank you @mabulgu

@mabulgu
Copy link
Contributor Author

mabulgu commented Aug 30, 2023

Thank you @mabulgu

Merci @goneri !!

@mabulgu mabulgu deleted the fix/username-anonymization branch August 30, 2023 14:44
mabulgu added a commit that referenced this pull request Aug 31, 2023
Bump version and add changelog for #70 fix
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.

2 participants