From 88b3a842be9fd4d92babd752415e50d83d28487e Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Sun, 8 Dec 2024 13:59:30 +0000 Subject: [PATCH] Sync v1 with v2, comments and tests --- provider/custom_server_test.go | 2 +- provider/telegram_test.go | 1 - token/jwt.go | 1 + token/jwt_test.go | 9 ++++++--- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/provider/custom_server_test.go b/provider/custom_server_test.go index 3083920f..69c4f027 100644 --- a/provider/custom_server_test.go +++ b/provider/custom_server_test.go @@ -80,7 +80,7 @@ func TestCustomProvider(t *testing.T) { http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } - assert.Equal(t, 2, len(resp.Cookies())) + require.Equal(t, 2, len(resp.Cookies())) assert.Equal(t, "JWT", resp.Cookies()[0].Name) assert.NotEqual(t, "", resp.Cookies()[0].Value, "token set") assert.Equal(t, 2678400, resp.Cookies()[0].MaxAge) diff --git a/provider/telegram_test.go b/provider/telegram_test.go index f56839bc..988f0ec8 100644 --- a/provider/telegram_test.go +++ b/provider/telegram_test.go @@ -89,7 +89,6 @@ func TestTelegramUnconfirmedRequest(t *testing.T) { func TestTelegramConfirmedRequest(t *testing.T) { var servedToken string - // is set when token becomes used, // no sync is required because only a single goroutine in TelegramHandler.Run() reads and writes it var tokenAlreadyUsed bool diff --git a/token/jwt.go b/token/jwt.go index 57687a63..d37291d7 100644 --- a/token/jwt.go +++ b/token/jwt.go @@ -337,6 +337,7 @@ func (j *Service) Reset(w http.ResponseWriter) { // checkAuds verifies if claims.Audience in the list of allowed by audReader func (j *Service) checkAuds(claims *Claims, audReader Audience) error { + // marshal the audience. if audReader == nil { // lack of any allowed means any return nil } diff --git a/token/jwt_test.go b/token/jwt_test.go index a5e8b558..5ea2b60c 100644 --- a/token/jwt_test.go +++ b/token/jwt_test.go @@ -31,9 +31,7 @@ var ( testJwtNonAudSign = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0X2F1ZF9vbmx5IiwiZXhwIjoyNzg5MTkxODIyLCJqdGkiOiJyYW5kb20gaWQiLCJpc3MiOiJyZW1hcms0MiIsIm5iZiI6MTUyNjg4NDIyMiwidXNlciI6eyJuYW1lIjoibmFtZTEiLCJpZCI6ImlkMSIsInBpY3R1cmUiOiJodHRwOi8vZXhhbXBsZS5jb20vcGljLnBuZyIsImlwIjoiMTI3LjAuMC4xIiwiZW1haWwiOiJtZUBleGFtcGxlLmNvbSIsImF0dHJzIjp7ImJvb2xhIjp0cnVlLCJzdHJhIjoic3RyYS12YWwifX0sImhhbmRzaGFrZSI6eyJzdGF0ZSI6IjEyMzQ1NiIsImZyb20iOiJmcm9tIiwiaWQiOiJteWlkLTEyMzQ1NiJ9fQ.kJc-U970h3j9riUhFLR9vN_YCUQwZ66tjk7zdC9OiUg" ) -var ( - days31 = time.Hour * 24 * 31 -) +var days31 = time.Hour * 24 * 31 const ( jwtCustomCookieName = "jc1" @@ -95,6 +93,11 @@ func TestJWT_Token(t *testing.T) { assert.NoError(t, err) assert.Equal(t, testJwtValid, res) + newClaims, _ := j.Parse(res) + assert.Equal(t, claims, newClaims) + fmt.Println(claims) + fmt.Println(newClaims) + j.SecretReader = nil _, err = j.Token(claims) assert.EqualError(t, err, "secret reader not defined")