From c7148043981b664bee92b77be03b972a0976444b Mon Sep 17 00:00:00 2001 From: Daniel Prange Date: Wed, 24 Jul 2024 09:56:19 +0300 Subject: [PATCH] feat: add enum in login_methods field Refs: HP-2490 --- .../tests/snapshots/snap_test_graphql_api_schema.py | 9 ++++++++- profiles/enums.py | 11 +++++++++++ profiles/schema.py | 6 ++++-- profiles/tests/test_gql_my_profile_query.py | 7 +++++-- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/open_city_profile/tests/snapshots/snap_test_graphql_api_schema.py b/open_city_profile/tests/snapshots/snap_test_graphql_api_schema.py index ac526795..8c993241 100644 --- a/open_city_profile/tests/snapshots/snap_test_graphql_api_schema.py +++ b/open_city_profile/tests/snapshots/snap_test_graphql_api_schema.py @@ -122,7 +122,7 @@ phones(offset: Int, before: String, after: String, first: Int, last: Int): PhoneNodeConnection addresses(offset: Int, before: String, after: String, first: Int, last: Int): AddressNodeConnection contactMethod: ContactMethod - loginMethods: [String] + loginMethods: [LoginMethodType] sensitivedata: SensitiveDataNode serviceConnections(offset: Int, before: String, after: String, first: Int, last: Int): ServiceConnectionTypeConnection verifiedPersonalInformation: VerifiedPersonalInformationNode @@ -216,6 +216,13 @@ SMS } +enum LoginMethodType { + PASSWORD + OTP + SUOMI_FI + HELSINKIAD +} + type SensitiveDataNode implements Node { id: ID! ssn: String! diff --git a/profiles/enums.py b/profiles/enums.py index 5de3faa6..e5f44d96 100644 --- a/profiles/enums.py +++ b/profiles/enums.py @@ -41,3 +41,14 @@ class Labels: WORK = _("Work address") HOME = _("Home address") OTHER = _("Other address") + + +class LoginMethodType(Enum): + PASSWORD = "password" + OTP = "otp" + SUOMI_FI = "suomi_fi" + + class Labels: + PASSWORD = _("Password") + OTP = _("One-time password") + SUOMI_FI = _("Suomi.fi") diff --git a/profiles/schema.py b/profiles/schema.py index 40ca6ca1..1da0359a 100644 --- a/profiles/schema.py +++ b/profiles/schema.py @@ -55,7 +55,7 @@ delete_connected_service_data, download_connected_service_data, ) -from .enums import AddressType, EmailType, PhoneType +from .enums import AddressType, EmailType, LoginMethodType, PhoneType from .keycloak_integration import delete_profile_from_keycloak, get_user_login_methods from .models import ( Address, @@ -581,7 +581,9 @@ class Meta: filterset_class = ProfileFilter login_methods = graphene.List( - graphene.String, + graphene.Enum.from_enum( + LoginMethodType, description=lambda e: e.label if e else "" + ), description="List of login methods that the profile has used to authenticate. " "Only visible to the user themselves.", ) diff --git a/profiles/tests/test_gql_my_profile_query.py b/profiles/tests/test_gql_my_profile_query.py index 3123fcc0..1e01e7b9 100644 --- a/profiles/tests/test_gql_my_profile_query.py +++ b/profiles/tests/test_gql_my_profile_query.py @@ -585,7 +585,7 @@ def test_user_can_see_own_login_methods_with_correct_amr_claim( user_gql_client, profile, group, service, monkeypatch, amr_claim_value ): def mock_return(*_, **__): - return {"foo", "bar"} + return {"suomi_fi", "password"} monkeypatch.setattr( "profiles.keycloak_integration.get_user_identity_providers", mock_return @@ -605,7 +605,10 @@ def mock_return(*_, **__): query, auth_token_payload={"amr": amr_claim_value}, service=service ) assert "errors" not in executed - assert set(executed["data"]["myProfile"]["loginMethods"]) == {"foo", "bar"} + assert set(executed["data"]["myProfile"]["loginMethods"]) == { + "SUOMI_FI", + "PASSWORD", + } @pytest.mark.parametrize("amr_claim_value", [None, "helsinkiad"])