Repository: kolide/launcher

Issue:
Improve handling of downloaded binaries in tests
Right now, we download the osquery binary for a couple different tests (see `ee/tuf/ci/valid_executable.go`, `pkg/osquery/interactive/interactive_test.go`, `ee/agent/reset_test.go`, `pkg/osquery/runsimple/osqueryrunner_test.go`, `pkg/osquery/runtime/runtime_test.go`). This means six separate downloads of the osquery (`ee/tuf/ci/valid_executable.go` now downloads both an older version of osquery and latest nightly) -- and although these downloads go into the temp directory, they are not cleaned up by the tests.

We would like to achieve:

* Fewer downloads of osquery
* Cleanup of the osquery binary post-test run

Improvements:

- [ ] We should pick one place (maybe somewhere inside pkg/osquery) to hold the logic to download the osquery binary for tests, instead of duplicating it across all the files above.
- [ ] We should either A) reuse the osquery binary on different test runs (by standardizing the filepath name), or B) figure out how to remove the osquery binary after all tests in the given package have run.
- [ ] If we use option A), we should at least clean up the downloaded tarballs in the temp directory, leaving only the bare binary or app bundle.

A: We can standardize the filepath name so that when we re-run tests locally, we don't have to re-download osquery for each test run -- i.e., after you run tests, you will have 1-2 temporary directories holding binaries that will be re-used on subsequent test runs. If we choose this approach, we will probably want to add the osquery version to the filepath so that we _will_ download a new osquery when there's a new nightly available.

B: We can investigate removing the temporary directory holding the osquery binaries after all tests complete. Last I looked, Golang tests didn't have great support for this. If we want to do this, then I think we'd need to go back to using `TestMain` rather than `sync.OnceFunc`. This would mean still doing six separate osquery downloads for one full `make test` run, but would not leave behind any artifacts after test run.

Hints from issue comments:
@RebeccaMahany: We would like to go with option A

Solution patch:
diff --git a/cmd/launcher/launcher.go b/cmd/launcher/launcher.go
index 1ba31055..9e31ae7b 100644
--- a/cmd/launcher/launcher.go
+++ b/cmd/launcher/launcher.go
@@ -558,7 +558,6 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl
 			k,
 			metadataClient,
 			mirrorClient,
