Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(registry): treat null claim value as missing #14

Merged
merged 1 commit into from
Oct 7, 2023

Conversation

alonbl
Copy link
Contributor

@alonbl alonbl commented Oct 6, 2023

Assert the following to be true:

essential allow_blank value result
True False missing MissingClaimError
True False null MissingClaimError
True False "" InvalidClaimError
True False "x" Accepted
True True missing MissingClaimError
True True null MissingClaimError
True True "" Accepted
True True "x" Accepted

Code:

    def test_essential_empty_value(self):
        claims_requests = jwt.JWTClaimsRegistry(sub={"essential": True})
        self.assertRaises(MissingClaimError, claims_requests.validate, {"sub": None})

@lepture : please tell me if you want to treat this as MissingClaimError or InvalidClaimError, I believe that JSON null value should be treated as missing.

@codecov
Copy link

codecov bot commented Oct 6, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (2f7a541) 99.80% compared to head (73171a3) 99.80%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #14   +/-   ##
=======================================
  Coverage   99.80%   99.80%           
=======================================
  Files          44       44           
  Lines        2548     2548           
  Branches      371      309   -62     
=======================================
  Hits         2543     2543           
  Misses          1        1           
  Partials        4        4           
Flag Coverage Δ
unittests 99.80% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/joserfc/rfc7519/registry.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Assert the following to be true:

    essential   allow_blank     value       result

    True        False           missing     MissingClaimError
    True        False           null        MissingClaimError
    True        False           ""          InvalidClaimError
    True        False           "x"         Accepted
    True        True            missing     MissingClaimError
    True        True            null        MissingClaimError
    True        True            ""          Accepted
    True        True            "x"         Accepted

Code:

    def test_essential_empty_value(self):
        claims_requests = jwt.JWTClaimsRegistry(sub={"essential": True})
        self.assertRaises(MissingClaimError, claims_requests.validate, {"sub": None})

Signed-off-by: Alon Bar-Lev <[email protected]>
@sonarcloud
Copy link

sonarcloud bot commented Oct 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

raise MissingClaimError(",".join(missed_key))
missed_keys = {key for key in self.essential_keys if claims.get(key) is None}
if missed_keys:
raise MissingClaimError(",".join(sorted(missed_keys)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to sort keys here? I'm ok with the sorting. But is there a reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is human readable message, it should be deterministic. As set order is not deterministic we should sort it.

@lepture lepture merged commit cae2347 into authlib:main Oct 7, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants