mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-15 02:45:22 +00:00
8fdffc94ca
Because the `git` module did not recognize SSH signed tags, those signatures ended up in the `notes` column of the `release` table. While future signatures will not end up there, Forgejo should clean up the old ones. This migration does just that: finds all releases that have an SSH signature, and removes those signatures, preserving the rest of the note (if any). While this may seem like an expensive operation, it's only done once, and even on the largest known Forgejo instance as of this writing (Codeberg), the number of affected rows are just over a hundred, a tiny amount all things considered. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
35 lines
864 B
Go
35 lines
864 B
Go
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package v1_22 //nolint
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/migrations/base"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_RemoveSSHSignaturesFromReleaseNotes(t *testing.T) {
|
|
// A reduced mock of the `repo_model.Release` struct.
|
|
type Release struct {
|
|
ID int64 `xorm:"pk autoincr"`
|
|
Note string `xorm:"TEXT"`
|
|
}
|
|
|
|
x, deferable := base.PrepareTestEnv(t, 0, new(Release))
|
|
defer deferable()
|
|
|
|
assert.NoError(t, RemoveSSHSignaturesFromReleaseNotes(x))
|
|
|
|
var releases []Release
|
|
err := x.Table("release").OrderBy("id ASC").Find(&releases)
|
|
assert.NoError(t, err)
|
|
assert.Len(t, releases, 3)
|
|
|
|
assert.Equal(t, "", releases[0].Note)
|
|
assert.Equal(t, "A message.\n", releases[1].Note)
|
|
assert.Equal(t, "no signature present here", releases[2].Note)
|
|
}
|