1package visual
2
3import (
4 "bytes"
5 "errors"
6 "testing"
7 "time"
8
9 "github.com/bnema/zerowrap"
10 "github.com/stretchr/testify/require"
11)
12
13func TestWorkerEnvironmentIsAnAllowlistOfPresentVariables(t *testing.T) {
14 host := map[string]string{
15 "HOME": "/home/u", "PATH": "/usr/bin", "USER": "u", "GNUPGHOME": "/g", "GPG_TTY": "/dev/pts/1",
16 "WAYLAND_DISPLAY": "wayland-1", "SSH_AUTH_SOCK": "/s", "NEFERAFK_PIN": "123456", "LC_ALL": "",
17 }
18 env := workerEnvironment(func(k string) (string, bool) { v, ok := host[k]; return v, ok })
19 require.Equal(t, []string{"HOME=/home/u", "PATH=/usr/bin", "USER=u", "LC_ALL=", "GNUPGHOME=/g", "GPG_TTY=/dev/pts/1"}, env)
20 for _, e := range env {
21 require.NotContains(t, e, "WAYLAND")
22 require.NotContains(t, e, "SSH_")
23 require.NotContains(t, e, "PIN")
24 }
25 require.Empty(t, workerEnvironment(func(string) (string, bool) { return "", false }))
26}
27
28func TestLockConfigReportsSkippedOutputWithComponent(t *testing.T) {
29 var buf bytes.Buffer
30 log := zerowrap.New(zerowrap.Config{Output: &buf})
31 ctl := newAuthController(testLog(), nil, boot(), time.Minute)
32 cfg := newLockConfig(log, ctl, make(chan struct{}, 1))
33 require.NotNil(t, cfg.OnOutputError)
34 cfg.OnOutputError("HDMI-A-1", errors.New("surface failed"))
35 out := buf.String()
36 require.Contains(t, out, "visual-lock")
37 require.Contains(t, out, "HDMI-A-1")
38 require.Contains(t, out, "surface failed")
39 require.Contains(t, out, "WRN")
40}