Skip to content

Commit

Permalink
✅ Add test for claim obfuscation configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Jun 13, 2024
1 parent 54206fa commit 48667bf
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions tests/oidc/test_claim_obfuscation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import pytest
from mozilla_django_oidc_db.models import OpenIDConnectConfigBase
from mozilla_django_oidc_db.typing import JSONObject
from mozilla_django_oidc_db.utils import obfuscate_claims

from digid_eherkenning.oidc.models import (
DigiDConfig,
DigiDMachtigenConfig,
EHerkenningBewindvoeringConfig,
EHerkenningConfig,
)


@pytest.mark.parametrize(
"config,claims,expected",
(
(
DigiDConfig(bsn_claim=["bsn"]),
{"bsn": "123456789", "other": "other"},
{"bsn": "*******89", "other": "other"},
),
(
DigiDMachtigenConfig(
representee_bsn_claim=["aanvrager"],
authorizee_bsn_claim=["gemachtigde"],
),
{
"aanvrager": "123456789",
"gemachtigde": "123456789",
"other": "other",
},
{
"aanvrager": "*******89",
"gemachtigde": "*******89",
"other": "other",
},
),
(
EHerkenningConfig(
legal_subject_claim=["kvk"],
acting_subject_claim=["ActingSubject"],
branch_number_claim=["branch"],
),
{
"kvk": "12345678",
"branch": "112233445566",
# this is already obfuscated by the broker
"ActingSubject": "1234567890@0987654321",
},
{
"kvk": "*******8",
"branch": "**********66",
# this is already obfuscated by the broker
"ActingSubject": "1234567890@0987654321",
},
),
(
EHerkenningBewindvoeringConfig(
representee_claim=["bsn"],
legal_subject_claim=["kvk"],
acting_subject_claim=["ActingSubject"],
branch_number_claim=["branch"],
),
{
"bsn": "123456789",
"kvk": "12345678",
"branch": "112233445566",
# this is already obfuscated by the broker
"ActingSubject": "1234567890@0987654321",
},
{
"bsn": "*******89",
"kvk": "*******8",
"branch": "**********66",
# this is already obfuscated by the broker
"ActingSubject": "1234567890@0987654321",
},
),
),
)
def test_claim_obfuscation(
config: OpenIDConnectConfigBase, claims: JSONObject, expected: JSONObject
):
obfuscated = obfuscate_claims(claims, config.oidcdb_sensitive_claims)

assert obfuscated == expected

0 comments on commit 48667bf

Please sign in to comment.