-			osqueryRunner,
 			tuf.WithOsqueryRestart(osqueryRunner.Restart),
 		)
 		if err != nil {
diff --git a/ee/tuf/autoupdate.go b/ee/tuf/autoupdate.go
index d4cd20f5..193de149 100644
--- a/ee/tuf/autoupdate.go
+++ b/ee/tuf/autoupdate.go
@@ -4,6 +4,7 @@
 package tuf
 
 import (
+	"bytes"
 	"context"
 	_ "embed"
 	"encoding/json"
@@ -18,6 +19,7 @@ import (
 	"path/filepath"
 	"runtime"
 	"slices"
+	"strings"
 	"sync"
 	"sync/atomic"
 	"time"
@@ -26,6 +28,7 @@ import (
 	"github.com/kolide/launcher/ee/agent/flags/keys"
 	"github.com/kolide/launcher/ee/agent/types"
 	"github.com/kolide/launcher/ee/observability"
+	"github.com/kolide/launcher/pkg/osquery/runsimple"
 	client "github.com/theupdateframework/go-tuf/client"
 	filejsonstore "github.com/theupdateframework/go-tuf/client/filejsonstore"
 	"github.com/theupdateframework/go-tuf/data"
@@ -80,27 +83,22 @@ type librarian interface {
 	TidyLibrary(binary autoupdatableBinary, currentVersion string)
 }
 
-type querier interface {
-	Query(query string) ([]map[string]string, error)
-}
-
 type TufAutoupdater struct {
-	metadataClient         *client.Client
-	libraryManager         librarian
-	osquerier              querier // used to query for current running osquery version
-	osquerierRetryInterval time.Duration
-	knapsack               types.Knapsack
-	updateChannel          string
-	pinnedVersions         map[autoupdatableBinary]string        // maps the binaries to their pinned versions
-	pinnedVersionGetters   map[autoupdatableBinary]func() string // maps the binaries to the knapsack function to retrieve updated pinned versions
-	initialDelayEnd        time.Time
-	updateLock             *sync.Mutex
-	interrupt              chan struct{}
-	interrupted            atomic.Bool
-	signalRestart          chan error
-	slogger                *slog.Logger
-	restartFuncs           map[autoupdatableBinary]func(context.Context) error
-	calculatedSplayDelay   *atomic.Int64 // the randomly selected delay within the download splay window
+	metadataClient       *client.Client
+	libraryManager       librarian
+	osqueryTimeout       time.Duration
+	knapsack             types.Knapsack
+	updateChannel        string
+	pinnedVersions       map[autoupdatableBinary]string        // maps the binaries to their pinned versions
+	pinnedVersionGetters map[autoupdatableBinary]func() string // maps the binaries to the knapsack function to retrieve updated pinned versions
+	initialDelayEnd      time.Time
+	updateLock           *sync.Mutex
+	interrupt            chan struct{}
+	interrupted          atomic.Bool
+	signalRestart        chan error
+	slogger              *slog.Logger
+	restartFuncs         map[autoupdatableBinary]func(context.Context) error
+	calculatedSplayDelay *atomic.Int64 // the randomly selected delay within the download splay window
 }
 
 type TufAutoupdaterOption func(*TufAutoupdater)
@@ -115,7 +113,7 @@ func WithOsqueryRestart(restart func(context.Context) error) TufAutoupdaterOptio
 }
 
 func NewTufAutoupdater(ctx context.Context, k types.Knapsack, metadataHttpClient *http.Client, mirrorHttpClient *http.Client,
-	osquerier querier, opts ...TufAutoupdaterOption) (*TufAutoupdater, error) {
+	opts ...TufAutoupdaterOption) (*TufAutoupdater, error) {
 	ctx, span := observability.StartSpan(ctx)
 	defer span.End()
 
@@ -132,13 +130,12 @@ func NewTufAutoupdater(ctx context.Context, k types.Knapsack, metadataHttpClient
 			binaryLauncher: func() string { return k.PinnedLauncherVersion() },
 			binaryOsqueryd: func() string { return k.PinnedOsquerydVersion() },
 		},
-		initialDelayEnd:        time.Now().Add(k.AutoupdateInitialDelay()),
-		updateLock:             &sync.Mutex{},
-		osquerier:              osquerier,
-		osquerierRetryInterval: 30 * time.Second,
-		slogger:                k.Slogger().With("component", "tuf_autoupdater"),
-		restartFuncs:           make(map[autoupdatableBinary]func(context.Context) error),
-		calculatedSplayDelay:   &atomic.Int64{},
+		initialDelayEnd:      time.Now().Add(k.AutoupdateInitialDelay()),
+		updateLock:           &sync.Mutex{},
+		osqueryTimeout:       30 * time.Second,
+		slogger:              k.Slogger().With("component", "tuf_autoupdater"),
+		restartFuncs:         make(map[autoupdatableBinary]func(context.Context) error),
+		calculatedSplayDelay: &atomic.Int64{},
 	}
 
 	for _, opt := range opts {
@@ -460,32 +457,30 @@ func (ta *TufAutoupdater) currentRunningVersion(binary autoupdatableBinary) (str
 		}
 		return launcherVersion, nil
 	case binaryOsqueryd:
-		// first verify that the osqueryd binary exists. if it doesn't, there's no reason to wait
-		// for initialization below
-		if ta.knapsack != nil {
-			latestOsqdPath := ta.knapsack.LatestOsquerydPath(context.TODO())
-			if _, statErr := os.Stat(latestOsqdPath); os.IsNotExist(statErr) {
-				return "", fmt.Errorf("finding current running version: osqueryd binary does not exist at `%s`", latestOsqdPath)
-			}
+		// Query via runsimple instead of client to avoid any socket contention
+		ctx, cancel := context.WithTimeout(context.Background(), ta.osqueryTimeout)
+		defer cancel()
+
+		var output bytes.Buffer
+		osquerydPath := ta.knapsack.LatestOsquerydPath(ctx)
+		osqVersionProc, err := runsimple.NewOsqueryProcess(osquerydPath, runsimple.WithStdout(&output))
+		if err != nil {
+			return "", fmt.Errorf("creating runsimple process to query for osqueryd version: %w", err)
 		}
 
-		// The osqueryd client may not have initialized yet, so retry the version
-		// check a couple times before giving up
-		osquerydVersionCheckRetries := 5
-		var err error
-		for i := 0; i < osquerydVersionCheckRetries; i += 1 {
-			var resp []map[string]string
-			resp, err = ta.osquerier.Query("SELECT version FROM osquery_info;")
-			if err == nil && len(resp) > 0 {
-				if osquerydVersion, ok := resp[0]["version"]; ok {
-					return osquerydVersion, nil
-				}
-			}
-			err = fmt.Errorf("error querying for osquery_info: %w; rows returned: %d", err, len(resp))
+		if err := osqVersionProc.RunVersion(ctx); err != nil {
+			return "", fmt.Errorf("running runsimple to query for osqueryd version: %w", err)
+		}
 
-			time.Sleep(ta.osquerierRetryInterval)
+		// Output looks like `osquery version x.y.z`, so split on `version` and return the last part of the string
+		outputStr := strings.TrimSpace(output.String())
+		parts := strings.SplitAfter(outputStr, "version")
+		if len(parts) < 2 {
+			return "", fmt.Errorf("malformed osqueryd version output %s", outputStr)
 		}
-		return "", err
+		osquerydVersion := strings.TrimSpace(parts[len(parts)-1])
+
+		return osquerydVersion, nil
 	default:
 		return "", fmt.Errorf("cannot determine current running version for unexpected binary %s", binary)
 	}
diff --git a/ee/tuf/ci/valid_executable.go b/ee/tuf/ci/valid_executable.go
index d50dbde6..58bb5fe7 100644
--- a/ee/tuf/ci/valid_executable.go
+++ b/ee/tuf/ci/valid_executable.go
@@ -71,3 +71,57 @@ func CopyBinary(t *testing.T, executablePath string) {
 	require.NoError(t, os.MkdirAll(filepath.Dir(executablePath), 0755))
 	require.NoError(t, os.Symlink(testOsqueryBinary, executablePath))
 }
+
+var testOlderOsqueryBinary string
+
+const OlderBinaryVersion = "5.17.0"
+
+var downloadOlderOnceFunc = sync.OnceFunc(func() {
+	downloadDir, err := os.MkdirTemp("", "tufci")
+	if err != nil {
+		fmt.Printf("failed to make temp dir for test osquery binary: %v", err)
+		os.Exit(1) //nolint:forbidigo // Fine to use os.Exit inside tests
+	}
+
+	target := packaging.Target{}
+	if err := target.PlatformFromString(runtime.GOOS); err != nil {
+		fmt.Printf("error parsing platform %s: %v", runtime.GOOS, err)
+		os.RemoveAll(downloadDir) // explicit removal as defer will not run when os.Exit is called
+		os.Exit(1)                //nolint:forbidigo // Fine to use os.Exit inside tests
+	}
+	target.Arch = packaging.ArchFlavor(runtime.GOARCH)
+	if runtime.GOOS == "darwin" {
+		target.Arch = packaging.Universal
+	}
+
+	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+	defer cancel()
+
+	// Hardcode an older version of osquery
+	dlPath, err := packaging.FetchBinary(ctx, downloadDir, "osqueryd", target.PlatformBinaryName("osqueryd"), OlderBinaryVersion, target)
+	if err != nil {
+		fmt.Printf("error fetching binary osqueryd binary: %v", err)
+		cancel()                  // explicit cancel as defer will not run when os.Exit is called
+		os.RemoveAll(downloadDir) // explicit removal as defer will not run when os.Exit is called
+		os.Exit(1)                //nolint:forbidigo // Fine to use os.Exit inside tests
+	}
+
+	testOlderOsqueryBinary = filepath.Join(downloadDir, filepath.Base(dlPath))
+	if runtime.GOOS == "windows" {
+		testOlderOsqueryBinary += ".exe"
+	}
+
+	if err := fsutil.CopyFile(dlPath, testOlderOsqueryBinary); err != nil {
+		fmt.Printf("error copying osqueryd binary: %v", err)
+		cancel()                  // explicit cancel as defer will not run when os.Exit is called
+		os.RemoveAll(downloadDir) // explicit removal as defer will not run when os.Exit is called
+		os.Exit(1)                //nolint:forbidigo // Fine to use os.Exit inside tests
+	}
+})
+
+func CopyOlderBinary(t *testing.T, executablePath string) {
+	downloadOlderOnceFunc()
+
+	require.NoError(t, os.MkdirAll(filepath.Dir(executablePath), 0755))
+	require.NoError(t, os.Symlink(testOlderOsqueryBinary, executablePath))
+}



Test patch:
diff --git a/ee/tuf/autoupdate_test.go b/ee/tuf/autoupdate_test.go
index bda84019..88590afb 100644
--- a/ee/tuf/autoupdate_test.go
+++ b/ee/tuf/autoupdate_test.go
@@ -46,7 +46,7 @@ func TestNewTufAutoupdater(t *testing.T) {
 	mockKnapsack.On("PinnedOsquerydVersion").Return("")
 	mockKnapsack.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel, keys.PinnedLauncherVersion, keys.PinnedOsquerydVersion, keys.AutoupdateDownloadSplay).Return()
 
-	_, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, newMockQuerier(t))
+	_, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient)
 	require.NoError(t, err, "could not initialize new TUF autoupdater")
 
 	// Confirm we pulled all config items as expected
@@ -72,10 +72,13 @@ func TestExecute_launcherUpdate(t *testing.T) {
 	testRootDir := t.TempDir()
 	testReleaseVersion := "1.2.3"
 	tufServerUrl, rootJson := tufci.InitRemoteTufServer(t, testReleaseVersion)
-	// setup fake osqueryd binary to mock file existence for currentRunningVersion
-	fakeOsqBinaryPath := executableLocation(testRootDir, "osqueryd")
-	_, err := os.Create(fakeOsqBinaryPath)
-	require.NoError(t, err, "unable to create fake osqueryd binary file for test setup")
+
+	// Set up osquery binary
+	osqBinaryPath := filepath.Join(t.TempDir(), "osqueryd")
+	if runtime.GOOS == "windows" {
+		osqBinaryPath += ".exe"
+	}
+	tufci.CopyOlderBinary(t, osqBinaryPath)
 
 	mockKnapsack := typesmocks.NewKnapsack(t)
 	mockKnapsack.On("RootDirectory").Return(testRootDir)
@@ -89,10 +92,9 @@ func TestExecute_launcherUpdate(t *testing.T) {
 	mockKnapsack.On("MirrorServerURL").Return("https://example.com")
 	mockKnapsack.On("LocalDevelopmentPath").Return("")
 	mockKnapsack.On("InModernStandby").Return(false)
-	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(fakeOsqBinaryPath)
+	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(osqBinaryPath)
 	mockKnapsack.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel, keys.PinnedLauncherVersion, keys.PinnedOsquerydVersion, keys.AutoupdateDownloadSplay).Return()
 	mockKnapsack.On("AutoupdateDownloadSplay").Return(0 * time.Second)
-	mockQuerier := newMockQuerier(t)
 
 	// Set logger so that we can capture output
 	var logBytes threadsafebuffer.ThreadSafeBuffer
@@ -100,7 +102,7 @@ func TestExecute_launcherUpdate(t *testing.T) {
 	mockKnapsack.On("Slogger").Return(slogger.Logger)
 
 	// Set up autoupdater
-	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, mockQuerier)
+	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient)
 	require.NoError(t, err, "could not initialize new TUF autoupdater")
 
 	// Update the metadata client with our test root JSON
@@ -118,8 +120,6 @@ func TestExecute_launcherUpdate(t *testing.T) {
 	mockLibraryManager := NewMocklibrarian(t)
 	autoupdater.libraryManager = mockLibraryManager
 	currentLauncherVersion := "" // cannot determine using version package in test
-	currentOsqueryVersion := "1.1.1"
-	mockQuerier.On("Query", mock.Anything).Return([]map[string]string{{"version": currentOsqueryVersion}}, nil)
 	mockLibraryManager.On("TidyLibrary", binaryOsqueryd, mock.Anything).Return().Once()
 
 	// Expect that we attempt to update the library
@@ -127,7 +127,7 @@ func TestExecute_launcherUpdate(t *testing.T) {
 	mockLibraryManager.On("Available", binaryOsqueryd, fmt.Sprintf("osqueryd-%s.tar.gz", testReleaseVersion)).Return(true).Maybe() // On subsequent iterations, no need to download again
 	mockLibraryManager.On("Available", binaryLauncher, fmt.Sprintf("launcher-%s.tar.gz", testReleaseVersion)).Return(false).Once()
 	mockLibraryManager.On("Available", binaryLauncher, fmt.Sprintf("launcher-%s.tar.gz", testReleaseVersion)).Return(true).Maybe() // On subsequent iterations, no need to download again
-	mockLibraryManager.On("AddToLibrary", binaryOsqueryd, currentOsqueryVersion, fmt.Sprintf("osqueryd-%s.tar.gz", testReleaseVersion), osquerydMetadata).Return(nil).Once()
+	mockLibraryManager.On("AddToLibrary", binaryOsqueryd, tufci.OlderBinaryVersion, fmt.Sprintf("osqueryd-%s.tar.gz", testReleaseVersion), osquerydMetadata).Return(nil).Once()
 	mockLibraryManager.On("AddToLibrary", binaryLauncher, currentLauncherVersion, fmt.Sprintf("launcher-%s.tar.gz", testReleaseVersion), launcherMetadata).Return(nil).Once()
 
 	// Let the autoupdater run for a bit -- it will shut itself down after a launcher update
@@ -172,10 +172,13 @@ func TestExecute_osquerydUpdate(t *testing.T) {
 	testRootDir := t.TempDir()
 	testReleaseVersion := "1.2.3"
 	tufServerUrl, rootJson := tufci.InitRemoteTufServer(t, testReleaseVersion)
-	// setup fake osqueryd binary to mock file existence for currentRunningVersion
-	fakeOsqBinaryPath := executableLocation(testRootDir, "osqueryd")
-	_, err := os.Create(fakeOsqBinaryPath)
-	require.NoError(t, err, "unable to create fake osqueryd binary file for test setup")
+
+	// Set up osquery binary
+	osqBinaryPath := filepath.Join(t.TempDir(), "osqueryd")
+	if runtime.GOOS == "windows" {
+		osqBinaryPath += ".exe"
+	}
+	tufci.CopyOlderBinary(t, osqBinaryPath)
 
 	mockKnapsack := typesmocks.NewKnapsack(t)
 	mockKnapsack.On("RootDirectory").Return(testRootDir)
@@ -189,9 +192,8 @@ func TestExecute_osquerydUpdate(t *testing.T) {
 	mockKnapsack.On("MirrorServerURL").Return("https://example.com")
 	mockKnapsack.On("InModernStandby").Return(false)
 	mockKnapsack.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel, keys.PinnedLauncherVersion, keys.PinnedOsquerydVersion, keys.AutoupdateDownloadSplay).Return()
-	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(fakeOsqBinaryPath)
+	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(osqBinaryPath)
 	mockKnapsack.On("AutoupdateDownloadSplay").Return(0 * time.Second)
-	mockQuerier := newMockQuerier(t)
 
 	// Set logger so that we can capture output
 	var logBytes threadsafebuffer.ThreadSafeBuffer
@@ -199,8 +201,9 @@ func TestExecute_osquerydUpdate(t *testing.T) {
 	mockKnapsack.On("Slogger").Return(slogger.Logger)
 
 	// Set up autoupdater
-	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, mockQuerier, WithOsqueryRestart(func(context.Context) error { return nil }))
+	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, WithOsqueryRestart(func(context.Context) error { return nil }))
 	require.NoError(t, err, "could not initialize new TUF autoupdater")
+	autoupdater.osqueryTimeout = 5 * time.Second
 
 	// Update the metadata client with our test root JSON
 	require.NoError(t, autoupdater.metadataClient.Init(rootJson), "could not initialize metadata client with test root JSON")
@@ -214,18 +217,16 @@ func TestExecute_osquerydUpdate(t *testing.T) {
 	// Expect that we attempt to tidy the library first before running execute loop
 	mockLibraryManager := NewMocklibrarian(t)
 	autoupdater.libraryManager = mockLibraryManager
-	currentOsqueryVersion := "1.1.1"
-	mockQuerier.On("Query", mock.Anything).Return([]map[string]string{{"version": currentOsqueryVersion}}, nil)
 	mockLibraryManager.On("TidyLibrary", binaryOsqueryd, mock.Anything).Return().Once()
 
 	// Expect that we attempt to update the library
 	mockLibraryManager.On("Available", binaryOsqueryd, fmt.Sprintf("osqueryd-%s.tar.gz", testReleaseVersion)).Return(false)
 	mockLibraryManager.On("Available", binaryLauncher, fmt.Sprintf("launcher-%s.tar.gz", testReleaseVersion)).Return(true)
-	mockLibraryManager.On("AddToLibrary", binaryOsqueryd, currentOsqueryVersion, fmt.Sprintf("osqueryd-%s.tar.gz", testReleaseVersion), osquerydMetadata).Return(nil)
+	mockLibraryManager.On("AddToLibrary", binaryOsqueryd, tufci.OlderBinaryVersion, fmt.Sprintf("osqueryd-%s.tar.gz", testReleaseVersion), osquerydMetadata).Return(nil)
 
 	// Let the autoupdater run for a bit
 	go autoupdater.Execute()
-	time.Sleep(1000 * time.Millisecond)
+	time.Sleep(2 * autoupdater.osqueryTimeout)
 
 	// Assert expectation that we added the expected `testReleaseVersion` to the updates library
 	mockLibraryManager.AssertExpectations(t)
@@ -261,10 +262,13 @@ func TestExecute_downgrade(t *testing.T) {
 	testRootDir := t.TempDir()
 	testReleaseVersion := "3.22.9"
 	tufServerUrl, rootJson := tufci.InitRemoteTufServer(t, testReleaseVersion)
-	// setup fake osqueryd binary to mock file existence for currentRunningVersion
-	fakeOsqBinaryPath := executableLocation(testRootDir, "osqueryd")
-	_, err := os.Create(fakeOsqBinaryPath)
-	require.NoError(t, err, "unable to create fake osqueryd binary file for test setup")
+
+	// Set up osquery binary
+	osqBinaryPath := filepath.Join(t.TempDir(), "osqueryd")
+	if runtime.GOOS == "windows" {
+		osqBinaryPath += ".exe"
+	}
+	tufci.CopyBinary(t, osqBinaryPath)
 
 	mockKnapsack := typesmocks.NewKnapsack(t)
 	mockKnapsack.On("RootDirectory").Return(testRootDir)
@@ -278,9 +282,8 @@ func TestExecute_downgrade(t *testing.T) {
 	mockKnapsack.On("MirrorServerURL").Return("https://example.com")
 	mockKnapsack.On("InModernStandby").Return(false)
 	mockKnapsack.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel, keys.PinnedLauncherVersion, keys.PinnedOsquerydVersion, keys.AutoupdateDownloadSplay).Return()
-	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(fakeOsqBinaryPath)
+	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(osqBinaryPath)
 	mockKnapsack.On("AutoupdateDownloadSplay").Return(0 * time.Second)
-	mockQuerier := newMockQuerier(t)
 
 	// Set logger so that we can capture output
 	var logBytes threadsafebuffer.ThreadSafeBuffer
@@ -288,7 +291,7 @@ func TestExecute_downgrade(t *testing.T) {
 	mockKnapsack.On("Slogger").Return(slogger.Logger)
 
 	// Set up autoupdater
-	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, mockQuerier, WithOsqueryRestart(func(context.Context) error { return nil }))
+	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, WithOsqueryRestart(func(context.Context) error { return nil }))
 	require.NoError(t, err, "could not initialize new TUF autoupdater")
 
 	// Update the metadata client with our test root JSON
@@ -301,8 +304,6 @@ func TestExecute_downgrade(t *testing.T) {
 	// Expect that we attempt to tidy the library first before running execute loop
 	mockLibraryManager := NewMocklibrarian(t)
 	autoupdater.libraryManager = mockLibraryManager
-	currentOsqueryVersion := "4.0.0"
-	mockQuerier.On("Query", mock.Anything).Return([]map[string]string{{"version": currentOsqueryVersion}}, nil)
 	mockLibraryManager.On("TidyLibrary", binaryOsqueryd, mock.Anything).Return().Once()
 
 	// Expect that we do not attempt to update the library (i.e. the osquery update was previously downloaded)
@@ -367,7 +368,6 @@ func TestExecute_withInitialDelay(t *testing.T) {
 	mockKnapsack.On("PinnedLauncherVersion").Return("")
 	mockKnapsack.On("PinnedOsquerydVersion").Return("")
 	mockKnapsack.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel, keys.PinnedLauncherVersion, keys.PinnedOsquerydVersion, keys.AutoupdateDownloadSplay).Return()
-	mockQuerier := newMockQuerier(t)
 
 	// Set logger so that we can capture output
 	var logBytes threadsafebuffer.ThreadSafeBuffer
@@ -376,7 +376,7 @@ func TestExecute_withInitialDelay(t *testing.T) {
 
 	// Set up autoupdater
 	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient,
-		mockQuerier, WithOsqueryRestart(func(context.Context) error { return nil }))
+		WithOsqueryRestart(func(context.Context) error { return nil }))
 	require.NoError(t, err, "could not initialize new TUF autoupdater")
 
 	// Expect that we interrupt
@@ -414,10 +414,13 @@ func TestExecute_inModernStandby(t *testing.T) {
 	testRootDir := t.TempDir()
 	testReleaseVersion := "1.2.3"
 	tufServerUrl, _ := tufci.InitRemoteTufServer(t, testReleaseVersion)
-	// setup fake osqueryd binary to mock file existence for currentRunningVersion
-	fakeOsqBinaryPath := executableLocation(testRootDir, "osqueryd")
-	_, err := os.Create(fakeOsqBinaryPath)
-	require.NoError(t, err, "unable to create fake osqueryd binary file for test setup")
+
+	// Set up osquery binary
+	osqBinaryPath := filepath.Join(t.TempDir(), "osqueryd")
+	if runtime.GOOS == "windows" {
+		osqBinaryPath += ".exe"
+	}
+	tufci.CopyBinary(t, osqBinaryPath)
 
 	mockKnapsack := typesmocks.NewKnapsack(t)
 	mockKnapsack.On("RootDirectory").Return(testRootDir)
@@ -432,23 +435,23 @@ func TestExecute_inModernStandby(t *testing.T) {
 	mockKnapsack.On("InModernStandby").Return(true)
 	mockKnapsack.On("Slogger").Return(multislogger.NewNopLogger())
 	mockKnapsack.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel, keys.PinnedLauncherVersion, keys.PinnedOsquerydVersion, keys.AutoupdateDownloadSplay).Return()
-	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(fakeOsqBinaryPath)
-	mockQuerier := newMockQuerier(t)
+	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(osqBinaryPath)
 
 	// Set up autoupdater
 	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient,
-		mockQuerier, WithOsqueryRestart(func(context.Context) error { return nil }))
+		WithOsqueryRestart(func(context.Context) error { return nil }))
 	require.NoError(t, err, "could not initialize new TUF autoupdater")
+	autoupdater.osqueryTimeout = 5 * time.Second
 
 	// Set up library manager: we should expect to tidy the library on startup, but NOT add anything to it
 	mockLibraryManager := NewMocklibrarian(t)
 	autoupdater.libraryManager = mockLibraryManager
-	mockQuerier.On("Query", mock.Anything).Return([]map[string]string{{"version": "5.6.7"}}, nil)
 	mockLibraryManager.On("TidyLibrary", binaryOsqueryd, mock.Anything).Return().Once()
 
-	// Let the autoupdater run for less than the initial delay
+	// Let the autoupdater run for long enough to make it through tidying the library (which includes an osquery version query)
+	// and at least starting an autoupdate check
 	go autoupdater.Execute()
-	time.Sleep(300 * time.Millisecond)
+	time.Sleep(2 * autoupdater.osqueryTimeout)
 
 	// Shut down the autoupdater
 	autoupdater.Interrupt(errors.New("test error"))
@@ -473,10 +476,13 @@ func TestInterrupt_Multiple(t *testing.T) {
 	})
 
 	testRootDir := t.TempDir()
-	// setup fake osqueryd binary to mock file existence for currentRunningVersion
-	fakeOsqBinaryPath := executableLocation(testRootDir, "osqueryd")
-	_, err := os.Create(fakeOsqBinaryPath)
-	require.NoError(t, err, "unable to create fake osqueryd binary file for test setup")
+
+	// Set up osquery binary
+	osqBinaryPath := filepath.Join(t.TempDir(), "osqueryd")
+	if runtime.GOOS == "windows" {
+		osqBinaryPath += ".exe"
+	}
+	tufci.CopyBinary(t, osqBinaryPath)
 
 	mockKnapsack := typesmocks.NewKnapsack(t)
 	mockKnapsack.On("RootDirectory").Return(testRootDir)
@@ -495,23 +501,24 @@ func TestInterrupt_Multiple(t *testing.T) {
 	mockKnapsack.On("PinnedOsquerydVersion").Return("")
 	mockKnapsack.On("InModernStandby").Return(false)
 	mockKnapsack.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel, keys.PinnedLauncherVersion, keys.PinnedOsquerydVersion, keys.AutoupdateDownloadSplay).Return()
-	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(fakeOsqBinaryPath)
-	mockQuerier := newMockQuerier(t)
+	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(osqBinaryPath)
 
 	// Set up autoupdater
 	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient,
-		mockQuerier, WithOsqueryRestart(func(context.Context) error { return nil }))
+		WithOsqueryRestart(func(context.Context) error { return nil }))
 	require.NoError(t, err, "could not initialize new TUF autoupdater")
+	autoupdater.osqueryTimeout = 5 * time.Second
 
 	// Set up normal library and querier interactions
 	mockLibraryManager := NewMocklibrarian(t)
 	autoupdater.libraryManager = mockLibraryManager
 	mockLibraryManager.On("TidyLibrary", binaryOsqueryd, mock.Anything).Return().Once()
-	mockQuerier.On("Query", mock.Anything).Return([]map[string]string{{"version": "1.1.1"}}, nil)
 
-	// Let the autoupdater run for a bit
+	// Let the autoupdater run for long enough to make it through tidying the library (which includes an osquery version query)
+	// and at least starting an autoupdate check
 	go autoupdater.Execute()
-	time.Sleep(300 * time.Millisecond)
+	time.Sleep(2 * autoupdater.osqueryTimeout)
+
 	interruptStart := time.Now()
 	autoupdater.Interrupt(errors.New("test error"))
 
@@ -612,10 +619,13 @@ func TestDo(t *testing.T) {
 			testRootDir := t.TempDir()
 			testReleaseVersion := "2.2.3"
 			tufServerUrl, rootJson := tufci.InitRemoteTufServer(t, testReleaseVersion)
-			// setup fake osqueryd binary to mock file existence for currentRunningVersion
-			fakeOsqBinaryPath := executableLocation(testRootDir, "osqueryd")
-			_, err := os.Create(fakeOsqBinaryPath)
-			require.NoError(t, err, "unable to create fake osqueryd binary file for test setup")
+
+			// Set up osquery binary
+			osqBinaryPath := filepath.Join(t.TempDir(), "osqueryd")
+			if runtime.GOOS == "windows" {
+				osqBinaryPath += ".exe"
+			}
+			tufci.CopyOlderBinary(t, osqBinaryPath)
 
 			mockKnapsack := typesmocks.NewKnapsack(t)
 			mockKnapsack.On("RootDirectory").Return(testRootDir)
@@ -627,13 +637,12 @@ func TestDo(t *testing.T) {
 			mockKnapsack.On("UpdateDirectory").Return("")
 			mockKnapsack.On("MirrorServerURL").Return("https://example.com")
 			mockKnapsack.On("LocalDevelopmentPath").Return("").Maybe()
-			mockQuerier := newMockQuerier(t)
 			mockKnapsack.On("Slogger").Return(multislogger.NewNopLogger())
 			mockKnapsack.On("InModernStandby").Return(false)
 			mockKnapsack.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel, keys.PinnedLauncherVersion, keys.PinnedOsquerydVersion, keys.AutoupdateDownloadSplay).Return()
-			mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(fakeOsqBinaryPath).Maybe()
+			mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(osqBinaryPath).Maybe()
 			// Set up autoupdater
-			autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, mockQuerier, WithOsqueryRestart(func(context.Context) error { return nil }))
+			autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, WithOsqueryRestart(func(context.Context) error { return nil }))
 			require.NoError(t, err, "could not initialize new TUF autoupdater")
 
 			// Update the metadata client with our test root JSON
@@ -646,14 +655,10 @@ func TestDo(t *testing.T) {
 			// Expect that we attempt to update the library, only for the selected, valid binary/binaries
 			mockLibraryManager := NewMocklibrarian(t)
 			autoupdater.libraryManager = mockLibraryManager
-			currentOsqueryVersion := "1.1.1"
 			for _, b := range tt.updateData.BinariesToUpdate {
 				if b.Name != "osqueryd" && b.Name != "launcher" {
 					continue
 				}
-				if b.Name == "osqueryd" {
-					mockQuerier.On("Query", mock.Anything).Return([]map[string]string{{"version": currentOsqueryVersion}}, nil)
-				}
 
 				mockLibraryManager.On("Available", autoupdatableBinary(b.Name), fmt.Sprintf("%s-%s.tar.gz", b.Name, testReleaseVersion)).Return(false)
 				mockLibraryManager.On("AddToLibrary", autoupdatableBinary(b.Name), mock.Anything, mock.Anything, mock.Anything).Return(nil)
@@ -682,10 +687,13 @@ func TestDo_HandlesSimultaneousUpdates(t *testing.T) {
 	testRootDir := t.TempDir()
 	testReleaseVersion := "1.5.0"
 	tufServerUrl, rootJson := tufci.InitRemoteTufServer(t, testReleaseVersion)
-	// setup fake osqueryd binary to mock file existence for currentRunningVersion
-	fakeOsqBinaryPath := executableLocation(testRootDir, "osqueryd")
-	_, err := os.Create(fakeOsqBinaryPath)
-	require.NoError(t, err, "unable to create fake osqueryd binary file for test setup")
+
+	// Set up osquery binary
+	osqBinaryPath := filepath.Join(t.TempDir(), "osqueryd")
+	if runtime.GOOS == "windows" {
+		osqBinaryPath += ".exe"
+	}
+	tufci.CopyOlderBinary(t, osqBinaryPath)
 
 	mockKnapsack := typesmocks.NewKnapsack(t)
 	mockKnapsack.On("RootDirectory").Return(testRootDir)
@@ -700,14 +708,13 @@ func TestDo_HandlesSimultaneousUpdates(t *testing.T) {
 	mockKnapsack.On("MirrorServerURL").Return("https://example.com")
 	mockKnapsack.On("LocalDevelopmentPath").Return("")
 	mockKnapsack.On("InModernStandby").Return(false)
-	mockQuerier := newMockQuerier(t)
 	mockKnapsack.On("Slogger").Return(multislogger.NewNopLogger())
 	mockKnapsack.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel, keys.PinnedLauncherVersion, keys.PinnedOsquerydVersion, keys.AutoupdateDownloadSplay).Return()
-	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(fakeOsqBinaryPath)
+	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(osqBinaryPath)
 	mockKnapsack.On("AutoupdateDownloadSplay").Return(0 * time.Second)
 
 	// Set up autoupdater
-	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, mockQuerier, WithOsqueryRestart(func(context.Context) error { return nil }))
+	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, WithOsqueryRestart(func(context.Context) error { return nil }))
 	require.NoError(t, err, "could not initialize new TUF autoupdater")
 
 	// Update the metadata client with our test root JSON
@@ -720,8 +727,6 @@ func TestDo_HandlesSimultaneousUpdates(t *testing.T) {
 	// Expect that we attempt to tidy the library first before running execute loop
 	mockLibraryManager := NewMocklibrarian(t)
 	autoupdater.libraryManager = mockLibraryManager
-	currentOsqueryVersion := "1.1.1"
-	mockQuerier.On("Query", mock.Anything).Return([]map[string]string{{"version": currentOsqueryVersion}}, nil)
 	mockLibraryManager.On("TidyLibrary", binaryOsqueryd, mock.Anything).Return().Once()
 
 	// Expect that we attempt to update the library, only for the selected binary/binaries
@@ -766,10 +771,13 @@ func TestDo_WillNotExecuteDuringInitialDelay(t *testing.T) {
 	testRootDir := t.TempDir()
 	testReleaseVersion := "1.5.0"
 	tufServerUrl, rootJson := tufci.InitRemoteTufServer(t, testReleaseVersion)
-	// setup fake osqueryd binary to mock file existence for currentRunningVersion
-	fakeOsqBinaryPath := executableLocation(testRootDir, "osqueryd")
-	_, err := os.Create(fakeOsqBinaryPath)
-	require.NoError(t, err, "unable to create fake osqueryd binary file for test setup")
+
+	// Set up osquery binary
+	osqBinaryPath := filepath.Join(t.TempDir(), "osqueryd")
+	if runtime.GOOS == "windows" {
+		osqBinaryPath += ".exe"
+	}
+	tufci.CopyOlderBinary(t, osqBinaryPath)
 
 	mockKnapsack := typesmocks.NewKnapsack(t)
 	mockKnapsack.On("RootDirectory").Return(testRootDir)
@@ -783,15 +791,14 @@ func TestDo_WillNotExecuteDuringInitialDelay(t *testing.T) {
 	mockKnapsack.On("TufServerURL").Return(tufServerUrl)
 	mockKnapsack.On("UpdateDirectory").Return("")
 	mockKnapsack.On("MirrorServerURL").Return("https://example.com")
-	mockQuerier := newMockQuerier(t)
 	mockKnapsack.On("Slogger").Return(multislogger.NewNopLogger())
 	mockKnapsack.On("InModernStandby").Return(false)
 	mockKnapsack.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel, keys.PinnedLauncherVersion, keys.PinnedOsquerydVersion, keys.AutoupdateDownloadSplay).Return()
-	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(fakeOsqBinaryPath)
+	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(osqBinaryPath)
 	mockKnapsack.On("AutoupdateDownloadSplay").Return(0 * time.Second)
 
 	// Set up autoupdater
-	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, mockQuerier, WithOsqueryRestart(func(context.Context) error { return nil }))
+	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, WithOsqueryRestart(func(context.Context) error { return nil }))
 	require.NoError(t, err, "could not initialize new TUF autoupdater")
 
 	// Update the metadata client with our test root JSON
@@ -804,8 +811,6 @@ func TestDo_WillNotExecuteDuringInitialDelay(t *testing.T) {
 	// Set up expectations for Execute function: tidying library, checking for updates
 	mockLibraryManager := NewMocklibrarian(t)
 	autoupdater.libraryManager = mockLibraryManager
-	currentOsqueryVersion := "1.1.1"
-	mockQuerier.On("Query", mock.Anything).Return([]map[string]string{{"version": currentOsqueryVersion}}, nil)
 	mockLibraryManager.On("TidyLibrary", binaryOsqueryd, mock.Anything).Return().Once()
 	autoupdater.libraryManager = mockLibraryManager
 	for _, b := range binaries {
@@ -847,10 +852,13 @@ func TestFlagsChanged_UpdateChannelChanged(t *testing.T) {
 	testRootDir := t.TempDir()
 	testReleaseVersion := "2.2.3"
 	tufServerUrl, rootJson := tufci.InitRemoteTufServer(t, testReleaseVersion)
-	// setup fake osqueryd binary to mock file existence for currentRunningVersion
-	fakeOsqBinaryPath := executableLocation(testRootDir, "osqueryd")
-	_, err := os.Create(fakeOsqBinaryPath)
-	require.NoError(t, err, "unable to create fake osqueryd binary file for test setup")
+
+	// Set up osquery binary
+	osqBinaryPath := filepath.Join(t.TempDir(), "osqueryd")
+	if runtime.GOOS == "windows" {
+		osqBinaryPath += ".exe"
+	}
+	tufci.CopyOlderBinary(t, osqBinaryPath)
 
 	mockKnapsack := typesmocks.NewKnapsack(t)
 	mockKnapsack.On("RootDirectory").Return(testRootDir)
@@ -859,20 +867,19 @@ func TestFlagsChanged_UpdateChannelChanged(t *testing.T) {
 	mockKnapsack.On("MirrorServerURL").Return("https://example.com")
 	mockKnapsack.On("AutoupdateInitialDelay").Return(0 * time.Second)
 	mockKnapsack.On("LocalDevelopmentPath").Return("").Maybe()
-	mockQuerier := newMockQuerier(t)
 	mockKnapsack.On("Slogger").Return(multislogger.NewNopLogger())
 	mockKnapsack.On("PinnedLauncherVersion").Return("")
 	mockKnapsack.On("PinnedOsquerydVersion").Return("")
 	mockKnapsack.On("InModernStandby").Return(false)
 	mockKnapsack.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel, keys.PinnedLauncherVersion, keys.PinnedOsquerydVersion, keys.AutoupdateDownloadSplay).Return()
-	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(fakeOsqBinaryPath)
+	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(osqBinaryPath)
 
 	// Start out on beta channel, then swap to nightly
 	mockKnapsack.On("UpdateChannel").Return("beta").Once()
 	mockKnapsack.On("UpdateChannel").Return("nightly")
 
 	// Set up autoupdater
-	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, mockQuerier, WithOsqueryRestart(func(context.Context) error { return nil }))
+	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, WithOsqueryRestart(func(context.Context) error { return nil }))
 	require.NoError(t, err, "could not initialize new TUF autoupdater")
 	require.Equal(t, "beta", autoupdater.updateChannel)
 
@@ -886,8 +893,6 @@ func TestFlagsChanged_UpdateChannelChanged(t *testing.T) {
 	// Expect that we attempt to update the library
 	mockLibraryManager := NewMocklibrarian(t)
 	autoupdater.libraryManager = mockLibraryManager
-	currentOsqueryVersion := "1.1.1"
-	mockQuerier.On("Query", mock.Anything).Return([]map[string]string{{"version": currentOsqueryVersion}}, nil)
 	mockLibraryManager.On("Available", binaryOsqueryd, fmt.Sprintf("%s-%s.tar.gz", binaryOsqueryd, testReleaseVersion)).Return(false)
 	mockLibraryManager.On("AddToLibrary", binaryOsqueryd, mock.Anything, mock.Anything, mock.Anything).Return(nil)
 	mockLibraryManager.On("Available", binaryLauncher, fmt.Sprintf("%s-%s.tar.gz", binaryLauncher, testReleaseVersion)).Return(false)
@@ -912,10 +917,13 @@ func TestFlagsChanged_PinnedVersionChanged(t *testing.T) {
 	testRootDir := t.TempDir()
 	pinnedOsquerydVersion := "5.11.0"
 	tufServerUrl, rootJson := tufci.InitRemoteTufServer(t, pinnedOsquerydVersion)
-	// setup fake osqueryd binary to mock file existence for currentRunningVersion
-	fakeOsqBinaryPath := executableLocation(testRootDir, "osqueryd")
-	_, err := os.Create(fakeOsqBinaryPath)
-	require.NoError(t, err, "unable to create fake osqueryd binary file for test setup")
+
+	// Set up osquery binary
+	osqBinaryPath := filepath.Join(t.TempDir(), "osqueryd")
+	if runtime.GOOS == "windows" {
+		osqBinaryPath += ".exe"
+	}
+	tufci.CopyOlderBinary(t, osqBinaryPath)
 
 	mockKnapsack := typesmocks.NewKnapsack(t)
 	mockKnapsack.On("RootDirectory").Return(testRootDir)
@@ -924,20 +932,19 @@ func TestFlagsChanged_PinnedVersionChanged(t *testing.T) {
 	mockKnapsack.On("MirrorServerURL").Return("https://example.com")
 	mockKnapsack.On("LocalDevelopmentPath").Return("").Maybe()
 	mockKnapsack.On("AutoupdateInitialDelay").Return(0 * time.Second)
-	mockQuerier := newMockQuerier(t)
 	mockKnapsack.On("Slogger").Return(multislogger.NewNopLogger())
 	mockKnapsack.On("UpdateChannel").Return("nightly")
 	mockKnapsack.On("PinnedLauncherVersion").Return("")
 	mockKnapsack.On("InModernStandby").Return(false)
 	mockKnapsack.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel, keys.PinnedLauncherVersion, keys.PinnedOsquerydVersion, keys.AutoupdateDownloadSplay).Return()
-	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(fakeOsqBinaryPath)
+	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(osqBinaryPath)
 
 	// Start out with no pinned version, then set a pinned version
 	mockKnapsack.On("PinnedOsquerydVersion").Return("").Once()
 	mockKnapsack.On("PinnedOsquerydVersion").Return(pinnedOsquerydVersion)
 
 	// Set up autoupdater
-	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, mockQuerier, WithOsqueryRestart(func(context.Context) error { return nil }))
+	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, WithOsqueryRestart(func(context.Context) error { return nil }))
 	require.NoError(t, err, "could not initialize new TUF autoupdater")
 	require.Equal(t, "", autoupdater.pinnedVersions[binaryOsqueryd])
 
@@ -951,8 +958,6 @@ func TestFlagsChanged_PinnedVersionChanged(t *testing.T) {
 	// Expect that we attempt to update the library
 	mockLibraryManager := NewMocklibrarian(t)
 	autoupdater.libraryManager = mockLibraryManager
-	currentOsqueryVersion := "1.1.1"
-	mockQuerier.On("Query", mock.Anything).Return([]map[string]string{{"version": currentOsqueryVersion}}, nil)
 	mockLibraryManager.On("Available", binaryOsqueryd, fmt.Sprintf("%s-%s.tar.gz", binaryOsqueryd, pinnedOsquerydVersion)).Return(false)
 	mockLibraryManager.On("AddToLibrary", binaryOsqueryd, mock.Anything, mock.Anything, mock.Anything).Return(nil)
 
@@ -984,7 +989,6 @@ func TestFlagsChanged_DuringInitialDelay(t *testing.T) {
 	mockKnapsack.On("TufServerURL").Return("https://example.com")
 	mockKnapsack.On("UpdateDirectory").Return("")
 	mockKnapsack.On("MirrorServerURL").Return("https://example.com")
-	mockQuerier := newMockQuerier(t)
 	mockKnapsack.On("Slogger").Return(multislogger.NewNopLogger())
 	mockKnapsack.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel, keys.PinnedLauncherVersion, keys.PinnedOsquerydVersion, keys.AutoupdateDownloadSplay).Return()
 
@@ -994,7 +998,7 @@ func TestFlagsChanged_DuringInitialDelay(t *testing.T) {
 	mockKnapsack.On("PinnedLauncherVersion").Return("")
 
 	// Set up autoupdater
-	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, mockQuerier, WithOsqueryRestart(func(context.Context) error { return nil }))
+	autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, WithOsqueryRestart(func(context.Context) error { return nil }))
 	require.NoError(t, err, "could not initialize new TUF autoupdater")
 	require.Equal(t, pinnedLauncherVersion, autoupdater.pinnedVersions[binaryLauncher])
 
@@ -1016,10 +1020,8 @@ func TestFlagsChanged_DuringInitialDelay(t *testing.T) {
 func Test_currentRunningVersion_launcher_errorWhenVersionIsNotSet(t *testing.T) {
 	t.Parallel()
 
-	mockQuerier := newMockQuerier(t)
 	autoupdater := &TufAutoupdater{
-		slogger:   multislogger.NewNopLogger(),
-		osquerier: mockQuerier,
+		slogger: multislogger.NewNopLogger(),
 	}
 
 	// In test, version.Version() returns `unknown` for everything, which is not something
@@ -1032,24 +1034,27 @@ func Test_currentRunningVersion_launcher_errorWhenVersionIsNotSet(t *testing.T)
 func Test_currentRunningVersion_osqueryd(t *testing.T) {
 	t.Parallel()
 
-	mockQuerier := newMockQuerier(t)
 	mockKnapsack := typesmocks.NewKnapsack(t)
 	testBinDir := t.TempDir()
-	fakeOsqBinaryPath := executableLocation(testBinDir, "osqueryd")
-	_, err := os.Create(fakeOsqBinaryPath)
-	require.NoError(t, err, "unable to create fake osqueryd binary file for test setup")
-	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(fakeOsqBinaryPath)
+
+	// Set up osquery binary
+	osqBinaryPath := filepath.Join(testBinDir, "osqueryd")
+	if runtime.GOOS == "windows" {
+		osqBinaryPath += ".exe"
+	}
+	tufci.CopyOlderBinary(t, osqBinaryPath)
+
+	mockKnapsack.On("LatestOsquerydPath", mock.Anything).Return(osqBinaryPath)
 
 	autoupdater := &TufAutoupdater{
-		slogger:   multislogger.NewNopLogger(),
-		osquerier: mockQuerier,
-		knapsack:  mockKnapsack,
+		slogger:        multislogger.NewNopLogger(),
+		osqueryTimeout: 5 * time.Second,
+		knapsack:       mockKnapsack,
 	}
 
 	// Expect to return one row containing the version
-	expectedOsqueryVersion, err := semver.NewVersion("5.10.12")
+	expectedOsqueryVersion, err := semver.NewVersion(tufci.OlderBinaryVersion)
 	require.NoError(t, err)
-	mockQuerier.On("Query", mock.Anything).Return([]map[string]string{{"version": expectedOsqueryVersion.Original()}}, nil).Once()
 
 	osqueryVersion, err := autoupdater.currentRunningVersion("osqueryd")
 	require.NoError(t, err, "expected no error fetching current running version of osqueryd")
@@ -1076,24 +1081,6 @@ func Test_currentRunningVersion_osqueryd_missing_binary(t *testing.T) {
 	require.Equal(t, "", osqueryVersion, "expected no current osquery version to be returned")
 }
 
-func Test_currentRunningVersion_osqueryd_handlesQueryError(t *testing.T) {
-	t.Parallel()
-
-	mockQuerier := newMockQuerier(t)
-	autoupdater := &TufAutoupdater{
-		slogger:                multislogger.NewNopLogger(),
-		osquerier:              mockQuerier,
-		osquerierRetryInterval: 1 * time.Millisecond,
-	}
-
-	// Expect to return an error (five times, since we perform retries)
-	mockQuerier.On("Query", mock.Anything).Return(make([]map[string]string, 0), errors.New("test osqueryd querying error"))
-
-	osqueryVersion, err := autoupdater.currentRunningVersion("osqueryd")
-	require.Error(t, err, "expected an error returning osquery version when querying osquery fails")
-	require.Equal(t, "", osqueryVersion)
-}
-
 //go:embed testdata/test_promote_time_target_files.json
 var sampleTargetJson []byte
 
diff --git a/ee/tuf/mock_querier_test.go b/ee/tuf/mock_querier_test.go
deleted file mode 100644
index d316dd7e..00000000
--- a/ee/tuf/mock_querier_test.go
+++ /dev/null
@@ -1,51 +0,0 @@
-// Code generated by mockery v2.21.1. DO NOT EDIT.
-
-package tuf
-
-import mock "github.com/stretchr/testify/mock"
-
-// mockQuerier is an autogenerated mock type for the querier type
-type mockQuerier struct {
-	mock.Mock
-}
-
-// Query provides a mock function with given fields: query
-func (_m *mockQuerier) Query(query string) ([]map[string]string, error) {
-	ret := _m.Called(query)
-
-	var r0 []map[string]string
-	var r1 error
-	if rf, ok := ret.Get(0).(func(string) ([]map[string]string, error)); ok {
-		return rf(query)
-	}
-	if rf, ok := ret.Get(0).(func(string) []map[string]string); ok {
-		r0 = rf(query)
-	} else {
-		if ret.Get(0) != nil {
-			r0 = ret.Get(0).([]map[string]string)
-		}
-	}
-
-	if rf, ok := ret.Get(1).(func(string) error); ok {
-		r1 = rf(query)
-	} else {
-		r1 = ret.Error(1)
-	}
-
-	return r0, r1
-}
-
-type mockConstructorTestingTnewMockQuerier interface {
-	mock.TestingT
-	Cleanup(func())
-}
-
-// newMockQuerier creates a new instance of mockQuerier. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
-func newMockQuerier(t mockConstructorTestingTnewMockQuerier) *mockQuerier {
-	mock := &mockQuerier{}
-	mock.Mock.Test(t)
-
-	t.Cleanup(func() { mock.AssertExpectations(t) })
-
-	return mock
-}