BlueGit

timfa bluegit

Files

bluegit / internal / store / token_test.go

token_test.go

fix: compacte token- en SSH-knoppen op /settings
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
25146e27 History
token_test.go 774 B Download Raw
1package store
2
3import (
4 "context"
5 "testing"
6 "time"
7)
8
9func TestListTokensReadsExpiry(t *testing.T) {
10 s := openTest(t)
11 ctx := context.Background()
12 user, err := s.UpsertUser(ctx, 1, "tim", "", false)
13 if err != nil {
14 t.Fatal(err)
15 }
16 if _, err := s.CreateToken(ctx, user.ID, "laptop"); err != nil {
17 t.Fatal(err)
18 }
19 when := time.Date(2026, 12, 1, 0, 0, 0, 0, time.UTC)
20 if _, err := s.db.ExecContext(ctx, `UPDATE access_tokens SET expires_at = ? WHERE user_id = ?`, when.Format(time.RFC3339), user.ID); err != nil {
21 t.Fatal(err)
22 }
23 list, err := s.ListTokens(ctx, user.ID)
24 if err != nil || len(list) != 1 {
25 t.Fatalf("%v %+v", err, list)
26 }
27 if !list[0].ExpiresAt.Equal(when) || list[0].Prefix == "" || list[0].Name != "laptop" {
28 t.Fatalf("%+v", list[0])
29 }
30}