30 lines
812 B
Go
30 lines
812 B
Go
package deviceauth
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"os"
|
||
|
|
"testing"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/redis/go-redis/v9"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestRedisReplayGuardClaimsNonceOnce(t *testing.T) {
|
||
|
|
address := os.Getenv("TEST_REDIS_ADDR")
|
||
|
|
if address == "" {
|
||
|
|
t.Skip("TEST_REDIS_ADDR is not set")
|
||
|
|
}
|
||
|
|
client := redis.NewClient(&redis.Options{Addr: address})
|
||
|
|
defer client.Close()
|
||
|
|
guard := NewRedisReplayGuard(client, "voice-platform-test")
|
||
|
|
nonce := time.Now().UTC().Format("20060102T150405.000000000")
|
||
|
|
claimed, err := guard.Claim(context.Background(), "device-test", nonce, time.Minute)
|
||
|
|
if err != nil || !claimed {
|
||
|
|
t.Fatalf("first claim = %v, err = %v", claimed, err)
|
||
|
|
}
|
||
|
|
claimed, err = guard.Claim(context.Background(), "device-test", nonce, time.Minute)
|
||
|
|
if err != nil || claimed {
|
||
|
|
t.Fatalf("second claim = %v, err = %v", claimed, err)
|
||
|
|
}
|
||
|
|
}
|