Artifact 124ec8a01bbac2481fb998b2adf6419f3de9dc4bb4c5f343d18494b5d47b9128:
- File
leaf/agent/notify/token_store_test.go
— part of check-in
[eda7960b81]
at
2026-04-23 19:23:42
on branch trunk
— rename module to github.com/danmestas/EdgeSync
Fix the case-sensitive module path to match the actual GitHub repo URL (danmestas/EdgeSync). Remove tracked leaf/leaf binary and ignore .claude/skills/ scratchpad dirs. (user: [email protected], size: 1799) [annotate] [blame] [check-ins using] [more...]
package notify import ( "testing" "time" _ "github.com/danmestas/libfossil/db/driver/modernc" ) func TestPendingTokenLifecycle(t *testing.T) { r := createTestRepo(t) tok, err := GenerateToken() if err != nil { t.Fatal(err) } // Store the token. err = StorePendingToken(r, PendingToken{ TokenHash: HashToken(tok), DeviceName: "dan-iphone", CreatedAt: time.Now().UTC(), ExpiresAt: time.Now().UTC().Add(10 * time.Minute), }) if err != nil { t.Fatal(err) } // Validate with correct token. pt, err := ValidateToken(r, tok) if err != nil { t.Fatal(err) } if pt.DeviceName != "dan-iphone" { t.Errorf("device name = %q", pt.DeviceName) } // Token is consumed — second validation fails. _, err = ValidateToken(r, tok) if err == nil { t.Error("expected error: token already consumed") } } func TestExpiredTokenRejected(t *testing.T) { r := createTestRepo(t) tok, err := GenerateToken() if err != nil { t.Fatal(err) } err = StorePendingToken(r, PendingToken{ TokenHash: HashToken(tok), DeviceName: "dan-iphone", CreatedAt: time.Now().UTC().Add(-20 * time.Minute), ExpiresAt: time.Now().UTC().Add(-10 * time.Minute), // already expired }) if err != nil { t.Fatal(err) } _, err = ValidateToken(r, tok) if err == nil { t.Error("expected error for expired token") } } func TestCreatePairingToken(t *testing.T) { r := createTestRepo(t) tok, err := CreatePairingToken(r, "test-device") if err != nil { t.Fatal(err) } // Token should be in XXXX-XXXX-XXXX format. if len(tok) != 14 { t.Errorf("token length = %d, want 14", len(tok)) } // Should be validatable. pt, err := ValidateToken(r, tok) if err != nil { t.Fatal(err) } if pt.DeviceName != "test-device" { t.Errorf("device name = %q", pt.DeviceName) } }