Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
jsonwebtoken.github.io/tests/utils.test.ts at master · jsonwebtoken/jsonwebtoken.github.io · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
jsonwebtoken
/
jsonwebtoken.github.io
Public
Notifications
You must be signed in to change notification settings
Fork
355
Star
597
Code
Issues
13
Pull requests
29
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
jsonwebtoken.github.io
/
tests
/
utils.test.ts
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
53 lines (46 loc) · 2.86 KB
master
Breadcrumbs
jsonwebtoken.github.io
/
tests
/
utils.test.ts
Copy path
Top
File metadata and controls
Code
Blame
53 lines (46 loc) · 2.86 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import
{
describe
,
expect
,
test
}
from
"vitest"
;
import
{
extractJwt
}
from
"@/features/common/services/utils"
;
describe
(
"extractJwt"
,
(
)
=>
{
test
(
"should return empty string for empty input"
,
(
)
=>
{
expect
(
extractJwt
(
""
)
)
.
toBe
(
""
)
;
expect
(
extractJwt
(
null
as
unknown
as
string
)
)
.
toBe
(
""
)
;
expect
(
extractJwt
(
undefined
as
unknown
as
string
)
)
.
toBe
(
""
)
;
}
)
;
test
(
"should extract JWT from normal input"
,
(
)
=>
{
const
jwt
=
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
;
expect
(
extractJwt
(
jwt
)
)
.
toBe
(
jwt
)
;
}
)
;
test
(
"should extract JWT with leading/trailing whitespace"
,
(
)
=>
{
const
jwt
=
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
;
const
jwtWithSpaces
=
`
${
jwt
}
`
;
expect
(
extractJwt
(
jwtWithSpaces
)
)
.
toBe
(
jwt
)
;
}
)
;
test
(
"should compact multiline JWTs by removing all whitespace"
,
(
)
=>
{
const
multilineJWT
=
`eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.
eyJjbGllbnRfaWQiOiJZekV6TUdkb01ISm5PSEJpT0cxaWJEaHlOVEE9IiwicmVzcG9uc2Vf
dHlwZSI6ImNvZGUiLCJzY29wZSI6ImludHJvc2NwZWN0X3Rva2VucywgcmV2b2tlX3Rva2Vu
cyIsImlzcyI6ImJqaElSak0xY1hwYWEyMXpkV3RJU25wNmVqbE1iazQ0YlRsTlpqazNkWEU9
Iiwic3ViIjoiWXpFek1HZG9NSEpuT0hCaU9HMWliRGh5TlRBPSIsImF1ZCI6Imh0dHBzOi8v
bG9jYWxob3N0Ojg0NDMve3RpZH0ve2FpZH0vb2F1dGgyL2F1dGhvcml6ZSIsImp0aSI6IjE1
MTYyMzkwMjIiLCJleHAiOiIyMDIxLTA1LTE3VDA3OjA5OjQ4LjAwMCswNTQ1In0.
IxvaN4ER-PlPgLYzfRhk_JiY4VAow3GNjaK5rYCINFsEPa7VaYnRsaCmQVq8CTgddihEPPXe
t2laH8_c3WqxY4AeZO5eljwSCobCHzxYdOoFKbpNXIm7dqHg_5xpQz-YBJMiDM1ILOEsER8A
DyF4NC2sN0K_0t6xZLSAQIRrHvpGOrtYr5E-SllTWHWPmqCkX2BUZxoYNK2FWgQZpuUOD55H
fsvFXNVQa_5TFRDibi9LsT7Sd_az0iGB0TfAb0v3ZR0qnmgyp5pTeIeU5UqhtbgU9RnUCVmG
IK-SZYNvrlXgv9hiKAZGhLgeI8hO40utfT2YTYHgD2Aiufqo3RIbJA`
;
const
compactedJWT
=
multilineJWT
.
replace
(
/
\s
+
/
g
,
""
)
;
expect
(
extractJwt
(
multilineJWT
)
)
.
toBe
(
compactedJWT
)
;
}
)
;
test
(
"should extract JWT from text with other content"
,
(
)
=>
{
const
jwt
=
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
;
const
textWithJWT
=
`Here is my token:
${
jwt
}
and some other text`
;
expect
(
extractJwt
(
textWithJWT
)
)
.
toBe
(
jwt
)
;
}
)
;
test
(
"should compact JWT with internal spaces"
,
(
)
=>
{
// This is a scenario where the JWT itself contains spaces (invalid, but should be handled)
const
jwtWithSpaces
=
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0 NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
;
// The spaces should be removed by our new implementation
const
compactedJWT
=
jwtWithSpaces
.
replace
(
/
\s
+
/
g
,
""
)
;
expect
(
extractJwt
(
jwtWithSpaces
)
)
.
toBe
(
compactedJWT
)
;
}
)
;
}
)
;
You can’t perform that action at this time.