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

Validation fails when claim has boolean false as value #23

Closed
stormcow opened this issue Jun 14, 2024 · 2 comments
Closed

Validation fails when claim has boolean false as value #23

stormcow opened this issue Jun 14, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@stormcow
Copy link
Contributor

stormcow commented Jun 14, 2024

Hello, I have noticed that when passing a claim that has a boolean false as value, the validation fails with Invalid claim error, e.g.:

registry = jwt.JWTClaimsRegistry(bool_claim={"essential": True})
registry.validate({"bool_claim": False})
Traceback (most recent call last):
  File "/home/schemer/test/test/main.py", line 23, in <module>
    registry.validate({"bool_claim": False})
  File "/home/schemer/test/.venv/lib/python3.12/site-packages/joserfc/rfc7519/registry.py", line 52, in validate
    self.check_value(key, value)
  File "/home/schemer/test/.venv/lib/python3.12/site-packages/joserfc/rfc7519/registry.py", line 31, in check_value
    raise InvalidClaimError(claim_name)
joserfc.errors.InvalidClaimError: invalid_claim: Invalid claim: "bool_claim"

But the same registry validates correctly when the claim has a boolean true:

registry = jwt.JWTClaimsRegistry(bool_claim={"essential": True})
registry.validate({"bool_claim": True})

I went through the code, and found that the issue is getting raised here:

if not allow_blank and not value:

Passing the "allow_blank" option does fix this, but I don't want to have a blank claim and I want to always ensure that it has a value.

@stormcow
Copy link
Contributor Author

stormcow commented Jun 14, 2024

The exception is raised on all falsy values of a claim without the "allow_blank" option. So if I were for example to pass this claim:

registry.validate({"int_claim": 0})

i will still get an exception, even though it isn't null nor is it empty.

Traceback (most recent call last):
  File "/home/schemer/test/test/main.py", line 28, in <module>
    registry.validate({"int_claim": 0})
  File "/home/schemer/test/.venv/lib/python3.12/site-packages/joserfc/rfc7519/registry.py", line 52, in validate
    self.check_value(key, value)
  File "/home/schemer/test/.venv/lib/python3.12/site-packages/joserfc/rfc7519/registry.py", line 31, in check_value
    raise InvalidClaimError(claim_name)
joserfc.errors.InvalidClaimError: invalid_claim: Invalid claim: "int_claim"

Is this behaviour intended?

@lepture lepture added the bug Something isn't working label Jun 15, 2024
@lepture
Copy link
Member

lepture commented Jun 15, 2024

Released 0.12.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants