internal_unix_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (C) 2019 Nicola Murino
  2. //
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU Affero General Public License as published
  5. // by the Free Software Foundation, version 3.
  6. //
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU Affero General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU Affero General Public License
  13. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. //go:build !windows
  15. // +build !windows
  16. package sftpd
  17. import (
  18. "os/exec"
  19. "testing"
  20. "github.com/stretchr/testify/assert"
  21. )
  22. func TestWrapCmd(t *testing.T) {
  23. cmd := exec.Command("ls")
  24. cmd = wrapCmd(cmd, 3001, 3002)
  25. assert.Equal(t, uint32(3001), cmd.SysProcAttr.Credential.Uid)
  26. assert.Equal(t, uint32(3002), cmd.SysProcAttr.Credential.Gid)
  27. cmd = exec.Command("cd")
  28. cmd = wrapCmd(cmd, processUID, processGID)
  29. assert.Nil(t, cmd.SysProcAttr)
  30. }