Skip to content

Commit 68cd877

Browse files
committed
fix: reject server.user explicitly on windows, add init validation test
1 parent 36e4d64 commit 68cd877

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

plugin.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log/slog"
66
"os"
77
"os/user"
8+
"runtime"
89
"strconv"
910
"strings"
1011
"sync"
@@ -58,6 +59,12 @@ func (p *Plugin) Init(cfg Configurer, log NamedLogger) error {
5859

5960
// resolve the configured run-as user's uid/gid once
6061
if p.cfg.User != "" {
62+
// process.ExecuteFromUser is a no-op on Windows, and Windows uids (SIDs)
63+
// are not numeric — reject the option explicitly instead of failing on Atoi.
64+
if runtime.GOOS == "windows" {
65+
return errors.E(op, errors.Init, errors.Str("server.user is not supported on windows"))
66+
}
67+
6168
usr, err := user.Lookup(p.cfg.User)
6269
if err != nil {
6370
return errors.E(op, errors.Init, err)

plugin_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ func TestCommandUnknownUser(t *testing.T) {
7777
})
7878
}
7979

80+
func TestInitUnknownUser(t *testing.T) {
81+
log := slog.New(slog.NewTextHandler(os.Stderr, nil))
82+
p := &Plugin{
83+
preparedEnvs: make([]string, 0),
84+
cfg: &Config{},
85+
log: log,
86+
}
87+
88+
v := viper.New()
89+
v.Set("server.command", "php php_test_files/client.php echo pipes")
90+
v.Set("server.user", "rr-definitely-missing-user")
91+
92+
cfg, err := InitMockCfg(v)
93+
require.NoError(t, err)
94+
95+
err = p.Init(cfg, NewTestLogger(log))
96+
require.Error(t, err)
97+
}
98+
8099
func TestCommand1(t *testing.T) {
81100
log := slog.New(slog.NewTextHandler(os.Stderr, nil))
82101
p := &Plugin{

0 commit comments

Comments
 (0)