package provider import ( "context" "encoding/base64" "encoding/json" "errors" "path/filepath" "strings" "testing" "time" ) func TestExpiredCredentialsNeedSignIn(t *testing.T) { for _, raw := range []string{`{"claudeAiOauth":{"expiresAt":1}}`, expiredLoginFixture()} { if !credentialsExpired([]byte(raw), time.Now()) { t.Fatal("expired token not detected") } } if credentialsExpired([]byte(`{"claudeAiOauth":{"expiresAt":4102444800000}}`), time.Now()) { t.Fatal("valid token expired") } } func TestExpiredLeaseRefusesDispatch(t *testing.T) { b, r := accountFixture(t) lease := openFixture(t, b, r) preflightFixture(t, lease) writeFake(t, filepath.Join(b.Home, "auth.json"), expiredLoginFixture()) if err := lease.BeginTurn(context.Background()); !errors.Is(err, ErrAccountMaintenance) { t.Fatal("expired account did not require maintenance", err) } if _, err := openAccount(context.Background(), b, r); !errors.Is(err, ErrAccountBusy) { t.Fatal("active account lock lost", err) } } // Construct an unsigned expired fixture in memory, without a token literal. func expiredLoginFixture() string { claims := base64.RawURLEncoding.EncodeToString([]byte(`{"exp":1}`)) token := strings.Join([]string{"e30", claims, "fixture"}, ".") raw, _ := json.Marshal(map[string]any{"tokens": map[string]string{"access_token": token}}) return string(raw) }