fleet/orbit/pkg/packaging/windows_test.go
Dante Catalfamo 94f6127edc
Orbit for Windows ARM64 (#27882)
#27275 and #27274

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files)
for more information.
- [x] Added/updated automated tests
- [x] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [x] Make sure fleetd is compatible with the latest released version of
Fleet (see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/fleetd-development-and-release-strategy.md)).
- [x] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [x] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).

---------

Co-authored-by: Lucas Rodriguez <lucas@fleetdm.com>
2025-04-11 10:18:28 -04:00

112 lines
3.8 KiB
Go

package packaging
import (
"fmt"
"path/filepath"
"testing"
"time"
"github.com/fleetdm/fleet/v4/pkg/fleethttp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCreateVersionInfo(t *testing.T) {
manifestPath := filepath.Join(t.TempDir(), "somefile.json")
t.Run("invalid version parts", func(t *testing.T) {
parts := []string{"1", "a", "3", "c"}
result, err := createVersionInfo(parts, manifestPath)
require.ErrorContains(t, err, "error parsing version part")
require.Nil(t, result)
})
t.Run("creates a VersionInfo struct", func(t *testing.T) {
parts := []string{"1", "2", "3", "0"}
result, err := createVersionInfo(parts, manifestPath)
require.NoError(t, err)
require.NotNil(t, result)
require.Equal(t, result.FixedFileInfo.FileVersion.Major, 1)
require.Equal(t, result.FixedFileInfo.FileVersion.Minor, 2)
require.Equal(t, result.FixedFileInfo.FileVersion.Patch, 3)
require.Equal(t, result.FixedFileInfo.FileVersion.Build, 0)
require.Equal(t, result.FixedFileInfo.ProductVersion.Major, 1)
require.Equal(t, result.FixedFileInfo.ProductVersion.Minor, 2)
require.Equal(t, result.FixedFileInfo.ProductVersion.Patch, 3)
require.Equal(t, result.FixedFileInfo.ProductVersion.Build, 0)
require.Equal(t, result.FixedFileInfo.FileFlagsMask, "3f")
require.Equal(t, result.FixedFileInfo.FileFlags, "00")
require.Equal(t, result.FixedFileInfo.FileOS, "040004")
require.Equal(t, result.FixedFileInfo.FileType, "01")
require.Equal(t, result.FixedFileInfo.FileSubType, "00")
require.Equal(t, result.StringFileInfo.Comments, "Fleet osquery")
require.Equal(t, result.StringFileInfo.CompanyName, "Fleet Device Management (fleetdm.com)")
require.Equal(t, result.StringFileInfo.FileDescription, "Fleet osquery installer")
require.Equal(t, result.StringFileInfo.FileVersion, "1.2.3.0")
require.Equal(t, result.StringFileInfo.LegalCopyright, fmt.Sprintf("%d Fleet Device Management Inc.", time.Now().Year()))
require.Equal(t, result.StringFileInfo.ProductName, "Fleet osquery")
require.Equal(t, result.StringFileInfo.ProductVersion, "1.2.3.0")
require.Equal(t, result.ManifestPath, manifestPath)
})
}
func TestWriteResourceSyso(t *testing.T) {
t.Run("removes intermediary manifest.xml file", func(t *testing.T) {
path := t.TempDir()
opt := Options{Version: "1.2.3", Architecture: ArchAmd64}
err := writeResourceSyso(opt, path)
require.NoError(t, err)
require.NoFileExists(t, filepath.Join(path, "manifest.xml"))
})
}
func TestSanitizeVersion(t *testing.T) {
testCases := []struct {
Version string
Parts []string
ErrorsOut bool
}{
{Version: "4.13.0", Parts: []string{"4", "13", "0", "0"}},
{Version: "4.13.0.1", Parts: []string{"4", "13", "0", "1"}},
// We need to support this form of semantic versioning (with pre-releases)
// to comply with semantic versioning required by goreleaser to allow building
// orbit pre-releases.
{Version: "4.13.0-1", Parts: []string{"4", "13", "0", "1"}},
{Version: "4.13.0-alpha", Parts: []string{"4", "13", "0", "alpha"}},
{Version: "4.13.0-", ErrorsOut: true},
{Version: "4.13.0.1.2", Parts: []string{"4", "13", "0", "1"}},
{Version: "4", ErrorsOut: true},
{Version: "4.13", ErrorsOut: true},
{Version: "bad bad", ErrorsOut: true},
}
for _, tC := range testCases {
result, err := SanitizeVersion(tC.Version)
if tC.ErrorsOut {
require.Error(t, err)
}
require.Equal(t, tC.Parts, result)
}
}
func TestDownloadAndExtractZip(t *testing.T) {
t.Parallel()
path := t.TempDir()
client := fleethttp.NewClient()
err := downloadAndExtractZip(client, wixDownload, path)
require.NoError(t, err)
assert.FileExists(t, filepath.Join(path, "heat.exe"))
assert.FileExists(t, filepath.Join(path, "candle.exe"))
assert.FileExists(t, filepath.Join(path, "light.exe"))
}