1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:44:43 -07:00

cmd/go/internal/work: more TestRespectSetgidDir fixes

Hopefully the last refactoring of TestRespectGroupSticky:
* Properly tested (+simplified) FreeBSD fix
* Tested on Darwin (10.12.4)
* Rename to TestRespectSetgidDir (I believe this is the accepted
  terminology)

Fixes golang/go#19596.

Change-Id: I8d689ac3e245846cb3f1338ea13e35be512ccb9c
Reviewed-on: https://go-review.googlesource.com/41430
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Mostyn Bramley-Moore 2017-04-21 23:34:39 +02:00 committed by Ian Lance Taylor
parent c2b4fb5a3b
commit 49f54e8617

View File

@ -171,12 +171,12 @@ func pkgImportPath(pkgpath string) *load.Package {
}
// When installing packages, the installed package directory should
// respect the group sticky bit and group name of the destination
// respect the SetGID bit and group name of the destination
// directory.
// See https://golang.org/issue/18878.
func TestRespectGroupSticky(t *testing.T) {
func TestRespectSetgidDir(t *testing.T) {
if runtime.GOOS == "nacl" {
t.Skip("can't set group sticky bit with chmod on nacl")
t.Skip("can't set SetGID bit with chmod on nacl")
}
var b Builder
@ -189,19 +189,21 @@ func TestRespectGroupSticky(t *testing.T) {
return cmdBuf.WriteString(fmt.Sprint(a...))
}
stickydir, err := ioutil.TempDir("", "GroupSticky")
setgiddir, err := ioutil.TempDir("", "SetGroupID")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(stickydir)
defer os.RemoveAll(setgiddir)
testdir, err := ioutil.TempDir(stickydir, "testdir")
if err != nil {
t.Fatal(err)
if runtime.GOOS == "freebsd" {
err = os.Chown(setgiddir, os.Getuid(), os.Getgid())
if err != nil {
t.Fatal(err)
}
}
// Change testdir's permissions to include group sticky bit.
if err := os.Chmod(testdir, 0755|os.ModeSetgid); err != nil {
// Change setgiddir's permissions to include the SetGID bit.
if err := os.Chmod(setgiddir, 0755|os.ModeSetgid); err != nil {
t.Fatal(err)
}
@ -212,14 +214,14 @@ func TestRespectGroupSticky(t *testing.T) {
defer os.Remove(pkgfile.Name())
defer pkgfile.Close()
stickyFile := filepath.Join(testdir, "sticky")
if err := b.moveOrCopyFile(nil, stickyFile, pkgfile.Name(), 0666, true); err != nil {
dirGIDFile := filepath.Join(setgiddir, "setgid")
if err := b.moveOrCopyFile(nil, dirGIDFile, pkgfile.Name(), 0666, true); err != nil {
t.Fatalf("moveOrCopyFile: %v", err)
}
got := strings.TrimSpace(cmdBuf.String())
want := b.fmtcmd("", "cp %s %s", pkgfile.Name(), stickyFile)
want := b.fmtcmd("", "cp %s %s", pkgfile.Name(), dirGIDFile)
if got != want {
t.Fatalf("moveOrCopyFile(%q, %q): want %q, got %q", stickyFile, pkgfile.Name(), want, got)
t.Fatalf("moveOrCopyFile(%q, %q): want %q, got %q", dirGIDFile, pkgfile.Name(), want, got)
}
}