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