Skip to content

Commit

Permalink
fix: revert previous implemenation and use existing string util
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-lebleu committed Nov 19, 2024
1 parent 3d7cc23 commit 195ff64
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ static/uploads/*
.vscode
__pycache__

docker-compose.debug.yaml
docker-compose.debug.yaml
docker-compose.dev.yaml
1 change: 0 additions & 1 deletion config/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ scalar UUID
scalar Generic
scalar BigInt
scalar OpaqueID
scalar TrimmedString
type Query
type Mutation
10 changes: 1 addition & 9 deletions config/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
opaque_id_scalar = ScalarType("OpaqueID")
trimmed_string_scalar = ScalarType("TrimmedString")


@uuid_scalar.value_parser
def parse_uuid_value(value):
try:
Expand Down Expand Up @@ -69,14 +70,6 @@ def serialize_opaque_id(value):
return base64.b64encode(value.encode("utf-8")).decode("utf-8")


@trimmed_string_scalar.value_parser
def parse_trimmed_string(value):
try:
return value.strip()
except (ValueError, TypeError):
raise ValueError(f'"{value}" is not a valid string')


type_defs = load_schema_from_path(
f"{pathlib.Path(__file__).parent.resolve()}/graphql/schema.graphql"
)
Expand All @@ -102,7 +95,6 @@ def parse_trimmed_string(value):
[
uuid_scalar,
opaque_id_scalar,
trimmed_string_scalar,
*pipelines_bindables,
*identity_bindables,
*tags_bindables,
Expand Down
2 changes: 1 addition & 1 deletion hexa/user_management/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ input LoginInput {
"""
The email address of the user.
"""
email: TrimmedString
email: String!

"""
The password of the user.
Expand Down
10 changes: 9 additions & 1 deletion hexa/user_management/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from hexa.analytics.api import track
from hexa.core.graphql import result_page
from hexa.core.string import remove_whitespace
from hexa.core.templatetags.colors import hash_color
from hexa.user_management.models import (
AlreadyExists,
Expand Down Expand Up @@ -297,8 +298,15 @@ def resolve_delete_team(_, info, **kwargs):
def resolve_login(_, info, **kwargs):
request: HttpRequest = info.context["request"]
mutation_input = kwargs["input"]

trimmed_email = remove_whitespace(mutation_input["email"])
# trimmed_email = mutation_input["email"].strip()

user_candidate = authenticate(
request, email=mutation_input["email"], password=mutation_input["password"]
request,
email=trimmed_email,
password=mutation_input["password"],
# request, email=mutation_input["email"], password=mutation_input["password"]
)

if user_candidate is None:
Expand Down
17 changes: 17 additions & 0 deletions hexa/user_management/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,23 @@ def test_login_without_two_factor(self):
r["data"]["login"],
)

def test_login_with_whitespace(self):
r = self.run_query(
"""
mutation login($input: LoginInput!) {
login(input: $input) {
success
}
}
""",
{"input": {"email": " [email protected]", "password": "jimspassword"}},
)

self.assertEqual(
{"success": True},
r["data"]["login"],
)

def test_login_invalid_credentials(self):
r = self.run_query(
"""
Expand Down

0 comments on commit 195ff64

Please sign in to comment.