traefik / yaegi

Yaegi is Another Elegant Go Interpreter

Home Page:https://pkg.go.dev/github.com/traefik/yaegi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jwt-go exp not work because the type cast is nil

kongh opened this issue · comments

The following program sample.go triggers an unexpected result

import (
	"context"
	"fmt"
	"github.com/dgrijalva/jwt-go"
	"testing"
)

func TestJwtExpired(t *testing.T) {
	token := "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NTgzMDU3MzUsImlhdCI6MTY1ODMwNTcyNSwicGF5bG9hZCI6IntcImNpdHlJZFwiOlwiTVktRGVmYXVsdFwiLFwiZHJpdmVySWRcIjpcIkRJMTY1NTQzNzQ4MDU5MjExODAwMDE4Nzc4OTJcIixcImV4cGlyZVwiOlwiMjAyMi0wNy0yMFQwODoyODo1NVpcIn0ifQ.VigJx43NI4VDkA15kNukENLGriGourlLRnRP37O5t8X6eoxnU7DLzFpz4n1UFYH4GXfUdorb-slii8S3pe2tEQ"
	abc, err := jwt.Parse(token, func(token *jwt.Token) (interface{}, error) {
		return []byte("app_local"), nil
	})
	fmt.Println(abc)
	fmt.Println(abc, err)
}

Expected result

Token is expired

Got

nil

Yaegi Version

v0.13.0

Additional Notes

//
// I debug here, the exp is nil in the interceptor
func (m MapClaims) VerifyExpiresAt(cmp int64, req bool) bool {
switch exp := m["exp"].(type) {
case float64:
return verifyExp(int64(exp), cmp, req)
case json.Number:
v, _ := exp.Int64()
return verifyExp(v, cmp, req)
}
return req == false
}

// I modify like below this, and work fine for me
func (m MapClaims) VerifyExpiresAt(cmp int64, req bool) bool {
switch exp := m["exp"].(type) {
case float64:
return verifyExp(int64(exp), cmp, req)
case json.Number:
v, _ := exp.Int64()
return verifyExp(v, cmp, req)
default:
fmt.Println(fmt.Sprintf("jwt debug, type=%v", exp))
return verifyExp(int64(m["exp"].(float64)), cmp, req)
}
return req == false
}

Retested with current master head: 03ccda1
and it works now.