Skip to content

Commit

Permalink
Sync v1 with v2, comments and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal authored and umputun committed Dec 8, 2024
1 parent 8734b99 commit 88b3a84
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion provider/custom_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion provider/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions token/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 6 additions & 3 deletions token/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 88b3a84

Please sign in to comment.