f21fa5b5e8
Commilitia Drop:自托管的跨设备剪贴板同步与点对点文件传输。 - 后端 Go(chi / SQLite WAL / SSE Hub / WebRTC signaling + 状态机 / Relay ring buffer),编译进单个 distroless 镜像(前端 go:embed)。 - 前端 React + TanStack Router + Zustand,自实现 SSE + WebRTC P2P,NAT 受阻时回退服务端中继;聚珍(Juzhen)CJK 综合排版。 - 桌面端 Wails v2(macOS / Windows),瘦客户端复用 web。 - 鉴权 OIDC PKCE(自建 Casdoor 等),refresh_token 信封加密存系统密钥库;iOS Shortcut 用 HS256 scoped token。 架构文档与变更记录见 docs 分支(PROJECT_BRIEF / FRONTEND_DESIGN / CHANGELOG)。 本次为公开发布初始提交:完整开发历史(含部署细节)留存于私有归档,公开仓库自此干净起步。
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package jwtauth
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"commilitia.net/cdrop/internal/db"
|
|
)
|
|
|
|
func openTestQueries(t *testing.T) *db.Queries {
|
|
t.Helper()
|
|
dbPath := filepath.Join(t.TempDir(), "x.db")
|
|
conn, err := db.Open(dbPath)
|
|
if err != nil {
|
|
t.Fatalf("open: %v", err)
|
|
}
|
|
t.Cleanup(func() { _ = conn.Close() })
|
|
if err := db.Bootstrap(context.Background(), conn); err != nil {
|
|
t.Fatalf("bootstrap: %v", err)
|
|
}
|
|
return db.New(conn)
|
|
}
|
|
|
|
func TestDeleteStaleDevices_RemovesOnlyOld(t *testing.T) {
|
|
q := openTestQueries(t)
|
|
ctx := context.Background()
|
|
|
|
now := time.Now()
|
|
old := now.Add(-200 * time.Hour)
|
|
fresh := now.Add(-1 * time.Hour)
|
|
|
|
upsert := func(name string, ts time.Time) {
|
|
if err := q.UpsertDevice(ctx, db.UpsertDeviceParams{
|
|
UserID: "alice", Name: name, Type: "browser", LastSeen: ts.Unix(),
|
|
}); err != nil {
|
|
t.Fatalf("upsert %s: %v", name, err)
|
|
}
|
|
}
|
|
upsert("old-device", old)
|
|
upsert("fresh-device", fresh)
|
|
|
|
// Cutoff = "older than 196 hours from now" mimics RunDeviceSweeper math.
|
|
cutoff := now.Add(-196 * time.Hour).Unix()
|
|
if err := q.DeleteStaleDevices(ctx, cutoff); err != nil {
|
|
t.Fatalf("delete: %v", err)
|
|
}
|
|
|
|
devs, _ := q.ListDevicesByUser(ctx, "alice")
|
|
got := map[string]bool{}
|
|
for _, d := range devs {
|
|
got[d.Name] = true
|
|
}
|
|
if got["old-device"] {
|
|
t.Error("old-device should have been swept")
|
|
}
|
|
if !got["fresh-device"] {
|
|
t.Error("fresh-device should remain")
|
|
}
|
|
}
|