]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/work: more TestRespectSetgidDir fixes
authorMostyn Bramley-Moore <mostyn@antipode.se>
Fri, 21 Apr 2017 21:34:39 +0000 (23:34 +0200)
committerIan Lance Taylor <iant@golang.org>
Fri, 21 Apr 2017 23:43:59 +0000 (23:43 +0000)
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>

src/cmd/go/internal/work/build_test.go

index d68711432b4460c9f9ace4d419da9631d1a3980e..294b83c6b2ae6272ccf3c31a16243fa4ea3b6235 100644 (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)
        }
 }