feat(backend): jwt middleware, login with redis rate limit, /auth/me
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package redispkg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDisabledIsSafe(t *testing.T) {
|
||||
r := New("")
|
||||
ctx := context.Background()
|
||||
if _, ok := r.Get(ctx, "x"); ok {
|
||||
t.Fatal("disabled Get must miss")
|
||||
}
|
||||
r.Set(ctx, "x", "y", time.Second) // 不 panic
|
||||
if n := r.IncrWindow(ctx, "k", time.Second); n != 1 {
|
||||
t.Fatal("disabled IncrWindow must allow")
|
||||
}
|
||||
un, ok := r.Lock(ctx, "lk", time.Second)
|
||||
if !ok {
|
||||
t.Fatal("disabled Lock must always acquire")
|
||||
}
|
||||
un()
|
||||
}
|
||||
Reference in New Issue
Block a user