mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
Update installer extensions based on file contents as part of uninstall script migration cron (#22060)
# Checklist for submitter - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [x] Added/updated tests Automated integration tests fully exercise this change (and have been revised to assert that this works correctly).
This commit is contained in:
parent
a2c6de65d6
commit
463b0048fc
3 changed files with 22 additions and 6 deletions
|
|
@ -1223,7 +1223,7 @@ func UninstallSoftwareMigration(
|
|||
// Update $PACKAGE_ID in uninstall script
|
||||
preProcessUninstallScript(&payload)
|
||||
|
||||
// Update the package_id in the software installer and the uninstall script
|
||||
// Update the package_id and extension in the software installer and the uninstall script
|
||||
if err := ds.UpdateSoftwareInstallerWithoutPackageIDs(ctx, id, payload); err != nil {
|
||||
return ctxerr.Wrap(ctx, err, "updating package_id in software installer")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -959,10 +959,10 @@ func (ds *Datastore) UpdateSoftwareInstallerWithoutPackageIDs(ctx context.Contex
|
|||
}
|
||||
query := `
|
||||
UPDATE software_installers
|
||||
SET package_ids = ?, uninstall_script_content_id = ?
|
||||
SET package_ids = ?, uninstall_script_content_id = ?, extension = ?
|
||||
WHERE id = ?
|
||||
`
|
||||
_, err = ds.writer(ctx).ExecContext(ctx, query, strings.Join(payload.PackageIDs, ","), uninstallScriptID, id)
|
||||
_, err = ds.writer(ctx).ExecContext(ctx, query, strings.Join(payload.PackageIDs, ","), uninstallScriptID, payload.Extension, id)
|
||||
if err != nil {
|
||||
return ctxerr.Wrap(ctx, err, "update software installer without package ID")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10584,14 +10584,22 @@ func (s *integrationEnterpriseTestSuite) TestSoftwareInstallerUploadDownloadAndD
|
|||
installerID, titleID := checkSoftwareInstaller(t, payload)
|
||||
|
||||
var origPackageIDs string
|
||||
// Update DB by clearing package id
|
||||
var origExtension string
|
||||
// Update DB by clearing package id and tweaking extension
|
||||
mysql.ExecAdhocSQL(t, s.ds, func(q sqlx.ExtContext) error {
|
||||
if err := sqlx.GetContext(context.Background(), q, &origPackageIDs, `SELECT package_ids FROM software_installers WHERE id = ?`,
|
||||
installerID); err != nil {
|
||||
return err
|
||||
}
|
||||
require.NotEmpty(t, origPackageIDs)
|
||||
if _, err = q.ExecContext(context.Background(), `UPDATE software_installers SET package_ids = '' WHERE id = ?`,
|
||||
|
||||
if err := sqlx.GetContext(context.Background(), q, &origExtension, `SELECT extension FROM software_installers WHERE id = ?`,
|
||||
installerID); err != nil {
|
||||
return err
|
||||
}
|
||||
require.NotEmpty(t, origExtension)
|
||||
|
||||
if _, err = q.ExecContext(context.Background(), `UPDATE software_installers SET package_ids = '', extension = 'rb' WHERE id = ?`,
|
||||
installerID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -10610,7 +10618,7 @@ func (s *integrationEnterpriseTestSuite) TestSoftwareInstallerUploadDownloadAndD
|
|||
err = eeservice.UninstallSoftwareMigration(context.Background(), s.ds, s.softwareInstallStore, logger)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Check package ID
|
||||
// Check package ID and extension
|
||||
mysql.ExecAdhocSQL(t, s.ds, func(q sqlx.ExtContext) error {
|
||||
var packageIDs string
|
||||
if err := sqlx.GetContext(context.Background(), q, &packageIDs, `SELECT package_ids FROM software_installers WHERE id = ?`,
|
||||
|
|
@ -10618,6 +10626,14 @@ func (s *integrationEnterpriseTestSuite) TestSoftwareInstallerUploadDownloadAndD
|
|||
return err
|
||||
}
|
||||
assert.Equal(t, origPackageIDs, packageIDs)
|
||||
|
||||
var extension string
|
||||
if err := sqlx.GetContext(context.Background(), q, &extension, `SELECT extension FROM software_installers WHERE id = ?`,
|
||||
installerID); err != nil {
|
||||
return err
|
||||
}
|
||||
assert.Equal(t, origExtension, extension)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue