Commit 49f54e86 authored by Mostyn Bramley-Moore's avatar Mostyn Bramley-Moore Committed by Ian Lance Taylor

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/41430Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
parent c2b4fb5a
......@@ -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)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment