fleet/orbit/pkg/update/update_test.go
Lucas Manuel Rodriguez f4d3159cc9
Fleetctl to package .app bundles for osquery (and changes for orbit to support them) (#4393)
* WIP

* WIP2

* Fix orbit and fleetctl tests

* Amend macos-app default

* Add some fixes

* Use fleetctl updates roots command

* Add more fixes to Updater

* Fixes to app publishing and downloading

* Add more changes to support fleetctl cross generation

* Amend comment

* Add pkg generation to ease testing

* Make more fixes

* Add changes entry

* Add legacy targets (until our TUF system exposes the new app)

* Fix fleetctl preview

* Fix bool flag

* Fix orbit logic for disabled-updates and dev-mode

* Fix TestPreview

* Remove constant and fix zip-slip attack (codeql)

* Return unknown error

* Fix updater's checkExec

* Add support for executable signing in init_tuf.sh

* Try only signing orbit

* Fix init_tuf.sh targets, macos-app only for osqueryd

* Specify GOARCH to support M1s

* Add workflow to generate osqueryd.app.tar.gz

* Use 5.2.2 on init_tuf.sh

* Add unit test for tar.gz target

* Use artifacts instead of releases

* Remove copy paste residue

* Trigger workflow on PR

* Fixes to ease handling of artifact

* Fix, do not use target name as dir

* Remove workaround
2022-03-15 16:04:12 -03:00

70 lines
2 KiB
Go

package update
import (
"os"
"path/filepath"
"testing"
"github.com/fleetdm/fleet/v4/orbit/pkg/constant"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestInitializeDirectories(t *testing.T) {
t.Parallel()
tmpDir := t.TempDir()
require.NoError(t, os.Chmod(tmpDir, constant.DefaultDirMode))
opt := DefaultOptions
opt.RootDirectory = tmpDir
updater := Updater{opt: opt}
err := updater.initializeDirectories()
require.NoError(t, err)
assertDir(t, filepath.Join(tmpDir, binDir))
}
func assertDir(t *testing.T, path string) {
info, err := os.Stat(path)
assert.NoError(t, err, "stat should succeed")
assert.True(t, info.IsDir())
}
func TestMakeRepoPath(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
version string
platform string
expected string
}{
{platform: "linux", name: "osqueryd", version: "4.6.0", expected: "osqueryd/linux/4.6.0/osqueryd"},
{platform: "linux", name: "osqueryd", version: "3.3.2", expected: "osqueryd/linux/3.3.2/osqueryd"},
{platform: "macos", name: "osqueryd", version: "4.6.0", expected: "osqueryd/macos/4.6.0/osqueryd"},
{platform: "macos", name: "osqueryd", version: "3.3.2", expected: "osqueryd/macos/3.3.2/osqueryd"},
{platform: "macos-app", name: "osqueryd", version: "3.3.2", expected: "osqueryd/macos-app/3.3.2/osqueryd.app.tar.gz"},
{platform: "windows", name: "osqueryd", version: "4.6.0", expected: "osqueryd/windows/4.6.0/osqueryd.exe"},
{platform: "windows", name: "osqueryd", version: "3.3.2", expected: "osqueryd/windows/3.3.2/osqueryd.exe"},
}
for _, tt := range testCases {
tt := tt
t.Run(tt.expected, func(t *testing.T) {
t.Parallel()
opt := DefaultOptions
osqueryd := opt.Targets[tt.name]
osqueryd.Platform = tt.platform
osqueryd.Channel = tt.version
osqueryd.TargetFile = filepath.Base(tt.expected)
opt.Targets[tt.name] = osqueryd
u := Updater{opt: opt}
repoPath, err := u.repoPath(tt.name)
require.NoError(t, err)
assert.Equal(t, tt.expected, repoPath)
})
}
}