From 3d7cc234a7b6c8daf1e8a38ef4acb6295ac0171c Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 14 Nov 2024 12:16:19 +0100 Subject: [PATCH] fix: silent email address trim --- config/graphql/schema.graphql | 1 + config/schema.py | 11 ++++++++++- hexa/user_management/graphql/schema.graphql | 2 +- hexa/user_management/schema.py | 1 - 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config/graphql/schema.graphql b/config/graphql/schema.graphql index a2710b6f5..dc8f04d4a 100644 --- a/config/graphql/schema.graphql +++ b/config/graphql/schema.graphql @@ -6,5 +6,6 @@ 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 78e7adad7..94ec756c0 100644 --- a/config/schema.py +++ b/config/schema.py @@ -35,7 +35,7 @@ uuid_scalar = ScalarType("UUID") opaque_id_scalar = ScalarType("OpaqueID") - +trimmed_string_scalar = ScalarType("TrimmedString") @uuid_scalar.value_parser def parse_uuid_value(value): @@ -69,6 +69,14 @@ 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" ) @@ -94,6 +102,7 @@ def serialize_opaque_id(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 0adbbaded..6d6b4fda5 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: String! + email: TrimmedString """ The password of the user. diff --git a/hexa/user_management/schema.py b/hexa/user_management/schema.py index b5d4824b9..6aaf734be 100644 --- a/hexa/user_management/schema.py +++ b/hexa/user_management/schema.py @@ -297,7 +297,6 @@ def resolve_delete_team(_, info, **kwargs): def resolve_login(_, info, **kwargs): request: HttpRequest = info.context["request"] mutation_input = kwargs["input"] - user_candidate = authenticate( request, email=mutation_input["email"], password=mutation_input["password"] )