mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
**Related issue:** Resolves #31633. Main change is stop relying on `who` command output to get the value of the DISPLAY variable on X11 sessions (old distributions), and instead search the value of the `DISPLAY` variable in processes that are owned by the target user. - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Enhanced X11 session detection for improved support in multi-session environments, providing more reliable display variable identification in complex session configurations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package execuser
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestReadEnvFromProcFile(t *testing.T) {
|
|
dir := t.TempDir()
|
|
environPath := filepath.Join(dir, "environ")
|
|
|
|
testCases := []struct {
|
|
name string
|
|
environ string
|
|
envVar string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "DISPLAY found",
|
|
environ: "HOME=/home/foo\x00DISPLAY=:0\x00LANG=en_US.UTF-8",
|
|
envVar: "DISPLAY",
|
|
expected: ":0",
|
|
},
|
|
{
|
|
name: "DISPLAY :1",
|
|
environ: "HOME=/home/foo\x00DISPLAY=:1\x00LANG=en_US.UTF-8",
|
|
envVar: "DISPLAY",
|
|
expected: ":1",
|
|
},
|
|
{
|
|
name: "DISPLAY not present",
|
|
environ: "HOME=/home/foo\x00LANG=en_US.UTF-8",
|
|
envVar: "DISPLAY",
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "empty environ",
|
|
environ: "",
|
|
envVar: "DISPLAY",
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "does not match prefix substring",
|
|
environ: "DISPLAY_NUM=5\x00DISPLAY=:2",
|
|
envVar: "DISPLAY",
|
|
expected: ":2",
|
|
},
|
|
{
|
|
name: "other env var",
|
|
environ: "HOME=/home/foo\x00DISPLAY=:0\x00WAYLAND_DISPLAY=wayland-0",
|
|
envVar: "WAYLAND_DISPLAY",
|
|
expected: "wayland-0",
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
require.NoError(t, os.WriteFile(environPath, []byte(tc.environ), 0o644))
|
|
result, err := readEnvFromProcFile(environPath, tc.envVar)
|
|
require.NoError(t, err)
|
|
require.Equal(t, tc.expected, result)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestReadEnvFromProcFileMissing(t *testing.T) {
|
|
_, err := readEnvFromProcFile("/nonexistent/path/environ", "DISPLAY")
|
|
require.Error(t, err)
|
|
}
|