diff --git a/backend/pkg/api/admin/packages.go b/backend/pkg/api/admin/packages.go index 886fcb584..d7af0a057 100644 --- a/backend/pkg/api/admin/packages.go +++ b/backend/pkg/api/admin/packages.go @@ -336,6 +336,10 @@ func (s *Service) DeletePackage(pkgID string) error { // called, the package has already been updated except for the channels // blacklist, that may happen here if needed. func (s *Service) updatePackageBlacklistedChannels(tx *sqlx.Tx, pkg *types.Package, oldPkg *types.Package) error { + if err := s.checkMatchingArch(pkg.ChannelsBlacklist, pkg.Arch); err != nil { + return err + } + pkgUpdated := oldPkg newChannelsBlacklist := make(map[string]struct{}, len(pkg.ChannelsBlacklist)) diff --git a/backend/pkg/api/packages_test.go b/backend/pkg/api/packages_test.go index 2f88e5c0d..7d3702f27 100644 --- a/backend/pkg/api/packages_test.go +++ b/backend/pkg/api/packages_test.go @@ -135,6 +135,41 @@ func TestUpdatePackage(t *testing.T) { assert.Equal(t, types.ArchAll, pkg.Arch) } +func TestUpdatePackageArchMismatch(t *testing.T) { + a := newForTest(t) + defer a.Close() + as := adminSvc(a) + + tTeam, _ := as.AddTeam(&types.Team{Name: "test_team"}) + tApp, _ := as.AddApp(&types.Application{Name: "test_app", TeamID: tTeam.ID}) + tChannel, _ := as.AddChannel(&types.Channel{ + Name: "arm_channel", + Color: "blue", + ApplicationID: tApp.ID, + Arch: types.ArchAArch64, + }) + + tPkg, err := as.AddPackage(&types.Package{ + Type: types.PkgTypeOther, + URL: "http://sample.url/pkg", + Version: "1.0.0", + ApplicationID: tApp.ID, + Arch: types.ArchAMD64, + }) + assert.NoError(t, err) + + err = as.UpdatePackage(&types.Package{ + ID: tPkg.ID, + Type: types.PkgTypeOther, + URL: "http://sample.url/pkg", + Version: "1.0.1", + ApplicationID: tApp.ID, + Arch: types.ArchAMD64, + ChannelsBlacklist: []string{tChannel.ID}, + }) + assert.Equal(t, types.ErrArchMismatch, err) +} + func TestUpdatePackageFlatcar(t *testing.T) { a := newForTest(t) defer a.Close()