Skip to content

Commit

Permalink
🐛 Fix obfuscation of missing claims
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed May 23, 2024
1 parent e48d55a commit 09d58d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mozilla_django_oidc_db/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections.abc import Collection
from copy import deepcopy

from glom import Path, assign, glom
from glom import Path, PathAccessError, assign, glom
from requests.utils import _parse_content_type_header # type: ignore

from .typing import ClaimPath, JSONObject, JSONValue
Expand Down Expand Up @@ -32,7 +32,10 @@ def obfuscate_claims(
copied_claims = deepcopy(claims)
for claim_bits in claims_to_obfuscate:
claim_path = Path(*claim_bits)
claim_value = glom(copied_claims, claim_path)
try:
claim_value = glom(copied_claims, claim_path)
except PathAccessError:
continue
assign(copied_claims, claim_path, obfuscate_claim_value(claim_value))
return copied_claims

Expand Down
9 changes: 9 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from mozilla_django_oidc_db.typing import JSONObject
from mozilla_django_oidc_db.utils import obfuscate_claim_value, obfuscate_claims


Expand Down Expand Up @@ -45,3 +46,11 @@ def test_obfuscate_nested():
result = obfuscate_claims(claims, claims_to_obfuscate)

assert result == expected_result


def test_obfuscate_with_missing_claims():
claims: JSONObject = {"present": "12345"}

result = obfuscate_claims(claims, claims_to_obfuscate=(["missing"], ["present"]))

assert result == {"present": "****5"}

0 comments on commit 09d58d2

Please sign in to comment.