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

🐛 Is812/email case insensitive #3953

Closed

Conversation

pcrespov
Copy link
Member

@pcrespov pcrespov commented Mar 7, 2023

What do these changes do?

  • 🐛 These changes make emails' case insensitive.
    • Now we will store all emails in the database in lower case, and when a user wants to authenticate with upper case, or wants to add user to the group with upper case (as is mentioned in the issue below) it will be possible.

Related issue/s

How to test

Checklist

@pcrespov pcrespov added a:webserver issue related to the webserver service changelog:🐛bugfix labels Mar 7, 2023
@pcrespov pcrespov added this to the Mithril milestone Mar 7, 2023
@codecov
Copy link

codecov bot commented Mar 7, 2023

Codecov Report

Merging #3953 (add93f3) into master (6032512) will increase coverage by 1.2%.
The diff coverage is 100.0%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #3953     +/-   ##
========================================
+ Coverage    85.0%   86.2%   +1.2%     
========================================
  Files         935     797    -138     
  Lines       40313   35578   -4735     
  Branches      848     394    -454     
========================================
- Hits        34286   30687   -3599     
+ Misses       5804    4782   -1022     
+ Partials      223     109    -114     
Flag Coverage Δ
integrationtests 66.5% <87.5%> (-0.1%) ⬇️
unittests 83.1% <100.0%> (+0.8%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
.../simcore_service_catalog/db/repositories/groups.py 59.4% <100.0%> (ø)
...server/src/simcore_service_webserver/groups_api.py 97.0% <100.0%> (+0.5%) ⬆️
.../src/simcore_service_webserver/invitations_core.py 80.0% <100.0%> (ø)
...r/src/simcore_service_webserver/login/_security.py 100.0% <100.0%> (ø)
...c/simcore_service_webserver/login/handlers_auth.py 94.1% <100.0%> (ø)
...ver/src/simcore_service_webserver/login/storage.py 94.5% <100.0%> (+0.3%) ⬆️

... and 144 files with indirect coverage changes

@pcrespov pcrespov force-pushed the is812/email-case-insensitive branch from d1da7b4 to 6819f9c Compare March 9, 2023 11:47
@matusdrobuliak66 matusdrobuliak66 marked this pull request as ready for review March 13, 2023 10:07
@matusdrobuliak66 matusdrobuliak66 changed the title WIP: 🐛 Is812/email case insensitive 🐛 Is812/email case insensitive Mar 13, 2023
@sanderegg
Copy link
Member

Very nice addition, check please if test_groups.py changes really make sense?

@matusdrobuliak66
Copy link
Contributor

matusdrobuliak66 commented Mar 13, 2023

Very nice addition, check please if test_groups.py changes really make sense?

I tried to test 3 scenarios:

  • adding the user to the group as it was till now
  • adding the user to the group with the uppercase email even though we stored him in the database with lowercase (this is testing the situation of issue e-mails in simcore should be case-insensitives osparc-issues#812)
  • adding the user to the group with the lowercase email even though he was registered with the uppercase email (testing that the registration worked and it was changed to the lowercase so we can compare correctly)

Copy link
Member

@sanderegg sanderegg left a comment

Choose a reason for hiding this comment

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

it seems my comments did not make it through this morning. really sorry about this. now this should work. I have a few questions regarding test_groups.py syntax. we can also talk about it tomorrow.

@codeclimate
Copy link

codeclimate bot commented Mar 14, 2023

Code Climate has analyzed commit add93f3 and detected 0 issues on this pull request.

View more on Code Climate.

@sonarcloud
Copy link

sonarcloud bot commented Mar 14, 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 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Contributor

@GitHK GitHK left a comment

Choose a reason for hiding this comment

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

While you changes work. I am worried that in the future we might stumble upon bugs due to the different way we treat emails. We check agains the db for email [email protected] but in a template we might have [email protected] and this could cease some unexpected issues.
My proposal is to apply lower case as soon as the email hits one of the entry points of a service and always use it as lower case.

@@ -39,7 +39,9 @@ async def get_user_gid_from_email(
) -> Optional[PositiveInt]:
async with self.db_engine.connect() as conn:
return await conn.scalar(
sa.select([users.c.primary_gid]).where(users.c.email == user_email)
sa.select([users.c.primary_gid]).where(
users.c.email == user_email.lower()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not what I would have expected. I would have changed the email at the point of ingress in the application. At the edge (on the ingress API route).
Doing so gives the guarantee that the email string is the same during the entire request and not treated differently in some cases.
I would track where this is coming from and change it accordingly at that entry point.

Comment on lines +104 to +106
result = await conn.execute(
sa.select([users]).where(users.c.email == email.lower())
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above, please check the source(s) and apply lower case at the closes point of entry in the application.

@@ -24,7 +24,7 @@ async def login_granted_response(

Uses security API
"""
email = user["email"]
email = user["email"].lower()
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

@@ -110,7 +110,7 @@ async def login(request: web.Request):
)

assert user["status"] == ACTIVE, "db corrupted. Invalid status" # nosec
assert user["email"] == login_.email, "db corrupted. Invalid email" # nosec
assert user["email"] == login_.email.lower(), "db corrupted. Invalid email" # nosec
Copy link
Contributor

Choose a reason for hiding this comment

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

And here as well I would make sure that login_.email is already lower case when used here

Comment on lines +50 to +51
if with_data.get("email"):
with_data["email"] = with_data["email"].lower()
Copy link
Contributor

Choose a reason for hiding this comment

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

and here

Comment on lines +58 to +59
if data.get("email"):
data["email"] = data["email"].lower()
Copy link
Contributor

Choose a reason for hiding this comment

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

and here once more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:webserver issue related to the webserver service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

e-mails in simcore should be case-insensitives
4 participants