Просмотр исходного кода

lib/fs: Let xattr test avoid non-test attributes (fixes #8601) (#8628)

SELinux for example adds security.* attributes by default that we are
not allowed to touch, which causes the test to fail.
Jakob Borg 3 лет назад
Родитель
Сommit
bf1e418e4a
1 измененных файлов с 10 добавлено и 8 удалено
  1. 10 8
      lib/fs/basicfs_test.go

+ 10 - 8
lib/fs/basicfs_test.go

@@ -591,12 +591,12 @@ func TestXattr(t *testing.T) {
 	}
 
 	// Set the xattrs, read them back and compare
-	if err := tfs.SetXattr("/test", attrs, noopXattrFilter{}); errors.Is(err, ErrXattrsNotSupported) || errors.Is(err, syscall.EOPNOTSUPP) {
+	if err := tfs.SetXattr("/test", attrs, testXattrFilter{}); errors.Is(err, ErrXattrsNotSupported) || errors.Is(err, syscall.EOPNOTSUPP) {
 		t.Skip("xattrs not supported")
 	} else if err != nil {
 		t.Fatal(err)
 	}
-	res, err := tfs.GetXattr("/test", noopXattrFilter{})
+	res, err := tfs.GetXattr("/test", testXattrFilter{})
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -631,10 +631,10 @@ func TestXattr(t *testing.T) {
 	sort.Slice(attrs, func(i, j int) bool { return attrs[i].Name < attrs[j].Name })
 
 	// Set the xattrs, read them back and compare
-	if err := tfs.SetXattr("/test", attrs, noopXattrFilter{}); err != nil {
+	if err := tfs.SetXattr("/test", attrs, testXattrFilter{}); err != nil {
 		t.Fatal(err)
 	}
-	res, err = tfs.GetXattr("/test", noopXattrFilter{})
+	res, err = tfs.GetXattr("/test", testXattrFilter{})
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -666,8 +666,10 @@ func TestWalkInfiniteRecursion(t *testing.T) {
 	testWalkInfiniteRecursion(t, FilesystemTypeBasic, dir)
 }
 
-type noopXattrFilter struct{}
+type testXattrFilter struct{}
 
-func (noopXattrFilter) Permit(string) bool         { return true }
-func (noopXattrFilter) GetMaxSingleEntrySize() int { return 0 }
-func (noopXattrFilter) GetMaxTotalSize() int       { return 0 }
+// Permit only xattrs generated by our test, avoiding issues with SELinux etc.
+func (testXattrFilter) Permit(name string) bool { return strings.HasPrefix(name, "user.test-") }
+
+func (testXattrFilter) GetMaxSingleEntrySize() int { return 0 }
+func (testXattrFilter) GetMaxTotalSize() int       { return 0 }