Support longer legacy token keys

This commit is contained in:
XiaoAI1024
2026-04-23 13:29:00 +08:00
parent 01c2e909a0
commit 2431efc01f
2 changed files with 26 additions and 1 deletions
+25
View File
@@ -38,6 +38,11 @@ type tokenKeyResponse struct {
Key string `json:"key"`
}
type sqliteColumnInfo struct {
Name string `gorm:"column:name"`
Type string `gorm:"column:type"`
}
func setupTokenControllerTestDB(t *testing.T) *gorm.DB {
t.Helper()
@@ -124,6 +129,26 @@ func decodeAPIResponse(t *testing.T, recorder *httptest.ResponseRecorder) tokenA
return response
}
func TestTokenAutoMigrateUsesVarchar128KeyColumn(t *testing.T) {
db := setupTokenControllerTestDB(t)
var columns []sqliteColumnInfo
if err := db.Raw("PRAGMA table_info(tokens)").Scan(&columns).Error; err != nil {
t.Fatalf("failed to inspect token table schema: %v", err)
}
for _, column := range columns {
if column.Name == "key" {
if strings.ToLower(column.Type) != "varchar(128)" {
t.Fatalf("expected key column type varchar(128), got %q", column.Type)
}
return
}
}
t.Fatal("key column not found in token table schema")
}
func TestGetAllTokensMasksKeyInResponse(t *testing.T) {
db := setupTokenControllerTestDB(t)
token := seedToken(t, db, 1, "list-token", "abcd1234efgh5678")