Repository navigation
test: cover decode success when required claims are present - #1220
Open
renanmpimentel wants to merge 1 commit into
Open
renanmpimentel wants to merge 1 commit into
renanmpimentel wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Adds
test_decode_should_succeed_if_required_claims_are_presentnext to the existingrequiretests intests/test_api_jwt.py. It decodes a token that carriesexp,iatandnbfwithoptions={"require": ["exp", "iat", "nbf"]}and asserts that the payload is returned unchanged.Why
The existing
requiretests are all negative (test_decode_should_raise_error_if_{exp,iat,nbf}_required_but_not_present, plus thesub/jtivariants). They check that a missing claim raisesMissingRequiredClaimError, but nothing checks that a token which does contain the required claims is accepted. The usage docs only show the error case as well.As a result, a regression in
_validate_required_claimsthat rejects every token wheneverrequireis set leaves the whole suite green, e.g.:With either change, every
jwt.decode(..., options={"require": [...]})call raises, even for valid tokens.Verification
pytestwithcryptography: 472 passed, 4 skipped (was 471)pytestwithoutcryptography: 287 passed, 189 skipped (was 286)mypy: no issuespre-commit run --files tests/test_api_jwt.py: passedMissingRequiredClaimError: Token is missing the "exp" claimThis is a test-only change, so I didn't add a CHANGELOG entry. Could a maintainer apply the
testslabel so the changelog check is skipped?I found this while experimenting with Supertest, a tool for evaluating test effectiveness using mutation testing and test-harness mutilation.