45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package logic
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestParsePairKey(t *testing.T) {
|
|
did, aid, ok := parsePairKey("1:9:2:3", "1:")
|
|
if !ok || did != 9 || aid != 2 {
|
|
t.Fatalf("triple %+v %v %v", did, aid, ok)
|
|
}
|
|
did, aid, ok = parsePairKey("1:9:0", "1:")
|
|
if !ok || did != 9 || aid != 0 {
|
|
t.Fatalf("pair mode key %+v %v %v", did, aid, ok)
|
|
}
|
|
if _, _, ok := parsePairKey("x", "p:"); ok {
|
|
t.Fatal("bad key")
|
|
}
|
|
}
|
|
|
|
func TestRedisPairsDeleteAllOnDeviceNil(t *testing.T) {
|
|
p := NewRedisPairs(nil, "")
|
|
ctx := t.Context()
|
|
if err := p.DeleteAllOnDevice(ctx, 1, 1); err == nil {
|
|
t.Fatal("expected unavailable")
|
|
}
|
|
if _, err := p.ListByUser(ctx, 1); err == nil {
|
|
t.Fatal("expected list error")
|
|
}
|
|
}
|
|
|
|
func TestMemoryPairsDeleteAllOnDevicePairMode(t *testing.T) {
|
|
p := NewMemoryPairsMode(PairKeyPair)
|
|
ctx := t.Context()
|
|
_ = p.Put(ctx, 1, 9, 0, TokenPair{Access: "a", Refresh: "r"}, time.Minute)
|
|
if err := p.DeleteAllOnDevice(ctx, 1, 9); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := p.Get(ctx, 1, 9, 0)
|
|
if err != nil || got.Access != "" {
|
|
t.Fatalf("cleared %+v %v", got, err)
|
|
}
|
|
}
|