func TestDefault(t *testing.T) { d := testutil.MustTempDir(t, "", "acl") defer os.RemoveAll(d) // Set default ACL to no permissions, which is pretty much // guaranteed not to be the system-wide default. // That way we know it's not a fluke if that's the ACL // on a newly-created file. dacl := ACL{Entry{Tag: TagUserObj}, Entry{Tag: TagUser, Qualifier: "0"}, Entry{Tag: TagGroupObj}, Entry{Tag: TagGroup, Qualifier: "0"}, Entry{Tag: TagMask}, Entry{Tag: TagOther}} err := SetDefault(d, dacl) testutil.Must(t, err) _, err = os.Create(filepath.Join(d, "file")) testutil.Must(t, err) acl, err := Get(filepath.Join(d, "file")) testutil.Must(t, err) if !reflect.DeepEqual(dacl, acl) { t.Errorf("access ACL does not match parent's default ACL: got %v; want %v", acl, dacl) } err = os.Mkdir(filepath.Join(d, "dir"), 0666) testutil.Must(t, err) dacl2, err := GetDefault(filepath.Join(d, "dir")) testutil.Must(t, err) if !reflect.DeepEqual(dacl, dacl2) { t.Errorf("default ACL does not match parent's default ACL: got %v; want %v", dacl2, dacl) } }
func TestSet(t *testing.T) { /* Access ACL */ f := testutil.MustTempFile(t, "", "acl").Name() defer os.Remove(f) acl, err := Get(f) testutil.Must(t, err) for i := range acl { acl[i].Perms = (^acl[i].Perms) & 0x7 // Flip the rwx bits } err = Set(f, acl) testutil.Must(t, err) acl2, err := Get(f) testutil.Must(t, err) if !reflect.DeepEqual(acl, acl2) { t.Errorf("unexpected ACL: want %v; got %v", acl, acl2) } /* Default ACL */ d := testutil.MustTempDir(t, "", "acl") defer os.Remove(d) // reuse the acl from above since we know it's valid err = SetDefault(d, acl) testutil.Must(t, err) acl2, err = GetDefault(d) testutil.Must(t, err) if !reflect.DeepEqual(acl, acl2) { t.Errorf("unexpected default ACL: want %v; got %v", acl, acl2) } }
func TestGet(t *testing.T) { f := testutil.MustTempFile(t, "", "acl").Name() defer os.Remove(f) _, err := Get(f) testutil.Must(t, err) d := testutil.MustTempDir(t, "", "acl") defer os.Remove(d) _, err = GetDefault(d) testutil.Must(t, err) }