Skip to content

Commit 69a0188

Browse files
committed
v0.1.14
1 parent d35785a commit 69a0188

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![build status](https://img.shields.io/github/actions/workflow/status/kataras/jwt/ci.yml?style=for-the-badge)](https://github.com/kataras/jwt/actions) [![gocov](https://img.shields.io/badge/Go%20Coverage-92%25-brightgreen.svg?style=for-the-badge)](https://travis-ci.org/github/kataras/jwt/jobs/740739405#L322) [![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=for-the-badge)](https://goreportcard.com/report/github.com/kataras/jwt) [![godocs](https://img.shields.io/badge/go-%20docs-488AC7.svg?style=for-the-badge)](https://pkg.go.dev/github.com/kataras/jwt)
44

5-
Fast and simple [JWT](https://jwt.io/#libraries-io) & JWKS implementation written in [Go](https://go.dev/dl/). This package was designed with security, performance and simplicity in mind, it protects your tokens from [critical vulnerabilities that you may find in other libraries](https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries).
5+
Zero-dependency lighweight, fast and simple [JWT](https://jwt.io/#libraries-io) & JWKS implementation written in [Go](https://go.dev/dl/). This package was designed with security, performance and simplicity in mind, it protects your tokens from [critical vulnerabilities that you may find in other libraries](https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries).
66

77
[![Benchmarks Total Repetitions - higher is better](http://iris-go.com/images/jwt/benchmarks.png)](_benchmarks)
88

claims_test.go

+8-16
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ func TestMerge(t *testing.T) {
199199
},
200200
expected: map[string]interface{}{
201201
"custom": "value",
202-
"iss": "test-issuer",
203-
"iat": float64(now), // JSON numbers are decoded as float64
204-
"exp": float64(expiry),
202+
"iss": "test-issuer",
203+
"iat": float64(now), // JSON numbers are decoded as float64
204+
"exp": float64(expiry),
205205
},
206206
},
207207
{
@@ -215,14 +215,12 @@ func TestMerge(t *testing.T) {
215215
for _, tt := range tests {
216216
t.Run(tt.name, func(t *testing.T) {
217217
result := Merge(tt.claims, tt.other)
218-
219-
// 解码结果
218+
220219
var got map[string]interface{}
221220
if err := json.Unmarshal(result, &got); err != nil {
222221
t.Fatalf("Failed to unmarshal result: %v", err)
223222
}
224223

225-
// 比较解码后的结果
226224
if !reflect.DeepEqual(got, tt.expected) {
227225
t.Errorf("Merge() = %v, want %v", got, tt.expected)
228226
}
@@ -264,29 +262,26 @@ func TestMergeAndSign(t *testing.T) {
264262
},
265263
expected: map[string]interface{}{
266264
"custom": "value",
267-
"iss": "test-issuer",
268-
"iat": fmt.Sprintf("%d", now),
269-
"exp": fmt.Sprintf("%d", expiry),
265+
"iss": "test-issuer",
266+
"iat": fmt.Sprintf("%d", now),
267+
"exp": fmt.Sprintf("%d", expiry),
270268
},
271269
},
272270
}
273271

274272
key := []byte("secret")
275273
for _, tt := range tests {
276274
t.Run(tt.name, func(t *testing.T) {
277-
// 合并 claims
275+
278276
mergedClaims := Merge(tt.claims, tt.other)
279277

280-
// 使用合并后的 claims 生成 token
281278
token, err := Sign(HS256, key, mergedClaims)
282279
if err != nil {
283280
t.Fatalf("Failed to sign token: %v", err)
284281
}
285282

286-
// 打印生成的 token
287283
t.Logf("Generated token: %s", string(token))
288284

289-
// 验证并解析 token
290285
var verifiedClaims map[string]interface{}
291286
verifiedToken, err := Verify(HS256, key, token)
292287
if err != nil {
@@ -298,21 +293,18 @@ func TestMergeAndSign(t *testing.T) {
298293
t.Fatalf("Failed to get claims from token: %v", err)
299294
}
300295

301-
// 将 json.Number 转换为字符串
302296
if exp, ok := verifiedClaims["exp"].(json.Number); ok {
303297
verifiedClaims["exp"] = exp.String()
304298
}
305299
if iat, ok := verifiedClaims["iat"].(json.Number); ok {
306300
verifiedClaims["iat"] = iat.String()
307301
}
308302

309-
// 打印类型信息
310303
t.Logf("Expected exp type: %T, value: %v", tt.expected["exp"], tt.expected["exp"])
311304
t.Logf("Actual exp type: %T, value: %v", verifiedClaims["exp"], verifiedClaims["exp"])
312305
t.Logf("Expected iat type: %T, value: %v", tt.expected["iat"], tt.expected["iat"])
313306
t.Logf("Actual iat type: %T, value: %v", verifiedClaims["iat"], verifiedClaims["iat"])
314307

315-
// 比较解析后的 claims 是否与预期一致
316308
if !reflect.DeepEqual(verifiedClaims, tt.expected) {
317309
t.Errorf("Claims after merge and verify = %#v, want %#v", verifiedClaims, tt.expected)
318310
}

0 commit comments

Comments
 (0)