Skip to content

Commit

Permalink
Add tests, documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Nov 21, 2023
1 parent 3d63d77 commit 90c9e03
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ee/tuf/finalize_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package tuf

import (
"bytes"
"context"
"debug/elf"
"errors"
Expand All @@ -14,6 +15,9 @@ import (
"github.com/kolide/launcher/pkg/allowedcmd"
)

// On NixOS, we have to set the interpreter for any non-NixOS executable we want to
// run. This means the binaries that our updater downloads.
// See: https://unix.stackexchange.com/a/522823
func patchExecutable(executableLocation string) error {
if !allowedcmd.IsNixOS() {
return nil
Expand Down Expand Up @@ -60,8 +64,10 @@ func getInterpreter(executableLocation string) (string, error) {
return "", fmt.Errorf("reading .interp section: %w", err)
}

// interpData should look something like "/lib64/ld-linux-x86-64.so.2"
return filepath.Base(string(interpData)), nil
trimmedInterpData := bytes.TrimRight(interpData, "\x00")

// interpData should look something like "/lib64/ld-linux-x86-64.so.2" -- grab just the filename
return filepath.Base(string(trimmedInterpData)), nil
}

func findInterpreterInNixStore(interpreter string) (string, error) {
Expand Down
22 changes: 22 additions & 0 deletions ee/tuf/finalize_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build linux
// +build linux

package tuf

import (
"os"
"testing"

"github.com/stretchr/testify/require"
)

func Test_getInterpreter(t *testing.T) {

Check failure on line 13 in ee/tuf/finalize_linux_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Function Test_getInterpreter missing the call to method parallel

Check failure on line 13 in ee/tuf/finalize_linux_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Function Test_getInterpreter missing the call to method parallel (paralleltest)
// Use the current executable in our test
currentRunningExecutable, err := os.Executable()
require.NoError(t, err, "getting current executable")

// Confirm we pick the expected interpreter
interpreter, err := getInterpreter(currentRunningExecutable)
require.NoError(t, err, "expected no error getting interpreter")
require.Equal(t, "ld-linux-x86-64.so.2", interpreter)
}
15 changes: 15 additions & 0 deletions ee/tuf/finalize_other_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build !linux
// +build !linux

package tuf

import (
"testing"

"github.com/stretchr/testify/require"
)

func Test_patchExecutable(t *testing.T) {

Check failure on line 12 in ee/tuf/finalize_other_test.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

Function Test_patchExecutable missing the call to method parallel (paralleltest)

Check failure on line 12 in ee/tuf/finalize_other_test.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

Function Test_patchExecutable missing the call to method parallel

Check failure on line 12 in ee/tuf/finalize_other_test.go

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

Function Test_patchExecutable missing the call to method parallel

Check failure on line 12 in ee/tuf/finalize_other_test.go

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

Function Test_patchExecutable missing the call to method parallel (paralleltest)
// patchExecutable is a no-op on windows and darwin
require.NoError(t, patchExecutable(""))
}

0 comments on commit 90c9e03

Please sign in to comment.