Release attachments must belong to the intended repo (#36347)

This commit is contained in:
Lunny Xiao
2026-01-14 11:37:53 -08:00
committed by GitHub
parent 7b5de594cd
commit 14e8c9b767
9 changed files with 122 additions and 32 deletions
+6 -10
View File
@@ -16,28 +16,24 @@ import (
"github.com/stretchr/testify/require"
)
func TestLinkedRepository(t *testing.T) {
func TestAttachLinkedType(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
testCases := []struct {
name string
attachID int64
expectedRepo *repo_model.Repository
expectedUnitType unit.Type
}{
{"LinkedIssue", 1, &repo_model.Repository{ID: 1}, unit.TypeIssues},
{"LinkedComment", 3, &repo_model.Repository{ID: 1}, unit.TypePullRequests},
{"LinkedRelease", 9, &repo_model.Repository{ID: 1}, unit.TypeReleases},
{"Notlinked", 10, nil, -1},
{"LinkedIssue", 1, unit.TypeIssues},
{"LinkedComment", 3, unit.TypePullRequests},
{"LinkedRelease", 9, unit.TypeReleases},
{"Notlinked", 10, unit.TypeInvalid},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
attach, err := repo_model.GetAttachmentByID(t.Context(), tc.attachID)
assert.NoError(t, err)
repo, unitType, err := LinkedRepository(t.Context(), attach)
unitType, err := GetAttachmentLinkedType(t.Context(), attach)
assert.NoError(t, err)
if tc.expectedRepo != nil {
assert.Equal(t, tc.expectedRepo.ID, repo.ID)
}
assert.Equal(t, tc.expectedUnitType, unitType)
})
}