func TestWithParseAndValidateInBlackList(t *testing.T) { bl := &testRealBL{} jm, err := ctxjwt.NewService( ctxjwt.WithBlacklist(bl), ) assert.NoError(t, err) theToken, _, err := jm.GenerateToken(nil) bl.token = theToken assert.NoError(t, err) assert.NotEmpty(t, theToken) req, err := http.NewRequest("GET", "http://auth.xyz", nil) assert.NoError(t, err) ctxjwt.SetHeaderAuthorization(req, theToken) finalHandler := ctxhttp.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error { w.WriteHeader(http.StatusTeapot) return nil }) authHandler := jm.WithParseAndValidate()(finalHandler) wRec := httptest.NewRecorder() assert.NoError(t, authHandler.ServeHTTPContext(context.Background(), wRec, req)) assert.NotEqual(t, http.StatusTeapot, wRec.Code) assert.Equal(t, http.StatusUnauthorized, wRec.Code) }
// BenchmarkServeHTTPHMACSimpleBL-4 100000 16037 ns/op 3808 B/op 82 allocs/op Go 1.5.0 func BenchmarkServeHTTPHMACSimpleBL(b *testing.B) { bl := ctxjwt.NewSimpleMapBlackList() password := []byte(`Rump3lst!lzch3n`) bmServeHTTP(b, ctxjwt.WithPassword(password), ctxjwt.WithBlacklist(bl), ) b.Logf("Blacklist Items %d", bl.Len()) }
func TestLogout(t *testing.T) { tbl := &testBL{T: t} jm, err := ctxjwt.NewService( ctxjwt.WithBlacklist(tbl), ) assert.NoError(t, err) theToken, _, err := jm.GenerateToken(nil) assert.NoError(t, err) tk, err := jm.Parse(theToken) assert.NoError(t, err) assert.NotNil(t, tk) assert.Nil(t, jm.Logout(nil)) assert.Nil(t, jm.Logout(tk)) assert.Equal(t, int(time.Hour.Seconds()), 1+int(tbl.exp.Seconds())) assert.Equal(t, theToken, tbl.theToken) }