decode does not allow stubbing for unit test with libraries such as sinon
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- javascript, node.js
Research direction
Start by reading commit 15a1bc449ab529d540eb9c2be4e093f9f5b0278d and locating how decode is defined in node-jsonwebtoken. Reproduce the direct reassignment shown in the issue, then verify that decode can be altered without the TypeError and add coverage for that behavior.
Written by the indexing model from the issue text.
Description
Description
Changes to how decode is defined in 9.0.0 (https://github.com/auth0/node-jsonwebtoken/commit/15a1bc449ab529d540eb9c2be4e093f9f5b0278d) prevent it from being altered for unit tests by tools such as sinon, or even direct alteration such as
jwt.decode = function() { return( 'teststring' ); };
As a result errors such as TypeError: Cannot redefine property: decode are thrown in these scenarios.
Other JWT libraries such as jose have added configurable: true to allow this scenario to succeed, which should probably be done here too:
- discussion: https://stackoverflow.com/a/64598197
- fix: https://github.com/panva/jose/commit/6c3b92f4394a5d7092d7336922eda61e311e6f8c
Reproduction
Test code such as
jwt.decode = function() { return( 'teststring' ); };
results in
TypeError: Cannot redefine property
Environment
- Version of this library used:
9.0.0 - Version of the platform or framework used, if applicable:
n/a - Other relevant versions (language, server software, OS, browser):
n/a - Other modules/plugins/libraries that might be involved:
n/a
- Dominant language
- JavaScript
- Stars
- 18.2k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from auth0/node-jsonwebtoken
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
auth0/node-jsonwebtoken#1042 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
auth0/node-jsonwebtoken#1000 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 65/100
auth0/node-jsonwebtoken#1046 ·
-
Difficulty 5/5 Over a week Newbie friendliness 10/100
auth0/node-jsonwebtoken#1034 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
auth0/node-jsonwebtoken#1032 ·
All issues in auth0/node-jsonwebtoken
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area-deployment area-integrations triage:bot-seen
Difficulty 2/5 Half a day Newbie friendliness 86/100
-
Issue-Bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
sugarlabs/musicblocks#8924 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
ArduPilot/ardupilot_wiki#8088 ·
-
[BUG] createTool tools cannot be registered with Mastra when exactOptionalPropertyTypes is enabled Opencustomer-eng status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100