diff --git a/.gitignore b/.gitignore index 795803c4e..27c47971d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ static/uploads/* .vscode __pycache__ -docker-compose.debug.yaml \ No newline at end of file +docker-compose.debug.yaml +docker-compose.dev.yaml \ No newline at end of file diff --git a/config/graphql/schema.graphql b/config/graphql/schema.graphql index dc8f04d4a..a2710b6f5 100644 --- a/config/graphql/schema.graphql +++ b/config/graphql/schema.graphql @@ -6,6 +6,5 @@ scalar UUID scalar Generic scalar BigInt scalar OpaqueID -scalar TrimmedString type Query type Mutation diff --git a/config/schema.py b/config/schema.py index 94ec756c0..fb3e4c1ed 100644 --- a/config/schema.py +++ b/config/schema.py @@ -37,6 +37,7 @@ opaque_id_scalar = ScalarType("OpaqueID") trimmed_string_scalar = ScalarType("TrimmedString") + @uuid_scalar.value_parser def parse_uuid_value(value): try: @@ -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" ) @@ -102,7 +95,6 @@ def parse_trimmed_string(value): [ uuid_scalar, opaque_id_scalar, - trimmed_string_scalar, *pipelines_bindables, *identity_bindables, *tags_bindables, diff --git a/hexa/user_management/graphql/schema.graphql b/hexa/user_management/graphql/schema.graphql index 6d6b4fda5..0adbbaded 100644 --- a/hexa/user_management/graphql/schema.graphql +++ b/hexa/user_management/graphql/schema.graphql @@ -110,7 +110,7 @@ input LoginInput { """ The email address of the user. """ - email: TrimmedString + email: String! """ The password of the user. diff --git a/hexa/user_management/schema.py b/hexa/user_management/schema.py index 6aaf734be..2521680a0 100644 --- a/hexa/user_management/schema.py +++ b/hexa/user_management/schema.py @@ -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, @@ -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: diff --git a/hexa/user_management/tests/test_schema.py b/hexa/user_management/tests/test_schema.py index 9d8d0447e..10bbbfaac 100644 --- a/hexa/user_management/tests/test_schema.py +++ b/hexa/user_management/tests/test_schema.py @@ -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": " jim@bluesquarehub.com", "password": "jimspassword"}}, + ) + + self.assertEqual( + {"success": True}, + r["data"]["login"], + ) + def test_login_invalid_credentials(self): r = self.run_query( """