Skip to content

Conversation

equalsgibson
Copy link
Contributor

Closes #453

Adds an additional test to parser_test.go, that validates the library can parse the valid JWT Claims in the token to a custom Go struct with different types - validates:

  • a string
  • a number
  • an object (JSON object)
  • an array
  • a boolean
  • null

Which should provide coverage for all valid data types as per the JSON spec

Copy link
Collaborator

@oxisto oxisto left a comment

Choose a reason for hiding this comment

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

Good idea. One small nit. It does however not really increase our test coverage, since this is basically handled by encoding/json. However, there were some issues creeping up where folks didn't get their custom claims parsed, so this should help to weed out any errors here.

@equalsgibson equalsgibson changed the title Additional test coverage for CustomClaims with most JSON Data Types Additional test for CustomClaims that validates unmarshalling behaviour Aug 3, 2025
@equalsgibson
Copy link
Contributor Author

Hi @oxisto, I agree with your comment on coverage (this does not add any "additional" coverage to the package), and I've updated the PR title accordingly

Please let me know if you would like any further changes 👍🏻

@mfridman
Copy link
Member

mfridman commented Aug 3, 2025

However, there were some issues creeping up where folks didn't get their custom claims parsed

How so? Weren't most of these user errors.

Not entirely sure we're adding anything here that the standard library doesn't already test.

@equalsgibson
Copy link
Contributor Author

Hi @mfridman, the reasoning for adding the tests is that there is not documented proof for custom claims being marshalled currently. I agree that the std lib does this already - but as there is a wrapper function around the use of json.unmarshal, (with the parse functions), this ensures that if any changes are made to the implementation in this package, that current functionality (custom claims types) would not break.

Happy to close this out if not needed or if you feel it is not warranted 👍

@oxisto oxisto merged commit 331b964 into golang-jwt:main Aug 21, 2025
9 checks passed
@equalsgibson equalsgibson deleted the 453-CustomClaim-validation-test branch August 21, 2025 14:10
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.

custom claim with an integer field fails parsing
3 participants