Skip to content

Commit

Permalink
feat(types): Added boolean types for registry value and values options
Browse files Browse the repository at this point in the history
added tests for boolean value and values in registry
  • Loading branch information
stormcow committed Jun 15, 2024
1 parent 2250618 commit 5e58bb3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/joserfc/rfc7519/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
class ClaimsOption(TypedDict, total=False):
essential: bool
allow_blank: Optional[bool]
value: Union[str, int]
values: Union[List[Union[str, int]], List[str], List[int]]
value: Union[str, int, bool]
values: Union[List[Union[str, int, bool]], List[str], List[int], List[bool]]


class ClaimsRegistry:
Expand Down
10 changes: 9 additions & 1 deletion tests/jwt/test_claims.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,20 @@ def test_option_value(self):
claims_requests = jwt.JWTClaimsRegistry(sub={"essential": True, "value": "123"})
self.assertRaises(InvalidClaimError, claims_requests.validate, {"sub": "a"})
claims_requests.validate({"sub": "123"})
claims_requests = jwt.JWTClaimsRegistry(sub={"essential":True,"value":True})
claims_requests.validate({"sub":True})
self.assertRaises(InvalidClaimError,claims_requests.validate,{"sub":False})
claims_requests = jwt.JWTClaimsRegistry(sub={"essential":True,"value":False})
claims_requests.validate({"sub":False})
self.assertRaises(InvalidClaimError,claims_requests.validate,{"sub":True})

def test_option_values(self):
claims_requests = jwt.JWTClaimsRegistry(sub={"essential": True, "values": ["1", "2"]})
claims_requests = jwt.JWTClaimsRegistry(sub={"essential": True, "values": ["1", "2", True, False]})
self.assertRaises(InvalidClaimError, claims_requests.validate, {"sub": "a"})
claims_requests.validate({"sub": "1"})
claims_requests.validate({"sub": "2"})
claims_requests.validate({"sub":True})
claims_requests.validate({"sub":False})

def test_int_claims(self):
now = int(time.time())
Expand Down

0 comments on commit 5e58bb3

Please sign in to comment.